Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-26 Thread Simon Brown
>
>
>
> Ok, I've cheated somewhat, and taken my (much older) ffmpeg and
> editted isom.c so that rather than substituting 0x40 for AV_CODEC_ID_AAC it
> now substitutes 0x67 instead.  If I look at the resulting output file with
> mp4info and the output of FFmpeg itself they both show that it's MP4 AAC
> LC.  However, the codec string given by mp4info is mp4a.67.  If I want to
> send it to a web page it has to be AAC LC, but the typically accepted codec
> string is mp4a.40.2 which is also supposed to map to AAC LC.  So now I am
> wondering how I would encode that in the ESDS or similar so that a) mp4info
> is happy that it's mp4a.40.2 and that the chrome video decoder is happy
> with the media type (because mp4a.67 codec string although in theory
> supported gives me "Unrecognised media codec: mp4a.67" in Chrome.
>
>
> Another update:
I've updated movenc.c now, having reverted isom.c to original.
This (as I'm only ever dealing with AAC_LC) hacks the decoder specific info
len to force an extra 10 bytes if the track->par->codec_id =
AV_CODEC_ID_AAC.
And then later on where decoder specific info is inserted from vos_len and
vos_data (I couldn't find where these get set - hence me doing it this way)
I force these to insert the extra info required to make it think it's
mp4a.40.2.
This was done by comparing the esds packet from a faulty encoding and from
the correct encoding.
The correct encoding for mp4a.40.2 adds a descriptor of 5, length 5, and
then the bytes: 0x11 0x90 0x56 0xe5 0x00
mp4info accepts this is mp4a.40.2 and so does Chrome.

Thank you again for pointing me in the right direction, and apologies that
I've hacked ffmpeg purely for my purposes without finding a "proper"
solution.

Cheers,
Simon
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-26 Thread Simon Brown
>
>
>
> So it seems to be a matter of TS demuxing passing along the codec
> extradata correctly.
>
> Regards,
> Tobias
>
> Thank you both for your replies.

Ok, I've cheated somewhat, and taken my (much older) ffmpeg and
editted isom.c so that rather than substituting 0x40 for AV_CODEC_ID_AAC it
now substitutes 0x67 instead.  If I look at the resulting output file with
mp4info and the output of FFmpeg itself they both show that it's MP4 AAC
LC.  However, the codec string given by mp4info is mp4a.67.  If I want to
send it to a web page it has to be AAC LC, but the typically accepted codec
string is mp4a.40.2 which is also supposed to map to AAC LC.  So now I am
wondering how I would encode that in the ESDS or similar so that a) mp4info
is happy that it's mp4a.40.2 and that the chrome video decoder is happy
with the media type (because mp4a.67 codec string although in theory
supported gives me "Unrecognised media codec: mp4a.67" in Chrome.

Regards,
Simon
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-25 Thread Tobias Rapp

On 24.05.2021 22:26, Moritz Barsnick wrote:

On Wed, May 19, 2021 at 12:17:38 +0200, Tobias Rapp wrote:

Looks like the data that should be found in the "esds" atom is missing or
incomplete when using -c:a copy. See this link for details on how AAC
profile information is stored in MP4:

https://stackoverflow.com/questions/3987850/mp4-atom-how-to-discriminate-the-audio-codec-is-it-aac-or-mp3


Interesting stuff.


Don't know enough about TS (de)muxing, though, to find out where this
profile data should be parsed out from the input by FFmpeg.


MPEG-TS and demuxing isn't the problem. If you look at the ffmpeg
output in the original e-mail from decoding the file, it correctly
identifies the codec as "aac (LC)". The issue is the encoding to MP4.

The reason is that the AAC variants have only one codec tag
AV_CODEC_ID_AAC, and that needs to map to various tags, e.g. 0x40 for
AAC and 0x67 for AAC LC.

https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/isom.c#L34

When writing the tag in the esds atom, there's no additional info
available allowing mapping to 0x67, therefore 0x40 is written:

https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/movenc.c#L711

I have no idea how this info could be carried forward.
From the StackOverflow answers the AAC profile seems to be part of the 
AudioSpecificConfig (ASC) part which is written as "TAG 5" within the 
Elementary Stream Descriptor MP4 atom.


Looking at the FFmpeg movenc.c link you posted it is written some lines 
below the codec id from track->vos_data. This pointer is filled from 
AVCodecParameters->extradata in ff_mov_write_packet:


https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/movenc.c#L5586

So it seems to be a matter of TS demuxing passing along the codec 
extradata correctly.


Regards,
Tobias

___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-24 Thread Moritz Barsnick
On Mon, May 24, 2021 at 22:26:03 +0200, Moritz Barsnick wrote:
> MPEG-TS and demuxing isn't the problem. If you look at the ffmpeg
> output in the original e-mail from decoding the file, it correctly
> identifies the codec as "aac (LC)". The issue is the encoding to MP4.

On the other hand, when I copy AAC LC audio from MPEG-TS to MP4, it
works. So my analysis has some major flaw.

Moritz
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-24 Thread Moritz Barsnick
On Wed, May 19, 2021 at 12:17:38 +0200, Tobias Rapp wrote:
> Looks like the data that should be found in the "esds" atom is missing or
> incomplete when using -c:a copy. See this link for details on how AAC
> profile information is stored in MP4:
>
> https://stackoverflow.com/questions/3987850/mp4-atom-how-to-discriminate-the-audio-codec-is-it-aac-or-mp3

Interesting stuff.

> Don't know enough about TS (de)muxing, though, to find out where this
> profile data should be parsed out from the input by FFmpeg.

MPEG-TS and demuxing isn't the problem. If you look at the ffmpeg
output in the original e-mail from decoding the file, it correctly
identifies the codec as "aac (LC)". The issue is the encoding to MP4.

The reason is that the AAC variants have only one codec tag
AV_CODEC_ID_AAC, and that needs to map to various tags, e.g. 0x40 for
AAC and 0x67 for AAC LC.

https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/isom.c#L34

When writing the tag in the esds atom, there's no additional info
available allowing mapping to 0x67, therefore 0x40 is written:

https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/movenc.c#L711

I have no idea how this info could be carried forward.

Moritz
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-19 Thread Tobias Rapp

On 14.05.2021 15:31, Simon Brown wrote:
[...] 


For although there it says aac (LC) if I run mp4info on the resultant file
I get this:

[...]

Track 2:
   flags:3 ENABLED IN-MOVIE
   id:   2
   type: Audio
   duration: 0 ms
   language: und
   media:
 sample count: 0
 timescale:48000
 duration: 0 (media timescale units)
 duration: 0 (ms)
 bitrate (computed): 125.373 Kbps
 sample count with fragments: 848
 duration with fragments: 868354
 duration with fragments: 18091 (ms)
   Sample Description 0
 Coding:  mp4a (MPEG-4 Audio)
 Stream Type: Audio
 Object Type: MPEG-4 Audio
 Max Bitrate: 128250
 Avg Bitrate: 0
 Buffer Size: 0
 Codecs String: mp4a.40.0
 MPEG-4 Audio Object Type: 0 (UNKNOWN)
 Sample Rate: 48000
 Sample Size: 16
 Channels:2

whereas if I used -c:a aac -profile:a aac_low instead of -c:a copy then I
get this from mp4info:
Track 2:
   flags:3 ENABLED IN-MOVIE
   id:   2
   type: Audio
   duration: 0 ms
   language: und
   media:
 sample count: 0
 timescale:48000
 duration: 0 (media timescale units)
 duration: 0 (ms)
 bitrate (computed): 49.589 Kbps
 sample count with fragments: 849
 duration with fragments: 869378
 duration with fragments: 18112 (ms)
   Sample Description 0
 Coding:  mp4a (MPEG-4 Audio)
 Stream Type: Audio
 Object Type: MPEG-4 Audio
 Max Bitrate: 128000
 Avg Bitrate: 0
 Buffer Size: 0
 Codecs String: mp4a.40.2
 MPEG-4 Audio Object Type: 2 (AAC Low Complexity)
 MPEG-4 Audio Decoder Config:
   Sampling Frequency: 48000
   Channels: 2
   Extension:
 Object Type: Spectral Band Replication
 SBR Present: no
 PS Present:  no
 Sampling Frequency: 0
 Sample Rate: 48000
 Sample Size: 16
 Channels:2

where it clearly states it as Mpeg-4 Audio AAC Low complexity.


Looks like the data that should be found in the "esds" atom is missing 
or incomplete when using -c:a copy. See this link for details on how AAC 
profile information is stored in MP4:


https://stackoverflow.com/questions/3987850/mp4-atom-how-to-discriminate-the-audio-codec-is-it-aac-or-mp3

Don't know enough about TS (de)muxing, though, to find out where this 
profile data should be parsed out from the input by FFmpeg.


Regards,
Tobias

___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-18 Thread Moritz Barsnick
On Mon, May 17, 2021 at 23:34:45 +0100, Simon Brown wrote:
> Thank you for your reply.  If it is the bitstream filter could you point me
> to the relevant source file that is responsible for this filter?

Sure, it's here:
https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/aac_adtstoasc_bsf.c

> mp4info doesn't deal with TS, as you surmise.  FFMpeg reports the output
> file as AAC (not LC).  I'm not sure VLC gives that detail.  But given that
> the ffmpeg processor and the mp4info program both seem to concur when there
> is or isn't AAC-LC I'm not sure there is much value in trying a third
> tool.

You could also try mediainfo. I also found a tool capable of parsing
and deconstruction AAC headers (https://p23.nl/projects/aac-header/),
but I don't trust it since it isn't capable of recognizing e.g.
HE-AACv2 (though I haven't taken the time to understand all the headers
myself).

I couldn't reproduce the loss of this information with the input
samples I have. Can you share your input file? Since it's an MPEG-TS.
perhaps the first MB (or five) suffice.

> I will download the latest prebuilt binaries for Windows and give it a try
> with those.  I'd still be interested in the source file responsible as the
> version on the embedded system I'm using is not the most recent build, and
> rebuilding for that isn't something I want to do at this stage.

I understand.

Cheers,
Moritz
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-17 Thread Simon Brown
>
>
> On Fri, May 14, 2021 at 14:31:42 +0100, Simon Brown wrote:
> > Hi,
> > I have a mpeg2 transport stream with video as H264 and audio as AAC LC.
> If
> > I use the following command to convert it to fragmented MP4 by just
> copying
> > the encoded data, then the result is now AAC, and not AAC LC.  If
> instead I
> > re-encode with AAC asking for profile:a aac_low then I get AAC LC.  But
> if
> > the input source is AAC LC why would it change the output type to AAC?
> >
> > ffmpeg.exe -f mpegts -fflags +nobuffer+nofillin -probesize 500 -i
> > soc_udp_rx_02.ts -c:a copy -bsf:a aac_adtstoasc -c:v copy -f mp4
> > -frag_duration 8 -movflags +empty_moov+default_base_moof -metadata
> > title="media source exentions" testaudio.mp4
>
> This shouldn't change anything in the AAC stream, unless the bitstream
> filter is capable of ruining it.
>
> What does it say about the original? (Nothing, presumably, because it's
> MPEG-TS.) What does ffmpeg say about the output file? Do you have any
> other tool which can use to check?
>
> Cheers,
> Moritz
>
> Hi Moritz,
Thank you for your reply.  If it is the bitstream filter could you point me
to the relevant source file that is responsible for this filter?

mp4info doesn't deal with TS, as you surmise.  FFMpeg reports the output
file as AAC (not LC).  I'm not sure VLC gives that detail.  But given that
the ffmpeg processor and the mp4info program both seem to concur when there
is or isn't AAC-LC I'm not sure there is much value in trying a third
tool.

I will download the latest prebuilt binaries for Windows and give it a try
with those.  I'd still be interested in the source file responsible as the
version on the embedded system I'm using is not the most recent build, and
rebuilding for that isn't something I want to do at this stage.

Regards,
Simon
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-17 Thread Moritz Barsnick
On Fri, May 14, 2021 at 14:31:42 +0100, Simon Brown wrote:
> Hi,
> I have a mpeg2 transport stream with video as H264 and audio as AAC LC.  If
> I use the following command to convert it to fragmented MP4 by just copying
> the encoded data, then the result is now AAC, and not AAC LC.  If instead I
> re-encode with AAC asking for profile:a aac_low then I get AAC LC.  But if
> the input source is AAC LC why would it change the output type to AAC?
>
> ffmpeg.exe -f mpegts -fflags +nobuffer+nofillin -probesize 500 -i
> soc_udp_rx_02.ts -c:a copy -bsf:a aac_adtstoasc -c:v copy -f mp4
> -frag_duration 8 -movflags +empty_moov+default_base_moof -metadata
> title="media source exentions" testaudio.mp4

This shouldn't change anything in the AAC stream, unless the bitstream
filter is capable of ruining it.

> ffmpeg version git-2020-06-19-2f59946 Copyright (c) 2000-2020 the FFmpeg 
> developers

This is a bit old, please retry with a recent build.

> For although there it says aac (LC) if I run mp4info on the resultant file
> I get this:
>
> mp4info testaudio.mp4
[...]
> Track 2:
>   flags:3 ENABLED IN-MOVIE
>   id:   2
>   type: Audio
>   duration: 0 ms
>   language: und
>   media:
> sample count: 0
> timescale:48000
> duration: 0 (media timescale units)
> duration: 0 (ms)
> bitrate (computed): 125.373 Kbps
> sample count with fragments: 848
> duration with fragments: 868354
> duration with fragments: 18091 (ms)
>   Sample Description 0
> Coding:  mp4a (MPEG-4 Audio)
> Stream Type: Audio
> Object Type: MPEG-4 Audio
> Max Bitrate: 128250
> Avg Bitrate: 0
> Buffer Size: 0
> Codecs String: mp4a.40.0
> MPEG-4 Audio Object Type: 0 (UNKNOWN)
> Sample Rate: 48000
> Sample Size: 16
> Channels:2

What does it say about the original? (Nothing, presumably, because it's
MPEG-TS.) What does ffmpeg say about the output file? Do you have any
other tool which can use to check?

Cheers,
Moritz
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

2021-05-14 Thread Simon Brown
Hi,
I have a mpeg2 transport stream with video as H264 and audio as AAC LC.  If
I use the following command to convert it to fragmented MP4 by just copying
the encoded data, then the result is now AAC, and not AAC LC.  If instead I
re-encode with AAC asking for profile:a aac_low then I get AAC LC.  But if
the input source is AAC LC why would it change the output type to AAC?

ffmpeg.exe -f mpegts -fflags +nobuffer+nofillin -probesize 500 -i
soc_udp_rx_02.ts -c:a copy -bsf:a aac_adtstoasc -c:v copy -f mp4
-frag_duration 8 -movflags +empty_moov+default_base_moof -metadata
title="media source exentions" testaudio.mp4
ffmpeg version git-2020-06-19-2f59946 Copyright (c) 2000-2020 the FFmpeg
developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfig --enable-gnutls --enable-iconv --enable-libass
--enable-libdav1d --enable-libbluray --enable-libfreetype
--enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy
--enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264
--enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma
--enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf
--enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa
--enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads
--enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid
--enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2
--enable-avisynth --enable-libopenmpt --enable-amf
  libavutil  56. 55.100 / 56. 55.100
  libavcodec 58. 93.100 / 58. 93.100
  libavformat58. 47.100 / 58. 47.100
  libavdevice58. 11.100 / 58. 11.100
  libavfilter 7. 86.100 /  7. 86.100
  libswscale  5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc55.  8.100 / 55.  8.100
[h264 @ 01967ec1ec00] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 01967ec1ec00] decode_slice_header error
[h264 @ 01967ec1ec00] no frame!
[h264 @ 01967ec1ec00] non-existing PPS 0 referenced
Last message repeated 1 times
[h264 @ 01967ec1ec00] decode_slice_header error
[h264 @ 01967ec1ec00] no frame!
[mpegts @ 01967ebfed00] start time for stream 0 is not set in
estimate_timings_from_pts
[mpegts @ 01967ebfed00] start time for stream 1 is not set in
estimate_timings_from_pts
[mpegts @ 01967ebfed00] Packet corrupt (stream = 0, dts = 590952620).
[mpegts @ 01967ebfed00] Packet corrupt (stream = 0, dts = 590952620).
[mpegts @ 01967ebfed00] Packet corrupt (stream = 0, dts = 590952620).
[mpegts @ 01967ebfed00] stream 0 : no TS found at start of file,
duration not set
[mpegts @ 01967ebfed00] stream 1 : no TS found at start of file,
duration not set
Input #0, mpegts, from 'soc_udp_rx_02.ts':
  Duration: N/A, bitrate: N/A
  Program 1
Stream #0:0[0x1100]: Video: h264 (Main) ([27][0][0][0] / 0x001B),
yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k
tbn, 100 tbc
Stream #0:1[0x1110]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000
Hz, stereo, fltp, 128 kb/s
File 'testaudio.mp4' already exists. Overwrite? [y/N] y
Output #0, mp4, to 'testaudio.mp4':
  Metadata:
title   : media source exentions
encoder : Lavf58.47.100
Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv,
progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 50 fps, 50 tbr, 90k tbn,
90k tbc
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo,
fltp, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mpegts @ 01967ebfed00] Packet corrupt (stream = 0, dts = 590952620).
frame=  902 fps=0.0 q=-1.0 Lsize=1803kB time=00:00:18.09 bitrate=
816.3kbits/s speed= 816x
video:1469kB audio:277kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 3.293837%

For although there it says aac (LC) if I run mp4info on the resultant file
I get this:

mp4info testaudio.mp4
File:
  major brand:  iso5
  minor version:200
  compatible brand: iso5
  compatible brand: iso6
  compatible brand: mp41
  fast start:   yes

Movie:
  duration:   0 ms
  time scale: 1000
  fragments:  yes

Found 2 Tracks
Track 1:
  flags:3 ENABLED IN-MOVIE
  id:   1
  type: Video
  duration: 0 ms
  language: und
  media:
sample count: 0
timescale:9
duration: 0 (media timescale units)
duration: 0 (ms)
bitrate (computed): 664.930 Kbps
sample count with fragments: 902
duration with fragments: 1628337
duration with fragments: 18093 (ms)
  display width:  1280.00
  display height: 720.00
  Sample Description 0
Coding:  avc1 (H.264)
Width:   1280
Height:  720
Depth: