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.

Wednesday, February 10, 2010

PDF to Word conversion notes

Had a complex PDF to convert to something editable like .doc, so I had another look at what was available.

This comparative test from 2008 was very helpful, as were some readers' comments. It concluded by recommending the koolwire.com service, which was indeed quite good, and also very convenient because it can be used through email. It produced an RTF with mostly actual tables. Visually, however, the tables in this particular case would have needed quite some re-formatting to look like the original ones.

Several readers suggested the PDF-to-Word service at pdftoword.com. For me, this gave me the best looking results. It converted the complex tables into columnized sections instead, but that was fine. (As an aside, it is not very clear which engine this service is using. It is related to Nitro PDF, a commercial Windows application which is promoted from the pdtftoword.com page. Also, the Nitro PDF pages link to the free pdftoword.com service as their free version. However, the produced Word document mentions Solid Converter PDF, another commercial Windows application, in it's properties. Weird...)

I also tried the convertpdftoword.net service which others suggested. It also gave a good looking Word document, but built it with tons of independent text boxes which was quite unconvenient in my case. A closer look, showed that this service was actually using VeryPDF's PDF2Word, which produced an RTF file (but with a .doc extension). PDF2Word turns out to actually be a re-packaging of xpdf, and is free (GPL) software. The source is available, but VeryPDF sells the Windows executable.

The funny thing from theses tests: the only completely useless conversions happened to be the one from Adobe itself.

Conclusion: I had the best results with pdftoword.com. But it all depends on your source document and what you want to do with it.

Labels: , , , , , ,