generating a quicktime compliant mp4 23. Feb 2011
I recently went trough a rather nerve recking video reencoding session. I thought my experience might be useful so I decided to document it. Have fun with my protocol!
I recorded a live stream with rtmpdump:
$ rtmpdump --live --host 123.123.123.123 --tcUrl \
rtmp://123.123.123.123/foobar/ --app foobar/
--playpath live -o video.flv --swfUrl
http://www.domain.net/player.swf
The result was saved to a Flash video container with an h264 and an aac stream:
$ ffmpeg -i video.flv
Seems stream 0 codec frame rate differs from container frame rate:
2000.00 (2000/1) -> 25.00 (25/1)
Input #0, flv, from 'video.flv':
Duration: 14:23:34.72, start: 0.000000, bitrate: N/A
Stream #0.0: Video: h264 (Main), yuv420p, 512x288,
25 tbr, 1k tbn, 2k tbc
Stream #0.1: Audio: aac, 44100 Hz, stereo, s16
With 4968987448 Byte (~5 GB) it was quite large. I wanted to have the video in a well accepted format so I tried to use ffmpeg to copy the streams to an mp4 container:
$ ffmpeg -i video.flv -vcodec copy -acodec copy video.mp4
But after processing for a while it threw an error:
Application provided invalid, non monotonically increasing dts to
muxer in stream 1: 171621324 >= 171620310
This seems to be a known error, but I couldn’t find a working fix so I tried a complete reencoding:
$ ffmpeg -i video.flv -vcodec libx264 -crf 15 \
-vpre default -acodec libfaac -ab 128k video.mp4
The file was digested okay but when I tried opening the file in QuickTime Player 7 on Mac OS X I got an error:
An invalid public movie atom was found in the movie
I tried opening it with QuickTime Player X and saving it to a new MP4 container but I got the same error so I decided to give mencoder a spin instead:
$ mencoder -ovc copy -oac copy video.flv -o video.mp4
But it didn’t want to copy the audio stream:
Audio format 0x4134504d is incompatible with '-oac copy',
please try '-oac pcm' instead or use '-fafmttag' to override it.
So I tried copying the video stream, but reencoding the audio stream:
$ mencoder -ovc copy -of lavf -lavfopts format=mp4 \
-oac faac video.flv -o video.mp4
But this resulted in lots of Skipping frame! so tried my luck with HandBrake instead:
$ HandBrakeCLI --input video.flv --output video.mp4 --quality 20 \
--encoder x264 --ab 128 --large-file
The movie was digested okay, but when trying to open it in QuickTime Player 7 this resulted in an error:
The movie contains an incorrect duration
It seemed to me like the problem might be in the header so I trief my luck with MP4Box:
$ MP4Box -add input.mp4 output.mp4
But when trying to open it in QuickTime Player 7 I got an already seen error:
An invalid public movie atom was found in the movie
So I tried to remux with mp4creator:
$ mp4creator -extract=1 input.mp4 input.h264
$ mp4creator -extract=2 input.mp4 input.aac
$ mp4creator -create=input.h264 -create=input.aac -rate=25 output.mp4
But the process hung at the end. I decided to change my strategy and use Matroska as an intermediate format:
$ ffmpeg -i video.flv -vcodec libx264 -crf 15 -vpre default \
-acodec libfaac -ab 128k video.mkv
I installed Perian and used QTCoffee to remux the file:
$ muxmovie video.mkv -mp4 -o video.mp4
Which finally resulted in an MP4 file which was accepted by QuickTime Player 7 and could be edited and saved in QuickTime Player X. To my understanding all these problems were a result of the rather large file size, since they didn’t occur if I tried the steps with a smaller part the movie. The magic boundary seems to be 4 GB, but I didn’t verify that.
Interessant.
In einem Videoprojekt, das ich voriges Jahr gemacht habe, habe ich auch Handbrake für die Konvertierung genutzt. Vorher hatte ich allerdings auch VLC ausprobiert, der viele interessante Möglichkeiten bietet.
Leider sind all diese Features recht gut versteckt und immer etwas knifflig zu bedienen.
Stimmt, VLC hatte ich in meinem Protokoll ganz vergessen. Den hatte ich als erstes ausprobiert, aber leider ebenfalls ohne Erfolg. Muss mal schauen, woran es gescheitert war, dann ergänze ich das vielleicht noch. Der Funktionsumfang von VLC hat mich ebenfalls verwirrt, aber wenn man damit umgehen kann ist es sicher ein tolles Werkzeug.