Encoding h.264 on Debian Wheezy with avconv

The Debian team went with libav instead of ffmpeg. Here are the lines I just used to encode h.264 with AAC audio.

avconv -i MVI_2671.MOV -crf 20 -c:v libx264 -preset slow -strict experimental -s 640x360 mvi_2671.mp4

ProRes encoding

If you're forced to use ProRes by someone else's choice to use Final Cut, you can now create Quicktimes of those with ffmpeg.

ProRes 422 HQ

ffmpeg -f image2 -i %d.tif -vcodec prores -profile:v 3 prores422hq.mov

H.264 encoding guide


If you want libx264 encoding in Debian, you'll need to make your own package, or use one from the http://debian-multimedia.org/ repository.

Adding metadata to a Quicktime


In summary...

ffmpeg -i track05.wav \
    -metadata title="Track #5" \
    -metadata author="Unknown Artist" \
    -metadata composer="Composer Unknown" \
    -metadata album="Tracer Video Game Soundtrack" \
    -metadata year="1996" \
    -metadata track="5" \
    -metadata comment="This is redbook CD audio track #5 from the Windows 95 game \"Tracer\"" \
    -metadata genre="Game Soundtrack" \
    -metadata copyright="Copyright 1996 Future Endeavors, Inc." \
    -metadata description="Nifty techno background tune for a futuristic video game" \
    -metadata synopsis="Hey, is this thing on? This is where the 'synopsis' field shows up." \
    -metadata show="Tracer" \
    -metadata episode_id="102" \
    -metadata network="Some network" \
    -acodec alac \
    -y track05.m4a

Concatenate video files

Concatenate two VOB files:

ffmpeg -i "concat:VTS_01_1.VOB|VTS_01_2.VOB" -f mpeg -c copy output.mpeg

Concatenate two MKV, MP4 files with H264 video stream:

ffmpeg-i file-01.mkv -f mpegts -c copy -bsf:v h264_mp4toannexb file-01.mpeg.ts
ffmpeg-i file-02.mkv -f mpegts -c copy -bsf:v h264_mp4toannexb file-02.mpeg.ts
ffmpeg -isync -i "concat:file-01.mpeg.ts|file-02.mpeg.ts" -f matroska -c copy output.mkv

Record only audio from pulseaudio source

You can use this command line to record to two-channel WAV file.

ffmpeg -y -f alsa -ac 2 -ab 256k -i pulse -acodec pcm_s16le audio.wav

Related video. http://www.youtube.com/watch?v=i-hGbw1Wb-w

Screen capture

ffmpeg-user random tip #19
X11 session recording with ffmpeg:
ffmpeg -f oss -i /dev/audio -f x11grab -s $WIDTHx$HEIGHT -r 5 -i :0.0 \
Use xdpyinfo to get WIDTH and HEIGHT values.

That's a pretty terse instruction from Stefano Sabatini's email signature on the ffmpeg-users mailing list, that is just begging for some elaboration.

The first thing that will probably trip people up here is that it looks like Stefano is expecting you to be using the OSS sound system.

In an alternate universe, the 4Front Technology guys offered OSS up under a GPL-compatible license a lot sooner, so ALSA was never written. In this universe, however, if you are running a Linux Kernel, you most likely are running straight ALSA (a professional audio sound system optimized for low-latency), or PulseAudio (a desktop sound system optimized for managing audio from multiple programs).

If you're not using OSS, you'll probably have to use some other flags than -f oss -i /dev/audio to get audio on your screen capture.

You might also check out this PyGTK frontend for ffmpeg. https://launchpad.net/kazam

Screen capture example command lines

All of these examples were done on a workstation with dual monitors. The leftmost monitor is set to 1920x1200.

Uncompressed 8-bit 422

Lossless. Smooth motion. Very large file.

ffmpeg -y -f x11grab -r 24 -s 1920x1200 -i :0.0+0,0 \
    -vcodec rawvideo -pix_fmt uyvy422 foo.mov

4 Mbit/s H.264

Slight desaturation, choppy screen movement. Decent if you're not moving around too much.

ffmpeg -y -f x11grab -r 24 -s 1920x1200 -i :0.0+0,0 \
    -vcodec libx264 -vpre normal -b 4Mb lala.mov

The argument to the -vpre flag should be some libx264 preset from /usr/share/ffmpeg. If the preset's filename is "libx264-lossless_medium.ffpreset", you should use the value "lossless_medium".

Make animation codec quicktime movies from an image sequence with ffmpeg

You can use the -start_frame flag to specify the start frame of the input sequence.

ffmpeg -f image2 -i ./test_sequence.%04d.dpx \
    -vcodec qtrle -r 10 -g 300 -s 1920x1080 test.mov

Input options:

'-f image2' tells ffmpeg its input is an image sequence.
'-i' is the image sequence spec.

Output options:

'-vcodec qtrle' says use qtrle as the output codec.
'-r' is the framerate.
'-g' is the GOP (group of pictures) size.
'-s' is the resolution of the output movie.
'test.mov' is the output filename.

One minute of silence file

One minute of audio silence with ffmpeg. Change codec to taste.

ffmpeg -ar 48000 -t 60 -f s16le -acodec pcm_s16le -i /dev/zero \
    -ab 64K -f mp2 -acodec mp2 -y silence.mp2

"Uncompressed 8-bit" (rawvideo) 422 yuv 2vuy rgb from image sequence

When you make this type of video with Apple's Quicktime, the video info on a Mac will show "Uncompressed 8-bit" as the codec. If you make the same type of video with the command line below the Mac will show "rawvideo" as the codec. Don't be alarmed.

You can actually search the .mov file in a hex editor to find the "rawvideo" string and change it, if it really bothers you.

ffmpeg -f image2 -i /path/to/frames/%d.tif \
    -vcodec rawvideo -pix_fmt uyvy422 -r 24 -y uncompressed.mov

Note that the image2 format expects input frames to start at 0 or 1.

Avid DNxHD codec

http://community.avid.com/forums/p/60895/341626.aspx - An old thread on the topic. Complaints about colorspace.

http://www.itbroadcastanddigitalcinema.com/ffmpeg_howto.html#Encoding_VC-3 - Table of DNxHD bitrates and formats.

ffmpeg -y -f image2 -r 24 -i test.%04d.tif \
    -vcodec dnxhd -b 36Mb -r 23.98 -s 1920x1080 test.mov

Rotate input movie 90 degrees

ffmpeg -vf "transpose=1" -i input.mp4 output.mp4

Pipe raw video in to ffmpeg without a container

02:40:18  rabidsnail> Is it possible to pipe raw video frames into 
   ffmpeg or do I absolutely need a container?
02:48:02  relaxed> rabidsnail: it's possible
02:49:52  relaxed> rabidsnail: cat raw.yuv | ffmpeg -f rawvideo 
   -pix_fmt $pix_fmt -s $framesize -r $framerate -i -

Per-frame md5 checksum

ffmpeg -i video.avi -f framemd5 checksum_output.txt