Reputation: 185
I want to play an avi
video format file in browsers using HTML5 video code. Since the
avi
format file doesn't play in browsers i have to convert it into mp4 format file.
For conversion i am using the ffmpeg
code in Windows.
ffmpeg -i input.avi OUTPUT.mp4
The conversion of video is completed but the video codec and audio codec isn't valid thus it fails to play to play using video tag in html5
.
Please find me proper code which coverts the file.
another conversion code i tried was.. ffmpeg -i input.avi -c:v libx264 -preset slow -crf 22 -c:a libfaac -b:a 128k OUTPUTAVINew.mp4
but i got error as libfaac unknown encoder
please help me out and even i downloaded the **libfaac.dll**
but didn't work out
`
Upvotes: 17
Views: 62146
Reputation: 699
For example there is a video file 139MB input.avi
ffprobe input.avi
Input #0, avi, from 'input.avi':
Metadata:
encoder : Lavf51.12.1
Duration: 00:21:20.16, start: 0.000000, bitrate: 891 kb/s
Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 769 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 32000 Hz, stereo, fltp, 112 kb/s
For the nearly loseless re-containering use:
ffmpeg -i "input.avi" -c:v copy -c:a copy "input.mp4"
where -c:v copy
copy video
-c:a copy
copy audio
Conversion about 2 sec, result is input.mp4 138MB. It is fast, and almost same quality as original. Best practice is let the audio in the original format.
ffprobe input.mp4
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.29.100
Duration: 00:21:20.16, start: 0.000000, bitrate: 884 kb/s
Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 769 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 32000 Hz, stereo, fltp, 112 kb/s (default)
Metadata:
handler_name : SoundHandler
If you have time, and want to recodec almost same quality, but 1/3 size, use this:
ffmpeg -i "input.avi" -c:a copy -c:v vp9 -b:v 100K "input.vp9.mp4"
where -c:a copy
copy audio -c:v vp9 -b:v 100K
re-encode video with 100K bitrate. 138MB re-encoding takes about 40min and the new file size is 41MB the quality is nearly same as original, but pixeled a bit.
ffprobe input.vp9.mp4
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf58.29.100
Duration: 00:21:20.16, start: 0.000000, bitrate: 261 kb/s
Stream #0:0(und): Video: vp9 (Profile 0) (vp09 / 0x39307076), yuv420p(tv, progressive), 640x480, 146 kb/s, SAR 1:1 DAR 4:3, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 32000 Hz, stereo, fltp, 112 kb/s (default)
Metadata:
handler_name : SoundHandler
Upvotes: 0
Reputation: 407
Old, but this post comes up tops in searches so...
ffmpeg should easily convert from avi to mp4 without re-encoding. (Do not specify new codecs!)
ffmpeg -i input.avi -c:v copy -c:a copy OUTPUT.mp4
Should also mention that batch conversions run most reliably when the script contains static data with each ffmpeg call on a new line (as opposed to having the script generate each call dynamically using variables).
Upvotes: 24
Reputation: 678
code to avi to mp4.ffmpeg provides the best solution
ffmpeg -i input.avi -strict -2 output.mp4
Upvotes: 11
Reputation: 21
I would suggest you use the latest version of ffmpeg. You don't need to download extra dlls.
Use libvo_aacenc
instead of libfaac
-crf 22
is high use lower say -crf 19
As far my experience I would use
ffmpeg -i input.avi -c:v libx264 -preset slow -crf 19 -c:a libvo_aacenc -b:a 128k
Upvotes: 1