Blog of roxlu, co-founder of Apollo Media. Contact info[shift+2]apollomedia.nl.

Converting video/audio using avconv

These examples show you how to convert videos using avconv.

The general usage of avconv is:

$avconv [global_options] [input options] -i [some_inputfile] [output_options] [output file].

Convert from raw x264 to quicktime mov:

./avconv -i test_input.264 -vcodec copy output.mov

Convert from raw x264 to flv (when you get an error with monotonically increasing dts):

./avconv -i test_input.264 -vcodec copy output.flv

Convert from flv to mov and specify bitrate:

./avconv -i test_input.flv -b 512k output.mov

Extract audio from movie:

./avconv -i test_input.mp4 -acodec copy -vn -y out.aac

Export only video from movie:

./avconv -i input.mov -an -vcodec copy out.mov

Combine audio and video file

./avconv -i video_input.mov -i audio_input.mp3 -c copy audio_and_video.mov

Create video from image sequence

./avconv -f image2 -i image-%03d.jpeg -b 65536k -r 24 out.mov

Create video from image sequence (really good quality)

./avconv -f image2 -i %04d.png -vcodec h264 -crf 1 -r 24 out.mov

Extract one second from a video

./avconv -ss 00:00:00 -i scanner.mov -t 00:00:01 -vcodec copy scanner_small.mov

Read raw RGB frames from tcp and convert them into a video

./avconv -v debug -f rawvideo -pix_fmt rgb24 -s 320x240 -i tcp://localhost:2233 -vcodec h264 result.mov

Add audio to a video file and make sure the shortest stream is used, also show some debug info

./avconv -v debug -i audio.wav -i video.mp4 -acodec libmp3lame -qscale 20 -shortest output.mov

Combining image sequences which are spread over multiple directories (on unices)

cat dir_a/*.jpg dir_b/*.jpg dir_c/*.jpg | ./avconv -f image2pipe -vcodec mjpeg -i - -r 25 -map 0 -map 1 out.mov

Combining image sequences which are spread over multiple directories (on windows, note the slashes)

type dir_a\\*.jpg dir_b\\*.jpg dir_c\\*.jpg | avconv.exe -f image2pipe -vcodec mjpeg -i - -r 25 -map 0 -map 1 out.mov

Combining image sequences which are spread over multiple directories and set a quality scale, use the shortest stream (audio of video) cat dir_a/*.jpg dir_b/*.jpg dir_c/*.jpg ./avconv | ./avconv -f image2pipe -vcodec mjpeg -i - -i audio.mp3 -acodec libmp3lame -qscale 20 -shortest -r 25 -map 0 -map 1 out.mov

Exporting frames from a video; qscale is the quality, 1 = excellent, 31 = worst ./avconv -i intro.mov -vsync 1 -r 25 -an -y -qscale 1 out_%04d.jpg

Exporting frames from a video + resize output ; qscale is the quality, 1 = excellent, 31 = worst ./avconv -i intro.mov -vsync 1 -r 25 -an -y -qscale 1 -s 1280x720 out_%04d.jpg

You can write raw YUV frames into one container "yuv.raw" and then convert it into a video using: ./avconv -v debug -f rawvideo -pix_fmt yuv420p -s 320x240 -i raw.yuv -r 1 -vcodec h264 out.mov