Saturday, February 27, 2010

Quicktime Error 2041 an invalid sample description was found in the movie

After converting an MPEG-TS file to mp4, I had trouble with some players. Particularly, the latest Quicktime (7.6.5) wouldn't play it, saying "Error -2041: an invalid sample description was found in the movie".

Searching Google on this error turned up thousands of results, but nothing I read was directly useful. The main "solution" proposed was "rename the .mp4 file to .3gp". That seems to work in some cases for .3gp phone files which the phone happens to name .mp4.

The only solution which worked for me was to use mp4creator with the " -aac-profile=4" option.

In case anybody wants to know all the details, they are below. If you happen to know the real source of the problem and/or a version of MP4Box or ffmpeg which fixes the problem, please leave a comment.

The source file was an MPEG-TS containing h264 video and aac audio. ffmpeg reported this:

$ ffmpeg -i INPUT_FILE.mpg
FFmpeg version 0.5-svn17737+3:0.svn20090303-1ubuntu6, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-postproc --enable-swscale --enable-x11grab
 --extra-version=svn17737+3:0.svn20090303-1ubuntu6 --prefix=/usr --enable-avfilter
 --enable-avfilter-lavf --enable-libgsm --enable-libschroedinger --enable-libspeex
 --enable-libtheora --enable-libvorbis --enable-pthreads --disable-stripping --disable-vhook
 --enable-libdc1394 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp
 --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 0 / 52.20. 0
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Apr 10 2009 23:18:41, gcc: 4.3.3

Seems stream 0 codec frame rate differs from container frame rate: 50.00 (50/1) -> 25.00 (25/1)
Input #0, mpegts, from 'INPUT_FILE.mpg':
  Duration: 00:00:36.05, start: 2.050022, bitrate: 9188 kb/s
  Program 1
    Stream #0.0[0x810]: Video: h264, yuv420p, 1280x688 [PAR 1:1 DAR 80:43], 25 tbr, 90k tbn, 50 tbc
    Stream #0.1[0x814](eng): Audio: aac, 48000 Hz, stereo, s16, 184 kb/s

The simple thing I did first and which gave a bad file was

$ ffmpeg -i INPUT_FILE.mpg -vcodec copy -acodec copy -f mp4 ffmpeg.mp4

 Looking at that file with various tools gives this:

$ mp4info ffmpeg.mp4
mp4info version 1.6
ffmpeg.mp4:
Track   Type    Info
1       video   H264 High@4.1, 36.000 secs, 7889 kbps, 1280x688 @ 25.000000 fps
2       audio   MPEG-4 Unknown Profile(0), 36.032 secs, 0 kbps, 48000 Hz
 Tool: Lavf52.31.0

$ MP4Box -info ffmpeg.mp4
* Movie Info *
        Timescale 1000 - Duration 00:00:36.032
        Fragmented File no - 2 track(s)
        File Brand isom - version 512
        Created: GMT Fri Jan  2 00:00:00 1970

File has no MPEG4 IOD/OD

iTunes Info:
        Encoder Software: Lavf52.31.0

Track # 1 Info - TrackID 1 - TimeScale 50 - Duration 00:00:36.000
Media Info: Language "Undetermined" - Type "vide:avc1" - 900 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1280 x 688 - Profile High @ Level 4.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 1280 x 688
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 48000 - Duration 00:00:36.032
Media Info: Language "English" - Type "soun:mp4a" - 1689 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
Segmentation fault

Next, I tried to extract them separately:

ffmpeg -i INPUT_FILE.mpg -an -vcodec copy -f h264 video.h264
ffmpeg -i INPUT_FILE.mpg -vn -acodec copy -f aac audio.aac

and re-mux them using MP4Box (version 0.4.4):

$ MP4Box -add video.h264#video -add audio.aac#audio mp4box.mp4

That didn't work any better, even though mp4box didn't report a segmentation fault anymore:

$ MP4Box -info mp4box.mp4
* Movie Info *
 ⁞       Timescale 600 - Duration 00:00:36.031
        Fragmented File no - 2 track(s)
        File Brand isom - version 1
        Created: GMT Sat Feb 27 15:33:40 2010

File has root IOD
Scene PL 0xff - Graphics PL 0xff - OD PL 0xff
Visual PL: AVC/H264 Profile (0x15)
Audio PL: AAC Profile @ Level 2 (0x29)
No streams included in root OD

Track # 1 Info - TrackID 1 - TimeScale 25000 - Duration 00:00:36.000
Media Info: Language "Undetermined" - Type "vide:avc1" - 900 samples
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1280 x 688 - Profile High @ Level 4.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 1280 x 688
Self-synchronized

Track # 2 Info - TrackID 2 - TimeScale 48000 - Duration 00:00:36.032
Media Info: Language "Undetermined" - Type "soun:mp4a" - 1689 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x67
MPEG-2 Audio AAC LC - 2 Channel(s) - SampleRate 48000
Synchronized on stream 1

and mp4info also seemed to like the file better:

$ mp4info mp4box.mp4
mp4info version 1.6
mp4box.mp4:
Track   Type    Info
1       video   H264 High@4.1, 36.000 secs, 7717 kbps, 1280x688 @ 25.000000 fps
2       audio   MPEG-2 AAC LC, 36.032 secs, 150 kbps, 48000 Hz

Note that re-wrapping this into a Quicktime .mov file ($ ffmpeg -i mp4box.mp4 -acodec copy -vcodec copy -f mov mp4box.mov) worked and gave a file Quicktime played without trouble.

But to get a working .mp4, I had to use yet another tool for the audio: mp4creator. With the -aac-profile=4 option:

$ mp4creator -aac-profile=4 audio.aac mp4creator-audio.mp4
Warning - you have changed the AAC profile level. ⁞ This is not recommended
If you have problems with the resultant file, it is your own fault
Do not contact project creators

Despite the warning, this worked after re-muxing with mp4box:

$ MP4Box -add video.h264#video -add mp4creator-audio.mp4#audio mp4box.mp4
$ mp4info mp4box-2.mp4
mp4info version 1.6
mp4box-2.mp4:
Track ⁞⁞⁞  Type    Info
1       video   H264 High@4.1, 36.000 secs, 7717 kbps, 1280x688 @ 25.000000 fps
2       audio   MPEG-4 AAC LC, 36.032 secs, 150 kbps, 48000 Hz

Examining the difference, it seems that both ffmpeg and MP4Box were making an MPEG-2 AAC track, and Quicktime wanted an MPEG-4 track instead.

4 Comments:

Anonymous pfn said...

thanks for the writeup, I'm going through the same issues now and trying to figure out how to make ffmpeg insert the metadata itself, rather than going through a multistep mux/remux process

04 August, 2010 21:18  
Anonymous billd said...

I had the same problem with FFMpeg when I ran across your blog. Further research led me to discover that FFMpeg has the ability to remove the ADTS header from wrapped transport stream audio. The following should work:

ffmpeg -i INPUT_MPEG_TRANSPORT.ts -absf aac_adtstoasc -vcodec copy -acodec copy OUTPUT_QUICKTIME.mp4

12 September, 2010 21:27  
Blogger alyawn said...

billd's solution (adding -absf aac_adtstoasc) worked for me! In my case, I had a separate AAC file that was extracted from and MP4 and was getting the QuickTime error. Now, my encoded files work in QT without erro. Good info. Thanks.

01 November, 2010 17:48  
Anonymous Jacob said...

I believe that using mp4box's -mpeg4 option when muxing has the same effect as first changing the audio profile using mp4creator.

11 June, 2011 07:19  

Post a Comment

<< Home