原文链接:https://blog.csdn.net/suny2020/article/details/129299839 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提取一帧 常用应用例子 #强制显示宽高 ffplay -i -volume 1 -x 800 -y 480 test_1920x1080.mp4 -framerate 25 :指定帧率 -fs :全屏播放 -an :禁用音频 -vn :禁用视频 -sn :禁用字幕 -ss pos :根据设置的秒进行定位 #在5分 55秒的位置进行播放 ffplay -i -volume 1 -x 800 -y 480 -fs test_1280x720.mp4 -ss 00:05:55 -acodec :指定音频解码器 -acodec libfdk_aac -vcodec :指定视频解码器 -vcodec h264 -window_title lpf :指定播放器播放视频的名称 -t 指定播放的时长 -loop number :循环播放的次数 -nostats :不输出视频相关信息,通过这个可以查看ffplay 如何收集的这些信息,自己写播放器可以借鉴 -ast :执行音频流索引 -vst :执行视频流索引,这个只有在视频包含多个流才会生效 #下面这个是执行视频流索引是4 音频索引是3 ffplay -i -x 800 -y 480 mult.ts -vst 4 -ast 3 -autoexit :播放完毕自动退出 #指定播放时间是5秒 播放完毕自动退出 ffplay -i -x 800 -y 480 mult.ts -t 5 -autoexit #通过-codec:v h264 指定使用特定的解码器进行解码播放 ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 5 -autoexit -codec:v h264 #通过-codec:a 指定使用libfdk_aac 来解码音频数据 ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 5 -autoexit -codec:a libfdk_aac 播放rtmp流媒体: #播放rtmp 流媒体 ffplay -window_title "cctv1" -x 640 -y 480 rtmp://media3.scctv.net/live/scctv_800 #播放yuv 裸视频 必须指定宽高以及视频格式 帧率指定不指定都行 ffplay -pixel_format yuv420p -video_size 320x240 -framerate 5 yuv420p_320x240.yuv #播放rgb ffplay -pixel_format rgb24 -video_size 320x240 -i rgb24_320x240.rgb #播放pcm -ar 执行采样率 -ac指定通道数 -f 指定位深 ffplay -ar 48000 -ac 2 -f f32le 48000_2_f32le.pcm ffplay 简单的过滤器: #ffplay 简单的过滤器 #视频旋转 ffplay -i test.mp4 -vf transpose=1 ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -vf transpose=1 #视频反转 ffplay test.mp4 -vf hflip ffplay test.mp4 -vf vflip ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -vf vflip #旋转和反转 ffplay test.mp4 -vf hflip,transpose=1 #音频变速播放 ffplay -i test.mp4 -af atempo=2 ffplay -i test_1280x720.mp4 -x 800 -y 480 -t 25 -autoexit -codec:a libfdk_aac -window_title lpf -af atempo=2 #视频变速播放 ffplay -i test.mp4 -vf setpts=PTS/2 #音频和视频同时变速 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 #-i 表示输入 -codec copy 不重新进行编码 -ss 起始时间 -t 指定时长 -f 指定输出格式 ffplay -i test_1280x720.mp4 -codec copy -ss 10 -t 20 -f flv out.mp4 ffmpeg 参数说明: #ffmpeg 参数说明 -i 设定输入流 -f 设定输出格式(format) -ss 开始时间 -t 时间长度 -aframes 设置要输出的音频帧数 -b:a 音频码率 -ar 设定采样率 -ac 设定声音的Channel数 -acodec 设定声音编解码器,如 果用copy表示原始编解码数据必 须被拷贝。 -an 不处理音频 -af 音频过滤器 ffmpeg -i test_1280x720.mp4 -b:a 192k -ar 48000 -ac 2 -acodec aac -aframes 200 out2.mp3 #视频 -vframes 设置要输出的视频帧数 -b 设定视频码率 -b:v 视频码率 -r 设定帧速率 -s 设定画面的宽与高 -vn 不处理视频 -aspect aspect 设置横纵比 4:3 16:9 或 1.3333 1.7777 -vcodec 设定视频编解码器,如果用copy表示原始编解码数据必须被拷贝。 -vf 视频过滤器 ffmpeg -i test.mp4 -vframes 300 -b:v 300k -r 30 -s 640x480 -aspect 16:9 -vcodec libx265 #提取音频数据 -acodec copy 直接拷贝音频编码数据 -VN 禁止视频 ffmpeg -i test_1280x720.mp4 -acodec copy -vn audio.mp4 #提取视频 -vcodec copy 直接拷贝视频编码数据 -an 禁止音频 ffmpeg -i test_1280x720.mp4 -vcodec copy -an video.mp4 #提取视频 ffmpeg -i test_1280x720.mp4 -vcodec copy -an test_lpf.h264 #强制格式 ffmpeg -i test_1280x720.mp4 -vcodec libx264 -an test_lpf.h264 #提取音频 ffmpeg -i test_1280x720.mp4 -acodec copy -vn test_lpf.aac #强制格式 ffmpeg -i test_1280x720.mp4 -acodec libmp3lame -vn test_lpf.mp3 #提取yuv数据 提取3秒数据,分辨率和源视频一致 ffmpeg -i test_1280x720.mp4 -t 3 -pix_fmt yuv420p yuv420p_orig.yuv #提取3秒数据,分辨率转为320x240 ffmpeg -i test_1280x720.mp4 -t 3 -pix_fmt yuv420p -s 640*480 yuv420p_320x240.yuv #播放yuv 视频数据 必须指定分辨率 否则会绿屏以及花屏 ffplay -i yuv420p_640x480.yuv -s 640*480 #提取3秒数据,分辨率转为320x240 ffmpeg -i test.mp4 -t 3 -pix_fmt rgb24 -s 320x240 rgb24_320x240.rgb #rgb 格式的数据进行播放 必须指定 pixel_format rgb24 必须指定分辨率 否则播放不出来 如果不指定pixel_format 会花屏绿屏 ffplay -i rgb24_320x240.rgb -pixel_format rgb24 -video_size 320*240 #RGB和YUV之间的转换 ffmpeg -s 640*480 -i yuv420p_640x480.yuv -pix_fmt yuv420p -pix_fmt rgb24 -s 640*480 rgb24_640x480.rgb #播放rgb 必须指定pixel_format 以及分辨率 ffplay -i rgb24_640x480.rgb -pixel_format rgb24 -s 640*480 #更改封装格式 ffmpeg -i test_1280x720.mp4 -vcodec copy -acodec copy test_copy.ts ffmpeg -i test_1280x720.mp4 -codec copy test_copy2.ts #改变编码格式 ffmpeg -i test_1280x720.mp4 -vcodec libx265 -acodec libmp3lame out_h265_mp3.mkv #改变帧率 ffmpeg -i test_1280x720.mp4 -r 15 output2.mp4 #修改视频码率: ffmpeg -i test.mp4 -b 400k output_b.mkv #修改视频码率: ffmpeg -i test.mp4 -b:v 400k output_bv.mkv #修改音频码率: 如果不想重新编码video,需要加上-vcodec copy ffmpeg -i test.mp4 -b:a 192k output_ba.mp4 #修改音视频码率: ffmpeg -i test.mp4 -b:v 400k -b:a 192k output_bva.mp4 #修改视频分辨率: ffmpeg -i test.mp4 -s 480x270 output_480x270.mp4 #修改音频采样率: ffmpeg -i test.mp4 -ar 44100 output_44100hz.mp4 #画中画 副视频停下之后默认显示最后一帧图像 ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20[out]" #eof_action=1 表示短的视频停止之后都会停止 ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20:eof_action=1[out]" #短的视频结束了 画面直接结束 ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20:eof_action=2[out]" #shortest=1 表示短的视频停止之后都会停止 ffplay -i input.mp4 -vf "movie=sub_320x240.mp4[sub];[in][sub]overlay=x=20:y=20:shortest =1[out]" #对副视频视频进行缩放 ffplay -i input.mp4 -vf "movie=sub_320x240.mp4,scale=640x480[sub];[in][sub]overlay=x=20:y=20[out]" #跑马灯 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]" #双宫格 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 #四宫格 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 |
|