ffmpeg usage to encode a video to H264 codec format
Solution 1
I believe you have libx264
installed and configured with ffmpeg
to convert video to h264
... Then you can try with -vcodec libx264
... The -format
option is for showing available formats, this is not a conversion option I think...
Solution 2
I used these options to convert to the H.264/AAC .mp4 format for HTML5 playback (I think it may help other guys with this problem in some way):
ffmpeg -i input.flv -vcodec mpeg4 -acodec aac output.mp4
UPDATE
As @LordNeckbeard mentioned, the previous line will produce MPEG-4 Part 2
(back in 2012 that worked somehow, I don't remember/understand why). Use the libx264
encoder to produce the proper video with H.264/AAC. To test the output file you can just drag it to a browser window and it should playback just fine.
ffmpeg -i input.flv -vcodec libx264 -acodec aac output.mp4
Solution 3
I believe that by now the above answers are outdated (or at least unclear) so here's my little go at it.
I tried compiling ffmpeg with the option --enable-encoders=libx264
and it will give no error but it won't enable anything (I can't seem to find where I found that suggestion).
Anyways step-by-step, first you must compile libx264 yourself because repository version is outdated:
wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
tar --bzip2 -xvf last_x264.tar.bz2
cd x264-snapshot-XXXXXXXX-XXXX/
./configure
make
sudo make install
And then get and compile ffmpeg with libx264 enabled. I'm using the latest release which is "Happiness":
wget http://ffmpeg.org/releases/ffmpeg-0.11.2.tar.bz2
tar --bzip2 -xvf ffmpeg-0.11.2.tar.bz2
cd ffmpeg-0.11.2/
./configure --enable-libx264 --enable-gpl
make
sudo install
Now finally you have the libx264 codec to encode, to check it you may run
ffmpeg -codecs | grep h264
and you'll see the options you have were the first D means decoding and the first E means encoding
Solution 4
"C:\Program Files (x86)\ffmpegX86shared\bin\ffmpeg.exe" -y -i "C:\testfile.ts" -an -vcodec libx264 -g 75 -keyint_min 12 -vb 4000k -vprofile high -level 40 -s 1920x1080 -y -threads 0 -r 25 "C:\testfile.h264"
The above worked for me on a Windows machine using a FFmpeg Win32 shared build by Kyle Schwarz. The build was compiled on: Feb 22 2013, at: 01:09:53
Note that -an defines that audio should be skipped.
goldenmean
struct descriptionOf { int elligent_Developer; short list_of_proven_skills; long list_of_ambitions; long long int erest_in_various_technologies; double effort_in_achieving_skills_and_ambitions; float ing_innovator; char of_a_hands_on_doer; }goldenmean; Software Developer with work experience in areas of Video/Image processing and codecs,DSP and multimedia Systems,on DSP/Multicore processor architecures, for devices and applications in Consumer Electronics, Communications industry. Programming languages: C,C++,Matlab/Octave,Python,DSP or RISC assembly languages.
Updated on March 07, 2020Comments
-
goldenmean over 4 years
I have a *.mp4 video file(MPEG4 video codec) and I am trying to convert this to a H264 video codec format(raw h.264 format) using ffmpeg on Linux(Version - FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1, Copyright (c) 2000-2009 Fabrice Bellard,) using command line as shown below,
ffmpeg -i input .mp4 output.h264
but I get an error saying -
Unsupported codec for output stream #0.0
Then when i try this option:
ffmpeg -i input .mp4 -formats h264 output.h264
it still does not work, and gives -
Seems stream 0 codec frame rate differs from container frame rate: 59.94 (5994/100) -> 29.97 (30000/1001) Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Rapture.mp4': Duration: 00:02:06.44, start: 0.000000, bitrate: 26574 kb/s Stream #0.0(eng): Video: h264, yuv420p, 1920x1080, 29.97 tbr, 29.97 tbn, 59.94 tbc Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16
And then it prints out help on the formats which we get when we do
ffmpeg -formats
When I checked the help,
ffmpeg -formats
, I see below information related to H264 file format and codec:File format : DE h264 raw H.264 video format Codecs: D V D h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
My questions :
How can I convert the video to a H264 encoded video (raw H264 video format)
When I do
ffmpeg -formats
, I see many acronyms for the codecs supported, I see many acronyms before the codec name/type such as - D V D S E A, what do they stand for?How to use the ffmpeg options
-vcodec
and-formats
?
-
goldenmean about 13 yearsI have x264 installed on this linux machine, but when I use -vcodec libx264, it gives error "Unknown encoder 'libx264' " . I guess when I installed x264 , libx264 would also have been installed. Am i right. Also what configuration is needed to use libx264 to use with ffmpeg. How to configure ffmpeg which is already installed to use this libx264?
-
Muhammad Razib about 13 yearsHi, have a look at here ubuntuforums.org/showthread.php?t=786095 . During configuration of ffmpeg you have to enable libx264 codec using --enable libx264 option
-
goldenmean about 13 yearsThat page says, If I have ffmpeg installed previously, I need to remove/uninstall , then build the libx264 and ffmpeg from source. I can do that, but isn't there any 'easier' way to install libx264 using the ubuntu pacgae manager/install apt-get install <libx264 something>..
-
Muhammad Razib about 13 years@goldenman: I tried to use libx264 once with already installed ffmpeg, but I could not. I think ffmpeg puts only those codecs information in libavcodec that have been configured using --enable option. btw libx264 does not give much trouble installing from source :)...So better to configure and make ffmpeg newly with libx264
-
Leigh Caldwell over 11 yearsI found that make install for libx264 installed only the executable x264 program, but not the libraries. After I used install-lib-dev install-lib-shared and install-lib-static it worked fine (I'm not sure which of these is necessary but I succeeded with all three).
-
Rafael Xavier over 11 yearsGreat Ubuntu installation guide ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide
-
Salmaan over 9 yearswhen i use -vcodec mpeg4, browser only runs audio not video
-
Alex K over 9 years@Salmaan you might not have the video codec on the system, you might want to try
ffmpeg -codecs
to see what you have available -
malat almost 9 yearsPlease edit your answer
sameq
is not what you want (See ffmpeg FAQ 3.17 Why was the ffmpeg -sameq option removed? What to use instead?) -
Don Law almost 9 yearsThanks malat - I've been wasting options all this time.
-
Dr.jacky over 8 yearsIf i'm going to compile ffmpeg for ARM processors, should I compile libx264 same as ffmpeg?! (do some specific stuff for libx264 too?).
-
Ian Beyer about 8 years@Salmaan That's because mpeg4 is not h.264/AVC.
-
llogan over 6 yearsThis does not output H.264 video. Using
mpeg4
produces the old, legacy MPEG-4 Part 2 video, not H.264 video. This will not work in HTML5 video. Changempeg4
tolibx264
to encode H.264 video. -
llogan over 6 yearsAdding
-movflags +faststart
is recommended for HTML5 playback (and all other progressive download playback) so it can begin playing before the file is completely downloaded by the viewer.