views:

17

answers:

0

Hi,
I was wondering why youtube video saved locally were not accepted by iTunes even if most of them are effectively using h264 video codec and AAC sound codec. iPhone and iPad are able to read them natively in YouTube.app and MobileSafari as well.

This is a matter of container. There are many way, out here, to re-encode such video but this is a waste of time and processing power since what we only need is repackaging the two streams, not re-encoding.

I tried to do this with vlc but it mangled the sound. So I eventually used ffmpeg to do the job, fast and easy. Here is the command line :

ffmpeg -i video_file.flv  -vcodec copy -acodec copy video_file.m4v

This runs as fast as a file copy and the resulting file is accepted by iTunes and plays nicely on iPhone/iPad.
Here under a batch command (bash) to convert every flv files in current directory

for i in *.flv; do  ffmpeg -i "$i"  -vcodec copy -acodec copy "${i%%.flv}.m4v"; done

Edit: These commands do not test for the original codecs, just keeping them. If you use one on an old video, it can fail. By watching the output of ffmpeg one can check the effective codec used. BTW, when copying the source h264, ffmpeg use a cryptic denomination. It works anyway.