ffmpeg convert mov file to mp4 for HTML5 video tag IE9
Solution 1:
For ffmpeg
:
ffmpeg -i {input}.mov -vcodec h264 -acodec aac -strict -2 {output}.mp4
You may also add the -q:v
/-q:a
parameter to specify the quality of the video. You may also use HandBrake which is a simpler encoder than ffmpeg.
For HandBrake
:
handbrakecli -i {input}.mov -e x264 -E facc -o {output}.mp4
EDIT: I found the solution! Here is a ZIP with a working demo that I tested on IE 9 and Firefox!
http://www.mediafire.com/download/kyavlpudybg0bc1/HTML5_video.zip
Also, the above demo has a flash fallback, so it should work on IE8 and less.
Same ffmpeg
command used.
EDIT: I had to re-upload the video, since my hosting service is down for now. Now it is hosted on mediafire. I found they are the best file sharing service. Minimum ads, no registration, no 30 sec wait.
Also, check out this discussion on the videojs website: http://help.videojs.com/discussions/problems/1020-ffmpeg-command-produce-your-demonstration-video.
VERY IMPORTANT! Make sure to click the 'Allow Active Content' button to allow the video when running locally!
Video of the problem I have and my solution: See my demo mentioned above.
HTML code used while testing:
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
I analyzed a working test video that w3schools provides (it works on IE), and I found out that they used HandBrake to encode the video.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'movie.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp42isomavc1
creation_time : 2010-05-11 10:32:06
encoder : HandBrake 0.9.4 2009112300
Duration: 00:00:12.61, start: 0.000000, bitrate: 202 kb/s
Chapter #0.0: start 0.000000, end 12.612000
Metadata:
title :
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 320x240, 80 kb/s, 29.65 fps, 29.97 tbr, 90k tbn, 59.31 tbc
Metadata:
creation_time : 2010-05-11 10:32:06
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 115 kb/s
Metadata:
creation_time : 2010-05-11 10:32:06
Stream #0:2(und): Subtitle: mov_text (text / 0x74786574)
Metadata:
creation_time : 2010-05-11 10:32:06`
Solution 2:
A Primary journey to ffmpeg
Download latest ffmpeg and its presets http://www.ffmpeg.org/download.html
Follow the instructions to install Ffmpeg Binary In Windows
Instructions:
- Get the latest build from the arrozcru autobuilds page
- Unzip the folder into C:/Program Files/ffmpeg
- Add C:/Program Files/ffmpeg/bin to your system’s PATH environment variable
Optional libx264 preset setup:
If you use libx264 presets (by using the -vpre flag) you need to do the following setup.
- Create a HOME environment variable for your user pointing to your home directory. (e.g. for Vista/7/8 C:/Users/moose or for XP C:/Documents and Settings/moose )
- Create a .ffmpeg folder in your home directory
- Copy the preset files from C:/Program Files/ffmpeg/share/*.ffpreset into %HOME%/.ffmpeg
- Now you can open a command prompt and use ffmpeg. :D (e.g. This is my Vimeo video conversion command. ffmpeg -i input.mov -vcodec libx264 -vpre hq -crf 24 -g 25 -acodec libmp3lame -ab 192k -ar 44100 output.mp4 )
*NOTE: libfaac is not included in the build since libfaac is considered to be a non-free plugin
Remember to set the HOME environmental variable in windows
- Copy the presets under the environmental variable folder
- You need to use the following commands to convert using ffmpeg:
For mp4 (H.264 / ACC):
ffmpeg -i INPUTFILE -b 1500k -vcodec libx264 -vpre slow -vpre baseline -g 30 "OUTPUTFILE.mp4"
For webm (VP8 / Vorbis):
ffmpeg -i "INPUTFILE" -b 1500k -vcodec libvpx -acodec libvorbis -ab 160000 -f webm -g 30 "OUTPUTFILE.webm"
For ogv (Theora / Vorbis):
ffmpeg -i "INPUTFILE" -b 1500k -vcodec libtheora -acodec libvorbis -ab 160000 -g 30 "OUTPUTFILE.ogv"
Solution 3:
from orig link...
WebM is fully supported in ffmpeg 0.6 and later. On the command line, run ffmpeg with no parameters and verify that it was compiled with VP8 support:
you@localhost$ ffmpeg
FFmpeg version SVN-r23197, Copyright (c) 2000-2010 the FFmpeg developers
built on May 19 2010 22:32:20 with gcc 4.4.3
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc
--enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora
--enable-libx264 --enable-libxvid --enable-x11grab --enable-libvorbis
--enable-libvpx
If you don’t see the magic words “--enable-libvorbis
” and “--enable-libvpx
” you don’t have the right version of ffmpeg. (If you compiled ffmpeg yourself, check to see if you have two versions installed. That’s fine, they won’t conflict with each other. You’ll just need to use the full path of the VP8-enabled version of ffmpeg.)
I’m going to do a two-pass encode. Pass 1 just scans through the input video file (-i pr6.dv) and writes out some statistics to a log file (which will be auto-named pr6.dv-0.log). I specify the video codec with the -vcodec parameter:
you@localhost$ ffmpeg -pass 1 -passlogfile pr6.dv -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i pr6.dv -vcodec libvpx -b 614400 -s 320x240 -aspect 4:3 -an -y NUL
Most of the ffmpeg command line has nothing to do with VP8 or WebM. libvpx does support a number of VP8-specific options that you can pass to ffmpeg, but I don’t yet know how any of them work. Once I find a good explanation of them, I’ll link it here and incorporate them into the narrative if it’s worthwhile to do so.
For the second pass, ffmpeg will read the statistics it wrote during the first pass and actually do the encoding of the video and the audio. It will write out a .webm file.
you@localhost$ ffmpeg -pass 2 -passlogfile pr6.dv -threads 16 -keyint_min 0 -g 250 -skip_threshold 0 -qmin 1 -qmax 51 -i pr6.dv -vcodec libvpx -b 614400 -s 320x240 -aspect 4:3 -acodec libvorbis -y pr6.webm
There are five important parameters here:
-
-vcodec libvpx
specifies that we’re encoding with the VP8 video codec. WebM always uses VP8 video. -
-b 614400
specifies the bitrate. Unlike other formats, libvpx expects the bitrate in actual bits, not kilobits. If you want a 600 kbps video, multiply 600 by 1024 to get 614400. -
-s 320x240
specifies the target size, width by height. -
-aspect 4:3
specifies the aspect ratio of the video. Standard definition video is usually 4:3, but most high-definition video is 16:9 or 16:10. In my testing, I found that I had to specify this explicitly on the command line, instead of relying on ffmpeg to autodetect it. -
-acodec libvorbis
specifies that we’re encoding with the Vorbis audio codec. WebM always uses Vorbis audio.