2

I'm using ffmpeg version 2.8.11 to convert an AVC/AAC video to HEVC/AAC: with the command ffmpeg -loglevel error -i input.mp4 -c:a copy -c:v libx265 -preset fast -x265-params crf=25 -vf scale=-8:ih output.mkv

The command works as expected on other files, but this particular file throws:

[matroska @ 0x88c2e0] Error parsing AAC extradata, unable to determine samplerate. Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

Source info from mediainfo:

Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 138 MiB
Duration                                 : 25mn 31s
Overall bit rate mode                    : Variable
Overall bit rate                         : 755 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=50
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 25mn 31s
Duration_FirstFrame                      : 40ms
Bit rate                                 : 650 Kbps
Width                                    : 864 pixels
Original width                           : 854 pixels
Height                                   : 470 pixels
Original height                          : 480 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.064
Stream size                              : 118 MiB (86%)
Writing library                          : x264 core 148 r236 a01e339
Encoding settings                        : cabac=1 / ref=1 / deblock=1:-1:-1 / analyse=0x1:0x111 / me=umh / subme=8 / psy=1 / psy_rd=1.00:0.15 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-1 / threads=2 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / stitchable=1 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=50 / keyint_min=5 / scenecut=0 / intra_refresh=0 / rc_lookahead=50 / rc=2pass / mbtree=1 / bitrate=650 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=850 / vbv_bufsize=850 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Codec ID                                 : 40
Duration                                 : 25mn 31s
Bit rate mode                            : Variable
Bit rate                                 : 98.5 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 44.1 KHz
Frame rate                               : 43.066 fps (1024 spf)
Compression mode                         : Lossy
Stream size                              : 18.0 MiB (13%)
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

I've tested playback of the source file which works as expected on both totem and mplayer. Based on the error I can only surmise that there's something off with the AAC stream description data. (extradata). My goal is to somehow repair/normalize this data so that I can successfully transcode it with HEVC encoder v.1.9

4

Your ffmpeg is outdated. Update and it will automatically insert some bitstream filters (at least aac_adtstoasc, hevc_mp4toannexb, h264_mp4toannexb). According to the aac_adtstoasc documentation:

Please note that it is auto-inserted for MP4A-LATM and MOV/MP4 and related formats.

It also seems to also work for Matroska. You can verify the behavior by adding -loglevel debug and viewing the output. Look for Automatically inserted bitstream filter 'aac_adtstoasc'.

See the FFmpeg Download page (Get the Packages section) for links to recent builds for Linux, macOS, and Windows. Get a build from the master branch: releases are essentially "frozen" branches derived from master; they are meant for distributors and those who need to stay within a particular API version. Releases receive less attention and get no new features so therefore they age quickly.

| improve this answer | |
  • I'll give that a try. Honestly I should upgrade the entire distro on this machine. (Still running Ubuntu 14.04 on it) – Elder Geek Sep 23 '17 at 16:05
  • @ElderGeek 18.04 LTS is 6 months away if you can wait. – llogan Sep 23 '17 at 18:09
  • Oh yes, I can wait. I have other systems running 16.04 that I can use. I'm still running 14.04 on this system mainly so that I can support it (without the inherent delays of running a VM) :-) – Elder Geek Sep 23 '17 at 18:13
  • So are you stating that with a recent version of ffmpeg (say 3.0 or above) I won't need the -bsf:a aac_adtstoasc switch? – Elder Geek Sep 23 '17 at 18:16
  • 1
    @ElderGeek Yes, but I'm unsure what release, if any yet, have the autobsf behavior. Releases are just "frozen" branches from master and are intended for distributors and those who need to stick with a certain API version. Most general users should use a recent build from the master branch. You can add -loglevel debug and view the output. Look for Automatically inserted bitstream filter 'aac_adtstoasc'. The docs say, "Please note that it is auto-inserted for MP4A-LATM and MOV/MP4 and related formats", but it also seems to also work for Matroska. – llogan Sep 23 '17 at 19:01
2

ffmpeg will happily rewrite the incorrect extradata for you if you simply copy the streams and utilize the bit stream filter aac_adtstoasc with the command ffmpeg -i input.mp4 -bsf:a aac_adtstoasc -c:a copy -c:v copy output.mp4 the resulting file converts as expected.

This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4 ADTS header and removes the ADTS header which appears was the root cause of the problem.

mediainfo reports the output file like this:

Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 137 MiB
Duration                                 : 25mn 31s
Overall bit rate mode                    : Variable
Overall bit rate                         : 750 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf56.40.101

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=50
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 25mn 31s
Duration_FirstFrame                      : 40ms
Duration_LastFrame                       : 23ms
Bit rate                                 : 650 Kbps
Width                                    : 854 pixels
Height                                   : 480 pixels
Display aspect ratio                     : 16:9
Original display aspect ratio            : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.063
Stream size                              : 118 MiB (86%)
Writing library                          : x264 core 148 r236 a01e339
Encoding settings                        : cabac=1 / ref=1 / deblock=1:-1:-1 / analyse=0x1:0x111 / me=umh / subme=8 / psy=1 / psy_rd=1.00:0.15 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-1 / threads=2 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / stitchable=1 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=50 / keyint_min=5 / scenecut=0 / intra_refresh=0 / rc_lookahead=50 / rc=2pass / mbtree=1 / bitrate=650 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=850 / vbv_bufsize=850 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 25mn 31s
Bit rate mode                            : Variable
Bit rate                                 : 96.0 Kbps
Maximum bit rate                         : 217 Kbps
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 44.1 KHz
Frame rate                               : 43.066 fps (1024 spf)
Compression mode                         : Lossy
Stream size                              : 17.6 MiB (13%)
Default                                  : Yes
Alternate group                          : 1
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

And a diff of the reports shows the relevant changes made:

6c6
< File size                                : 138 MiB
---
> File size                                : 137 MiB
9c9
< Overall bit rate                         : 755 Kbps
---
> Overall bit rate                         : 750 Kbps
11a12
> Writing application                      : Lavf56.40.101
24a26
> Duration_LastFrame                       : 23ms
26,29c28,29
< Width                                    : 864 pixels
< Original width                           : 854 pixels
< Height                                   : 470 pixels
< Original height                          : 480 pixels
---
> Width                                    : 854 pixels
> Height                                   : 480 pixels
30a31
> Original display aspect ratio            : 16:9
37c38
< Bits/(Pixel*Frame)                       : 0.064
---
> Bits/(Pixel*Frame)                       : 0.063
47a49
> Format profile                           : LC
51c53,54
< Bit rate                                 : 98.5 Kbps
---
> Bit rate                                 : 96.0 Kbps
> Maximum bit rate                         : 217 Kbps
52a56
> Channel positions                        : Front: L R
56c60,62
< Stream size                              : 18.0 MiB (13%)
---
> Stream size                              : 17.6 MiB (13%)
> Default                                  : Yes
> Alternate group                          : 1

Source: https://ffmpeg.org/ffmpeg-bitstream-filters.html#aac_005fadtstoasc

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.