Back to posts.

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

Convert PCM audio, 2 channels, interleaved float 32 (le), rate 4800 to wav:

./avconv -f f32le -ac 2 -ar 48000 -i out.pcm out.wav

Speed up a movie:

./avconv -i out.mov -filter:v "setpts=0.5*PTS" out2.mov

Create a h264 based video that only contains IDR frames:

./avconv -i bbb.avi -an -vcodec x264 -g 1 -bsf h264_mp4toannexb out.h264

Convert a file which contains raw rgb24 frames into a yuv420p stream:

avconv -v debug -f rawvideo -pix_fmt rgb24 -s 1280x720 -i frames.raw -pix_fmt yuv420p frames.yuv

Convert a h264 stream into a mp4 file.

avconv -v debug -f h264 -i out.h264 -codec copy -y out.mp4

Convert a raw file with NV12 into a MP4 and set framerate to 60.

./avconv -v debug -r 60 -f rawvideo -pix_fmt nv12 -s 640x480 -i yuy2_generator_downloader.nv12 -r 60 -y yuy2_generator_downloader.mp4

Convert a h264 file to annex-b and disable b-frames:

./avconv -i sourcing2.mp4 -vcodec h264 -an -bsf h264_mp4toannexb -bf 0 data/sourcing2.h264