avi to mp4

Generally, you want to copy streams without re-encoding them. This avoids loss in quality ( generation loss). Sometimes you can do this strait up with a couple of flags. 

Check it first with avprobe to make sure there's no warnings and that the stream formats are allowed in a mp4 container. (mpeg4 and mp3 are fine)

avprobe -i someVideo.avi

Input #0, avi, from 'someVideo.avi':
  Duration: 00:40:34.59, start: 0.000000, bitrate: 1139 kb/s
    Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 23.98 tbn, 23.98 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, 2 channels, s16p, 128 kb/s
    Metadata:
      title           : someVideo.audio

Since it's coming from an AVI you'll need to pass a few flags and use ffmpeg. avconv will sometimes work, but is more susceptible to PTS and DTS errors. We'll also remove any metadata while we're at it.

ffmpeg -fflags +genpts -i someVideo.avi -flags +global_header -codec copy -map_metadata -1 someVideo.mp4


However, many older AVIs use a B frame 'hack' that will result in jerky video if you just try a -codec copy operation.

avprobe -i someVideo.avi

[mpeg4 @ 0x1ebd380] Invalid and inefficient vfw-avi packed B frames detected
Input #0, avi, from 'someVideo.avi':
  Duration: 01:21:01.00, start: 0.000000, bitrate: 1208 kb/s
    Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 544x400 [PAR 1:1 DAR 34:25], 25 tbn, 25 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, 2 channels, s16p, 121 kb/s


Luckily there is a filter for it. If you is that and pass it though an intermediary mpeg container (I don't know why, probably something to do with the bitstream filter) you can get it to a non-jerky mp4

ffmpeg -i someVideo.avi -codec copy -bsf:v mpeg4_unpack_bframes -f mpeg someVideo.mpg
ffmpeg -fflags +genpts -i someVideo.mpg -flags +global_header -codec copy someVideo.mp4


[mp3 @ 0x2cd89e0] Header missing
However, even though you tell it to generate pts, it will sometimes refuse and you 

 Note: still testing










ffmpeg -fflags +genpts -i someVideo.avi -codec copy -bsf:v mpeg4_unpack_bframes someVideo.mp4

http://superuser.com/questions/257962/how-can-i-convert-avi-files-into-mpgs-with-ffmpeg

https://en.wikipedia.org/wiki/MPEG-4_Part_14
http://stackoverflow.com/questions/18331787/invalid-and-inefficient-vfw-avi-packed-b-frames-detected

You'll see this message for most older AVIs, and it's a problem when converting to another format

    https://ffmpeg.org/pipermail/ffmpeg-devel/2008-November/054385.html

Comments