ffmpeg command line option makeup - 02

本文详细介绍使用FFmpeg进行音视频处理的各种实用案例,包括文件流处理、原始视频处理及网络流传输等,并深入探讨了如何配置不同类型的过滤器图表以实现复杂的音视频处理任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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

 

 


<think>好的,用户遇到了在编译FFmpeg时出现“Unknown option '--enable-optimization'”的问题,需要帮助解决。首先,我要确认这个错误的原因。用户可能在配置时使用了这个选项,但FFmpeg的configure脚本并不支持它。 接下来,我需要回忆FFmpeg的编译选项。FFmpeg的configure脚本通常使用--enable-xxx或--disable-xxx来开启或关闭功能,但optimization这个选项可能不存在。用户可能混淆了其他项目的配置选项,比如x264或某些库的优化选项。 然后,我应该考虑用户可能从哪里看到这个选项。也许是一些过时的教程或文档,或者是用户自己记错了。需要建议用户查阅官方文档或运行./configure --help来查看所有可用选项。 另外,用户可能想优化编译参数。虽然没有--enable-optimization,但FFmpeg默认会启用优化。如果需要更多控制,可以设置CFLAGS和CXXFLAGS环境变量,比如-O3或者特定的架构优化选项。 还需要检查用户使用的FFmpeg版本,如果版本较旧,可能配置选项有所不同,建议更新到最新版本。同时,确保依赖库正确安装,避免其他配置错误。 最后,给出一个示例配置命令,帮助用户正确使用常见的优化选项,并提醒根据具体需求调整。这样用户就能正确编译,避免再次遇到这个问题。</think>在编译FFmpeg时出现`Unknown option "--enable-optimization"`错误,通常是因为该配置选项不存在于FFmpeg的构建系统中。以下是问题分析和解决方案: --- ### **问题原因** 1. **无效参数**:FFmpeg的`configure`脚本本身并没有`--enable-optimization`这个选项。这个参数可能是某些过时的教程或第三方脚本中提到的错误选项。 2. **混淆项目**:某些其他开源项目(如x264、libvpx等)可能支持类似的优化选项,但FFmpeg的构建系统并不使用这个名称。 --- ### **解决方案** #### 1. **移除无效参数** 直接删除`--enable-optimization`参数: ```bash ./configure --prefix=/usr/local --enable-shared --enable-gpl --enable-libx264 ``` #### 2. **检查合法参数** 通过以下命令查看所有可用配置选项: ```bash ./configure --help ``` #### 3. **实际优化配置** FFmpeg默认会启用编译器优化(如`-O3`)。若需要手动控制优化级别,可通过环境变量实现: ```bash # 使用-O3优化级别 export CFLAGS="-O3" export CXXFLAGS="-O3" # 再运行configure ./configure --prefix=/usr/local --enable-shared ``` #### 4. **架构特定优化** 根据CPU架构启用指令集优化: ```bash # 示例:为x86-64启用AVX2指令集 ./configure --enable-avx2 --enable-lto ``` --- ### **完整示例** ```bash # 清理旧配置(如有) make distclean # 设置编译优化参数 export CFLAGS="-O3 -march=native" export CXXFLAGS="-O3 -march=native" # 配置并编译 ./configure \ --prefix=/usr/local \ --enable-shared \ --enable-gpl \ --enable-libx264 \ --enable-libfdk-aac \ --enable-nonfree make -j$(nproc) sudo make install ``` --- ### **注意事项** - **版本检查**:确保使用最新版FFmpeg(通过`git clone https://git.ffmpeg.org/ffmpeg.git`获取)。 - **依赖库**:如果启用了`--enable-libx264`等选项,需提前安装对应开发库。 - **错误排查**:遇到其他错误时,检查`config.log`文件中的详细日志。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值