【libav】libav的常用方法

https://wiki.libav.org/Snippets/avconv

ffmpeg是对libav的封装

avconv

Thanks to roxlu for providing most of them.

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

avconv -i test_input.264 -c:v 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 -c:a copy -vn -y out.aac

Export only video from movie

avconv -i input.mov -an -c:v 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 -framerate 25 -f image2 -i image-%03d.jpeg -b 65536k out.mov

Create video from image sequence (really good quality)

avconv -framerate 25 -f image2 -i %04d.png -c:v h264 -crf 1 out.mov

Extract one second from a video

avconv -ss 00:00:00 -i scanner.mov -t 00:00:01 -c:v 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 -c:v 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 -c:a libmp3lame -qscale 20 -shortest output.mov

Combining image sequences

Combining image sequences which are spread over multiple directories

On unix-like systems

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

On windows, note the slashes

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

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 -c:v mjpeg -i - -i audio.mp3 -c:a libmp3lame -qscale 20 -shortest -r 25 -map 0 -map 1 out.mov

Exporting frames from a video

Exporting to jpeg images

The qscale is the jpeg quality, 1 = excellent, 31 = worst

avconv -i intro.mov -vsync 1 -r 25 -an -y -qscale 1 out_%04d.jpg

Resizing the output on the fly.

avconv -i intro.mov -vsync 1 -r 25 -an -y -qscale 1 -s 1280x720 out_%04d.jpg

Exporting to raw YUV

avconv -v debug -f rawvideo -pix_fmt yuv420p -s 320x240 -i raw.yuv -r 1 -vcodec h264 out.mov

Produce a 10s test video

avconv -y -filter_complex testsrc -t 10s out.avi

Streaming

Test akamai CDN using synthetic video

avconv -filter_complex text testsrc=hd720 -c:v h264 -b:v 500k -f flv rtmp://<USERNAME>:<PASSWORD>@p.<CPCODE>.i.akamaientrypoint.net/EntryPoint/mystream_1_500@<STREAMID>

Streaming pcm audio

Never use the wav container if you plan to stream indefinitely. arecord is provided as example, the alsa or pulsebuiltin capture should work better.

arecord -Dplughw:0,0 -f S16_LE -t raw -r 44100 -c 2 -N - | /usr/bin/avconv  -f s16le -ar 44100 -ac 2 -i - -c:a libfdk_aac -b:a 80k -f mpegts udp://localhost:5000

Restream multicast mpegts to rtmp

Select a specific PID from a multicast mpegts stream and re-encode it before reflecting to an rtmp server

avconv -f mpegts -i udp://host:port -c:a:i:2300 aac -b:a 384k -c:v copy -f flv rtmp://host/live/stream

Interlace a progressive content

Creating new interlaced content is a bad idea in general terms, do that only if you need to feed content to legacy equipment that does not have a progressive mode. 720p50 is always better than 1080i25 and it uses the same bandwidth.

avconv -i INPUT -vf interlace -flags +ildct+ilme OUTPUT

Use avfilter

Use frei0r's bluescreen0r-filter

Make a certain color transparent, for example for webcam chroma key'ing

avconv -i overlay_source -i background_source -filter_complex 'frei0r=bluescreen0r:0/0/255|128,[1:v]overlay=0:0' output_destination

0/0/255|128 are the bluescreen0r-parameters, first color, then the tolerance. The format is blue/green/red|tolerance. The components of the color being alpha'ed out is specificed between 0-255, and the tolerance adjusts how wide a range around the specified color is to be adjusted.

bluescreen0r will ignore all existing alpha-components in the source and completely replace them.

你可能感兴趣的:(【libav】libav的常用方法)