94

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 :

  1. How can I convert the video to a H264 encoded video (raw H264 video format)

  2. 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?

  3. How to use the ffmpeg options -vcodec and -formats?

sjngm
  • 12,423
  • 14
  • 84
  • 114
goldenmean
  • 18,376
  • 54
  • 154
  • 211
  • 5
    D..... = Decoding supported .E.... = Encoding supported ..V... = Video codec ..A... = Audio codec ..S... = Subtitle codec ...S.. = Supports draw_horiz_band ....D. = Supports direct rendering method 1 .....T = Supports weird frame truncation ; use ffmpeg -codecs – Paul Jun 05 '13 at 06:57

5 Answers5

101

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

Alex K
  • 6,737
  • 9
  • 41
  • 63
  • when i use -vcodec mpeg4, browser only runs audio not video – Salmaan Mar 05 '15 at 06:50
  • 1
    @Salmaan you might not have the video codec on the system, you might want to try `ffmpeg -codecs` to see what you have available – Alex K Mar 11 '15 at 07:33
  • 1
    @Salmaan That's because mpeg4 is not h.264/AVC. – Ian Beyer May 13 '16 at 13:01
  • 3
    **This 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. Change `mpeg4` to `libx264` to encode H.264 video. – llogan Mar 01 '18 at 18:42
  • 5
    Adding `-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. – llogan Mar 10 '18 at 19:10
64

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...

Wtower
  • 18,848
  • 11
  • 103
  • 80
Muhammad Razib
  • 1,297
  • 9
  • 13
  • 2
    I 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? – goldenmean Apr 15 '11 at 15:52
  • Hi, have a look at here http://ubuntuforums.org/showthread.php?t=786095 . During configuration of ffmpeg you have to enable libx264 codec using --enable libx264 option – Muhammad Razib Apr 15 '11 at 16:08
  • 2
    That 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 .. – goldenmean Apr 15 '11 at 16:11
  • @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 – Muhammad Razib Apr 15 '11 at 16:29
  • Great Ubuntu installation guide https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide – Rafael Xavier Jan 20 '13 at 14:45
6

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

Ivaylo Petrov
  • 1,162
  • 9
  • 18
JunCTionS
  • 442
  • 5
  • 13
  • 2
    I 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). – Leigh Caldwell Jan 03 '13 at 21:38
  • If i'm going to compile ffmpeg for ARM processors, should I compile libx264 same as ffmpeg?! (do some specific stuff for libx264 too?). – Dr.jacky Dec 08 '15 at 10:36
3
"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.

Shjiemon
  • 31
  • 1
-3

I have a Centos 5 system that I wasn't able to get this working on. So I built a new Fedora 17 system (actually a VM in VMware), and followed the steps at the ffmpeg site to build the latest and greatest ffmpeg.

I took some shortcuts - I skipped all the yum erase commands, added freshrpms according to their instructions:

wget http://ftp.freshrpms.net/pub/freshrpms/fedora/linux/9/freshrpms-release/freshrpms-release-1.1-1.fc.noarch.rpm
rpm -ivh rpmfusion-free-release-stable.noarch.rpm

Then I loaded the stuff that was already readily available:

yum install lame libogg libtheora libvorbis lame-devel libtheora-devel

Afterwards, I only built the following from scratch: libvpx vo-aacenc-0.1.2 x264 yasm-1.2.0 ffmpeg

Then this command encoded with no problems (the audio was already in AAC, so I didn't recode it):

ffmpeg -i input.mov -c:v libx264 -preset slow -crf 22 -c:a copy output.mp4

The result looks just as good as the original to me, and is about 1/4 of the size!

Don Law
  • 1,329
  • 13
  • 7
  • 2
    Please 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?) – malat Aug 16 '15 at 06:01
  • Thanks malat - I've been wasting options all this time. – Don Law Aug 19 '15 at 23:24