On a Ubuntu 10.04, I am trying to encode a raw video (YUV format) to a H.264 encoded video using below ffmpeg commands:

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

Now I understood that ffmpeg uses libx264 for encoding to H.264 format. Now I have the package x264 - fast H.264 encoder installed on this Ubuntu.

My questions:

  1. Is there any relation between this libx264 which ffmpeg needs and x264 program?
  2. How do I install libx264 and make ffmpeg use this to allow me to encode a video to H.264 format?
link|improve this question

54% accept rate
What about your previous question, wasn't that solved? ffmpeg usage to encode a video to H264 codec format – slhck Aug 12 '11 at 13:25
is there a good reason why you have a space both times between input and .mp4 in input .mp4 ? – barlop Aug 12 '11 at 14:48
@barlop - Thats a typo. – goldenmean Aug 12 '11 at 15:29
@slhck - Thanks but, When I used:- ffmpeg -s 352x240 -i 352x240_420.yuv -vcodec libx264 out.mp4. It gave error - "Unknown encoder 'libx264'". Any further pointers. Is libx264 same as x264 library or something other. – goldenmean Aug 12 '11 at 15:44
feedback

1 Answer

up vote 0 down vote accepted

If you haven't got libx264 installed and enabled yet:

Follow this guide in order to install all necessary tools.

Remove the default Ubuntu packages first, then install the missing ones for building the tools we need:

sudo apt-get remove ffmpeg x264 libx264-dev
sudo apt-get update
sudo apt-get install build-essential checkinstall git libfaac-dev libjack-jackd2-dev \
  libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev \
  libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html \
  yasm zlib1g-dev

Download and install x264 from source.

git clone git://git.videolan.org/x264
cd x264
./configure --enable-static
make
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | \
    awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes \
    --fstrans=no --default

Download and install ffmpeg from source. Here, the --enable-libx264 flag is important.

git clone git://git.videolan.org/ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
    --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 \
    --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no \
  --deldoc=yes --fstrans=no --default
hash x264 ffmpeg ffplay ffprobe

When we're done, we should be able to use x264 over ffmpeg.


If you have libx264 installed and enabled:

First of all, those commands you use look syntactically incorrect. In order to have ffmpeg use x264, you need to supply the -vcodec libx264 argument.

ffmpeg -i input.yuv -vcodec libx264 output.mp4

This should be enough to create an h.264 output file embedded in an MP4 container.

However, this might result in an error due to ffmpeg overriding the x264 settings. I got the error:

[libx264 @ 0x101811200]broken ffmpeg default settings detected
[libx264 @ 0x101811200]use an encoding preset (vpre)

So, let's do this and supply the vpre option:

ffmpeg -i input.yuv -vcodec libx264 -vpre hq output.mp4

Here, "hq" is the name of an ffmpeg preset that includes several options to be passed to x264. There are other presets as well, and they contain most settings that we need for a typical encoding process.

Where you find these presets depends on your ffmpeg installation. Search for files named "ffpreset" in your ffmpeg source folder (if you've compiled from source). Here's a guide on ffmpeg presets too.

link|improve this answer
Also, you should follow this guide to install everything you need, if you haven't yet: HOWTO: Install and use the latest FFmpeg and x264 – slhck Aug 12 '11 at 13:35
where is documentation for -vpre hq ? – barlop Aug 12 '11 at 14:51
@barlop There is no real documentation. vpre takes as an argument the name of an ffmpeg preset, which are by default placed in the ffmpeg source folder. – slhck Aug 12 '11 at 14:56
@slhck - Thanks but, When I used:- ffmpeg -s 352x240 -i 352x240_420.yuv -vcodec libx264 out.mp4. It gave error - "Unknown encoder 'libx264'". Any further pointers. Is libx264 same as x264 library or something other. – goldenmean Aug 12 '11 at 15:45
@slhck - First I installed ffmpeg using Ubuntu package manager(not build from source) and then installed x264 in same manner. Now that I have ffmpeg installed already, but not configured with --enable-libx264 option, Is there any way I can I can make it recognize the libx264 library and used it in encoding – goldenmean Aug 12 '11 at 15:54
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.