ffmpeg -f mpegts -stream_loop -1 -re -i war.ts -c:v libx264 -s 1280x720 -b:v 1000k -c:a libfdk_aac -ar 48000 -f flv rtmp://localhost/hls/333333
ffmpeg -i war.ts -f mpegts -an -c:v rawvideo -pix_fmt yuyv422 ff422.yuv
ffmpeg -i input.mov -c:v libx264 -vf 'yadif,format=pix_fmts=yuv420p'
access.mp4
1. c:v c:a -- specifiy codec for video audio
-c:v mpeg4
-c:a libmp3lame
2. b:v b:a -- specify bitrate for video audio
-b:v 800k
-b:a 128k
3. f -- specify format for video
-f avi
4. s -- specify frame size for video
aspect -- specify video display aspect ratio
-s 720x480
-aspect 4:3
5. r -- specifiy fps for video
-r 25
6. map
The first -map
option on the command line specifies the source for output stream 0, the second -map
option specifies the source for output stream 1, etc.
6.1 ffmpeg -i input.avi -map 0 output.h264
to map ALL streams from the first input file to output
6.2For example, if you have two audio streams in the first input file, these streams are identified by "0:0"
and "0:1". You can use -map
to select which streams to place in an output file. For example:
ffmpeg -i input.avi -map 0:1 output.wav
to map the input stream in ‘input.avi’ identified by "0:1" to the (single) output stream in ‘output.wav’.
6.3 For example, to select the stream with index 2 from input file ‘a.mov’
(specified by the identifier "0:2"), and stream with index 6 from input ‘b.mov’
(specified by the identifier "1:6"), and copy them to the output file ‘out.mov’:
ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov
6.4 To select all video and the third audio stream from an input file
ffmpeg -i input.avi -map 0:v -map 0:a:2 output.h264
6.5 To map all the streams except the second audio, use negative mappings
ffmpeg -i input.avi -map 0 -map -0:a:1 output.h264
You can disable some of those video audio or subtitle stream by using -vn/-an/-sn
options. For full manual control, use the -map
option.
7. q and qscale
8. filtering
Before encoding, ffmpeg
can process raw audio and video frames using filters from the libavfilter library. Several chained filters form a filter graph. ffmpeg
distinguishes between two types of filtergraphs - simple and complex.
8.1 simple filtergraphs
Simple filtergraphs are those that have exactly one input and output, both of the same type. In the above diagram they can be represented by simply inserting an additional step between decoding and encoding:
_________ __________ ______________ | | | | | | | decoded | simple filtergraph | filtered | encoder | encoded data | | frames | -------------------> | frames | ---------> | packets | |_________| |__________| |______________| |
Simple filtergraphs are configured with the per-stream ‘-filter’ option (with ‘-vf’ and ‘-af’ aliases for video and audio respectively). A simple filtergraph for video can look for example like this:
_______ _____________ _______ _____ ________ | | | | | | | | | | | input | ---> | deinterlace | ---> | scale | ---> | fps | ---> | output | |_______| |_____________| |_______| |_____| |________| |
8.2 complex filtergraphs
9. some examples
9.1 file streaming
ffmpeg -f mpegts -i film.v -an -c:v libx264 -f h264 film.h264
ffmpeg -f mpegts -i film.v -an -c:v libx264 -s 720x480 -aspect 4:3 -b:v(-vb) 1024k -f h264 film1.h264
ffmpeg -f mpegts -i film.v -f s16le -c:a pcm_s16le film.wav
ffmpeg -f mpegts -i fm352.ts -vn -ac 1 -f s16le -c:a pcm_s16le fm1.wav
ffmpeg -f s16le -i fm_01.wav -vn -c:a libfaac -ac 1 -ar 48000 -b:a 128k -f mp4 fm_aac_01.mp4
--enable-libx264 \
--enable-encoder=rawvideo \
--enable-decoder=rawvideo \
--enable-encoder=libx264 \
--enable-decoder=h264 \
--enable-encoder=mp3 \
--enable-decoder=mp3 \
--enable-encoder=pcm_s16le \
--enable-decoder=pcm_s16le \
--enable-encoder=aac \
--enable-decoder=aac \
--disable-muxers \
--enable-muxer=mpegts \
--enable-muxer=h264 \
--enable-muxer=aac \
--enable-muxer=pcm_s16le \
--disable-demuxers \
--enable-demuxer=mpegts \
--enable-demuxer=aac \
--enable-demuxer=pcm_s16le \
ffmpeg -f mpegts -i film.v -f s16le -c:a pcm_s16le film.wav
ffmpeg -f mpegts -i fm352.ts -vn -ac 1 -f s16le -c:a pcm_s16le fm1.wav
ffmpeg -f rawvideo -s 768x432 -i cap.yuv -an -c:v libx264 -f h264 cap.h264
ffmpeg -f mpegts -i film.v -c:a libfaac -ac 1 -c:v libx264 -s 720x480 -aspect 4:3 -b:v 512k -r 16 -f mpegts fm.ts
ffmpeg -i input -c:v libx264 -preset slow -crf 22 -x264opts keyint=123:min-keyint=20 -c:a copy output.mkv
ffmpeg -f mpegts -i film.v -c:a libfaac -c:v libx264 -s 352x288 -b:v 200k -f 3gp Battle1.3gp
ffmpeg -f mpegts -i film352.ts -c:a libopencore_amrnb -ar 8000 -ac 1 -c:v libx264 -s qcif -f 3gp Battle2.3gp
Notes: amrnb only support single channel, therefore the option -ac 1 is a must.
9.2 rawvideo
ffmpeg -i test3.264 -s 352x288 -pix_fmt yuv420p test31.yuv
ffmpeg -s 352x288 -i /.live_stream_fifo -pix_fmt yuv420p -vcodec rawvideo -s 176x144 test31.yuv
9.3 network streaming
ffmpeg -i rtsp://192.168.0.158:8000/sample_h264_300kbit.mp4 -c:a libfaac -c:v libx264 -f mpegts sample.ts
ffmpeg -i rtsp://admin:admin@192.168.0.109:554/mpeg4cif -c:v rawvideo -s 352x255 -f rawvideo 111.yuv
./ffmpeg -re -f mpegts -i film.v -c:a libfaac -ac 1 -c:v libx264 -s 352x288 -aspect 4:3 -b:a 100k -b:v 200k -preset fast -f flv 'rtmp://192.168.0.158/live/sss1'
./ffmpeg -re -f mpegts -i film.v -c:a libfaac -ac 1 -c:v libx264 -s 352x288 -aspect 4:3 -b:a 100k -b:v 200k -preset fast -f flv 'rtmp://192.168.0.158/live/sss1 live=1'
./ffmpeg -re -f mpegts -i film.v -c:a libfaac -ac 1 -c:v libx264 -s 352x288 -aspect 4:3 -b:a 100k -b:v 200k -preset fast -f flv 'rtmp://192.168.0.158/live/sss1.flv'
./ffmpeg -re -f mpegts -i film.v -c:a libfaac -ac 1 -c:v libx264 -s 352x288 -aspect 4:3 -b:a 100k -b:v 200k -preset fast -f flv 'rtmp://192.168.0.158/live/sss1.flv live=1'
ffmpeg -re -i 'rtmp://192.168.137.66/live/sss1 live=1' -an -c:v rawvideo -s 352x288 -f rawvideo tt.yuv
ffmpeg -f mpegts -i ../film.v -an -c:v libx264 -s 720x480 -b:v 1000k -flags +global_header -f rtp rtp://192.168.0.58:55002 -vn -c:a libfaac -b:a 128k -flags +global_header-f rtp rtp://192.168.0.58:55004 >111.sdp
ffmpeg -i ./film1.ts -f mpegts -vn -c:a libfaac -ac 1 -f adts fm.aac.adts
ffmpeg -i ./film1.ts -f mpegts -vn -c:a ac3 -ac 1 -f adts fm.ac3.adts
ffmpeg -i ./film1.ts -f mpegts -vn -c:a g722 -ac 1 -f rtp rtp://224.135.6.17:5556
ffmpeg -re -i ./film1.ts -f mpegts -vn -c:a g722 -ac 1 -f rtp rtp://224.135.6.17:50056 >test.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
t=0 0
a=tool:libavformat 55.48.100
m=video 55002 RTP/AVP 96
c=IN IP4 224.235.6.17
b=AS:1000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAHqzZQLQ9v/AC8AHhAAADA+kAALuADxYtlg==,aOvssiw=; profile-level-id=64001E
m=audio 55004 RTP/AVP 97
c=IN IP4 224.235.6.17
b=AS:128
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190
ffmpeg -f mpegts -re -i ./film1.ts -an -c:v libx264 -s 720x480 -b:v 1000k -flags +global_header -f rtp rtp://192.168.1.149:55002 >111.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.1.149
t=0 0
a=tool:libavformat 55.48.100
m=video 55002 RTP/AVP 96
b=AS:1000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAHqzZQLQ9v/AC8AHhAAADA+kAALuADxYtlg==,aOvssiw=; profile-level-id=64001E
在 192.168.1.149 PC 机上, 用VLC打开111.sdp, VLC 将能播放rtp视频流。
ffmpeg -f mpegts -re -i ./film1.ts -an -c:v libx264 -s 720x480 -b:v 512k -flags +global_header -f rtp rtp://192.168.1.149:55002 -vn -c:a libfaac -b:a 32k -flags +global_header -f rtp rtp://192.168.1.149:55004 >111.sdp
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
t=0 0
a=tool:libavformat 55.48.100
m=video 55002 RTP/AVP 96
c=IN IP4 192.168.1.149
b=AS:512
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAHqzZQLQ9v/AC8AHhAAADA+kAALuADxYtlg==,aOvssiw=; profile-level-id=64001E
m=audio 55004 RTP/AVP 97
c=IN IP4 192.168.1.149
b=AS:32
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190
在 192.168.1.149 PC 机上, 用VLC打开111.sdp, VLC 将能播放rtp音视频流。
====================================================================================
ffmpeg -f mpegts -re -i ./film1.ts -an -c:v libx264 -s 720x480 -b:v 512k -flags +global_header -f rtp rtp://192.168.1.149:55002 -vn -c:a adpcm_g722 -ac 1 -flags +global_header -f rtp rtp://192.168.1.149:55004 >111.sdp
v=0^M
o=- 0 0 IN IP4 127.0.0.1^M
s=No Name^M
t=0 0^M
a=tool:libavformat 55.48.100^M
m=video 55002 RTP/AVP 96^M
c=IN IP4 192.168.1.149^M
b=AS:512^M
a=rtpmap:96 H264/90000^M
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAHqzZQLQ9v/AC8AHhAAADA+kAALuADxYtlg==,aOvssiw=; profile-level-id=64001E^M
m=audio 55004 RTP/AVP 97^M
c=IN IP4 192.168.1.149^M
b=AS:128^M
a=rtpmap:97 G722/8000/1^M
ffmpeg -f mpegts -i ./film1.ts -an -c:v rawvideo -s 720x480 -pix_fmt yuv420p -f rawvideo fm.yuv
ffmpeg -i ./film1.ts -f mpegts -c:a libfaac -b:a 512k -ac 2 -ar 48000 -c:v libx264 -b:v 1536k -f mpegts ff.ts
./x264 --input-res 1280x720 --input-csp i420 --bitrate 1536 --fps 30 --profile high --level 52 -o fm720.h264 fm720p.yuv
1. AVIOContext
(AVIOContext *)->(URLContext *)opaque->(FileContext *)priv_data
2. AVFormatContext
(AVFormatContext *)->(MpegTSContext *)priv_data
3.
(MpegTSFilter *)->(MpegTSContext *)u.section_filter.opaque