当前位置:   article > 正文

FFmpeg最常用命令参数详解及应用实例_ffmpeg 参数

ffmpeg 参数

FFMPEG堪称自由软件中最完备的一套多媒体支持库,它几乎实现了所有当下常见的数据封装格式、多媒体传输协议以及音视频编解码器,提供了录制、转换以及流化音视频的完整解决方案。

ffmpeg命令行参数解释

ffmpeg -i [输入文件名] [参数选项] -f [格式] [输出文件]
ffmpeg [[ options ][ -i input_file ]]... {[ options ] output_file}...

    参数选项:

  •     (1) -an: 去掉音频 -vn:去掉视频 -t:持续时长 -ss:起始时间 -r:帧率(默认为25) -s:帧大小(W*H) -aspect:横纵比(4:3,16:9等)
  •     (2) -acodec: 音频选项, 一般后面加copy表示拷贝
  •     (3) -vcodec:视频选项,一般后面加copy表示拷贝
  •     格式选项:
  •     (1) h264: 表示输出的是h264的视频裸流
  •     (2) mp4: 表示输出的是mp4的视频
  •     (3) mpegts: 表示ts视频流

ffmpeg命令格式转换

视频格式转换

ffmpeg -i test.h264 -vcodec copy -f mpegts test.ts              # 将h264格式转为ts格式

ffmpeg -i test.h264 -vcodec copy -f mp4 test.mp4              # 将h264格式转为MP4格式

视频拼接: 

ffmpeg -i "concat:test1.h264|test2.h264" -vcodec copy -f h264 out12.h264

# 将test1.h264和test2.h264视频拼接起来,输出out12.h264视频

视频截图:

ffmpeg -i test.mp4  -t 0.001 -s 352x240 1.jpg    # 在test.mp4中截图

ffmpeg -i test.mp4 -vframes 30 -y -f gif 1.gif       # 将test.py前30帧做成gif动图

ffmpeg -i test.mp4 -t 10 -r 1 pic-%03d.jpg           # 从视频前10s中取图像,1s提取一帧

常用应用例子

  1. #强制显示宽高
  2. ffplay -i -volume 1 -x 800 -y 480 test_1920x1080.mp4
  3. -framerate 25 :指定帧率
  4. -fs :全屏播放
  5. -an :禁用音频
  6. -vn :禁用视频
  7. -sn :禁用字幕
  8. -ss pos :根据设置的秒进行定位
  9. #在555秒的位置进行播放
  10. ffplay -i -volume 1 -x 800 -y 480 -fs test_1280x720.mp4 -ss 00:05:55
  11. -acodec :指定音频解码器 -acodec libfdk_aac
  12. -vcodec :指定视频解码器 -vcodec h264
  13. -window_title lpf :指定播放器播放视频的名称
  14. -t 指定播放的时长
  15. -loop number :循环播放的次数
  16. -nostats :不输出视频相关信息,通过这个可以查看ffplay 如何收集的这些信息,自己写播放器可以借鉴
  17. -ast :执行音频流索引
  18. -vst :执行视频流索引,这个只有在视频包含多个流才会生效
  19. #下面这个是执行视频流索引是4 音频索引是3
  20. ffplay -i -x 800 -y 480 mult.ts -vst 4 -ast 3
  21. -autoexit :播放完毕自动退出
  22. #指定播放时间是5秒 播放完毕自动退出
  23. ffplay -i -x 800 -y 480 mult.ts -t 5 -autoexit
  24. #通过-codec:v h264 指定使用特定的解码器进行解码播放
  25. ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 5 -autoexit -codec:v h264
  26. #通过-codec:a 指定使用libfdk_aac 来解码音频数据
  27. ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 5 -autoexit -codec:a libfdk_aac

播放rtmp流媒体:

  1. #播放rtmp 流媒体
  2. ffplay -window_title "cctv1" -x 640 -y 480 rtmp://media3.scctv.net/live/scctv_800
  3. #播放yuv 裸视频 必须指定宽高以及视频格式 帧率指定不指定都行
  4. ffplay -pixel_format yuv420p -video_size 320x240 -framerate 5 yuv420p_320x240.yuv
  5. #播放rgb
  6. ffplay -pixel_format rgb24 -video_size 320x240 -i rgb24_320x240.rgb
  7. #播放pcm -ar 执行采样率 -ac指定通道数 -f 指定位深
  8. ffplay -ar 48000 -ac 2 -f f32le 48000_2_f32le.pcm

 ffplay 简单的过滤器:

  1. #ffplay 简单的过滤器
  2. #视频旋转
  3. ffplay -i test.mp4 -vf transpose=1
  4. ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -vf transpose=1
  5. #视频反转
  6. ffplay test.mp4 -vf hflip
  7. ffplay test.mp4 -vf vflip
  8. ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -vf vflip
  9. #旋转和反转
  10. ffplay test.mp4 -vf hflip,transpose=1
  11. #音频变速播放
  12. ffplay -i test.mp4 -af atempo=2
  13. ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -af atempo=2
  14. #视频变速播放
  15. ffplay -i test.mp4 -vf setpts=PTS/2
  16. #音频和视频同时变速
  17. ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -af atempo=2 -vf setpts=PTS/2
  18. #-i 表示输入 -codec copy 不重新进行编码 -ss 起始时间 -t 指定时长 -f 指定输出格式
  19. ffplay -i test_1280x720.mp4 -codec copy -ss 10 -t 20 -f flv out.mp4

ffmpeg 参数说明: 

  1. #ffmpeg 参数说明
  2. -i 设定输入流
  3. -f 设定输出格式(format)
  4. -ss 开始时间
  5. -t 时间长度
  6. -aframes 设置要输出的音频帧数
  7. -b:a 音频码率
  8. -ar 设定采样率
  9. -ac 设定声音的Channel数
  10. -acodec 设定声音编解码器,如
  11. 果用copy表示原始编解码数据必
  12. 须被拷贝。
  13. -an 不处理音频
  14. -af 音频过滤器
  15. ffmpeg -i test_1280x720.mp4 -b:a 192k -ar 48000 -ac 2 -acodec aac -aframes 200 out2.mp3
  16. #视频
  17. -vframes 设置要输出的视频帧数
  18. -b 设定视频码率
  19. -b:v 视频码率
  20. -r 设定帧速率
  21. -s 设定画面的宽与高
  22. -vn 不处理视频
  23. -aspect aspect 设置横纵比 4:3 16:91.3333 1.7777
  24. -vcodec 设定视频编解码器,如果用copy表示原始编解码数据必须被拷贝。
  25. -vf 视频过滤器
  26. ffmpeg -i test.mp4 -vframes 300 -b:v 300k -r 30 -s 640x480 -aspect 16:9 -vcodec libx265
  1. #提取音频数据 -acodec copy 直接拷贝音频编码数据 -VN 禁止视频
  2. ffmpeg -i test_1280x720.mp4 -acodec copy -vn audio.mp4
  3. #提取视频 -vcodec copy 直接拷贝视频编码数据 -an 禁止音频
  4. ffmpeg -i test_1280x720.mp4 -vcodec copy -an video.mp4
  5. #提取视频
  6. ffmpeg -i test_1280x720.mp4 -vcodec copy -an test_lpf.h264
  7. #强制格式
  8. ffmpeg -i test_1280x720.mp4 -vcodec libx264 -an test_lpf.h264
  9. #提取音频
  10. ffmpeg -i test_1280x720.mp4 -acodec copy -vn test_lpf.aac
  11. #强制格式
  12. ffmpeg -i test_1280x720.mp4 -acodec libmp3lame -vn test_lpf.mp3
  1. #提取yuv数据 提取3秒数据,分辨率和源视频一致
  2. ffmpeg -i test_1280x720.mp4 -t 3 -pix_fmt yuv420p yuv420p_orig.yuv
  3. #提取3秒数据,分辨率转为320x240
  4. ffmpeg -i test_1280x720.mp4 -t 3 -pix_fmt yuv420p -s 640*480 yuv420p_320x240.yuv
  5. #播放yuv 视频数据 必须指定分辨率 否则会绿屏以及花屏
  6. ffplay -i yuv420p_640x480.yuv -s 640*480
  7. #提取3秒数据,分辨率转为320x240
  8. ffmpeg -i test.mp4 -t 3 -pix_fmt rgb24 -s 320x240 rgb24_320x240.rgb
  9. #rgb 格式的数据进行播放 必须指定 pixel_format rgb24 必须指定分辨率 否则播放不出来 如果不指定pixel_format 会花屏绿屏
  10. ffplay -i rgb24_320x240.rgb -pixel_format rgb24 -video_size 320*240
  11. #RGB和YUV之间的转换
  12. ffmpeg -s 640*480 -i yuv420p_640x480.yuv -pix_fmt yuv420p -pix_fmt rgb24 -s 640*480 rgb24_640x480.rgb
  13. #播放rgb 必须指定pixel_format 以及分辨率
  14. ffplay -i rgb24_640x480.rgb -pixel_format rgb24 -s 640*480

  1. #更改封装格式
  2. ffmpeg -i test_1280x720.mp4 -vcodec copy -acodec copy test_copy.ts
  3. ffmpeg -i test_1280x720.mp4 -codec copy test_copy2.ts
  4. #改变编码格式
  5. ffmpeg -i test_1280x720.mp4 -vcodec libx265 -acodec libmp3lame out_h265_mp3.mkv
  6. #改变帧率
  7. ffmpeg -i test_1280x720.mp4 -r 15 output2.mp4
  8. #修改视频码率:
  9. ffmpeg -i test.mp4 -b 400k output_b.mkv
  10. #修改视频码率:
  11. ffmpeg -i test.mp4 -b:v 400k output_bv.mkv
  12. #修改音频码率: 如果不想重新编码video,需要加上-vcodec copy
  13. ffmpeg -i test.mp4 -b:a 192k output_ba.mp4
  14. #修改音视频码率:
  15. ffmpeg -i test.mp4 -b:v 400k -b:a 192k output_bva.mp4
  16. #修改视频分辨率:
  17. ffmpeg -i test.mp4 -s 480x270 output_480x270.mp4
  18. #修改音频采样率:
  19. ffmpeg -i test.mp4 -ar 44100 output_44100hz.mp4
  1. #画中画 副视频停下之后默认显示最后一帧图像
  2. ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20[out]"
  3. #eof_action=1 表示短的视频停止之后都会停止
  4. ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20:eof_action=1[out]"
  5. #短的视频结束了 画面直接结束
  6. ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20:eof_action=2[out]"
  7. #shortest=1 表示短的视频停止之后都会停止
  8. ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20:shortest =1[out]"
  9. #对副视频视频进行缩放
  10. ffplay -i input.mp4 -vf "movie=sub_320x240.mp4,scale=640x480[sub];[in][sub]overlay=x=20:y=20[out]"
  11. #跑马灯
  12. ffplay -i test_60_1280x720.mp4 -vf "movie=test_60_1280x720.mp4,scale=320x270[test];[in][test]overlay=x=mod(50*t\,main_w):y=abs(sin(t))*main_h*0.7[out]"
  1. #双宫格
  2. ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -filter_complex "nullsrc=size=640x480[base];[0:v]setpts=PTS-STARTPTS,scale=320x240[upperleft];[1:v]setpts=PTS-STARTPTS,scale=320x240[upperright];[base][upperleft]overlay=shortest=1[tmp1];[tmp1][upperright]overlay=shortest=1:x=320" out2.mp4
  3. #四宫格
  4. ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -filter_complex "nullsrc=size=640x480[base];[0:v] setpts=PTS-STARTPTS,scale=320x240[upperleft];[1:v]setpts=PTS-STARTPTS,scale=320x240[upperright];[2:v]setpts=PTS-STARTPTS, scale=320x240[lowerleft];[3:v]setpts=PTS-STARTPTS,scale=320x240[lowerright];[base][upperleft]overlay=shortest=1[tmp1];[tmp1][upperright]overlay=shortest=1:x=320[tmp2];[tmp2][lowerleft]overlay=shortest=1:y=240[tmp3];[tmp3][lowerright]overlay=shortest=1:x=320:y=240" out3.mp4

 我的热门文章推荐

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/174829
推荐阅读
相关标签
  

闽ICP备14008679号