前叙
一直以来用的是Mac自带VLC工具播放直播生成的url链接,简单但不够用,所以还是要入门FFmpeg。
安装
~ brew install ffmpeg
~ git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
~ man ffmpeg
命令
1、查看一个视频去掉多余修身部分
~ ffmpeg -i IMG_3158.MOV -hide_banner
2、mp4转换avi
~ ffmpeg -i test.avi test.mp4
3、视频原画质输出
~ ffmpeg -i 2019.flv -qscale 0 2019.mp4
4、预览
~ ffplay 2019.mp4
~ ffplay 2019.mp3
5、二倍速
~ ffplay -i 2019.mp4 -vf "setpts = 0.5*PTS" 2020.mp4(0.5倍速)
~ ffplay -i 2019.mp4 -vf "setpts = 2*PTS" 2020.mp4(2倍速)
6、mp4转换mp3
~ ffmpeg -i 2019.mp4 -vn 2020.mp4
~ ffmpeg -i 2019.mp4 -vn -ar 44100 -ac 2 -ab 320 -f mp3 2019.mp3
-ar:输出文件音频频率
-ac:音频通道数目
-ab:音频比特率
-f:输出格式mp3
7、更改文件分辨率(手机16:9)
~ ffmpeg -i 2019.mp4 -s 1280*720 -c:a copy 2010.mp4
~ ffmpeg -i 2019.mp4 -s 640*480 -c:a copy 2010.mp4
~ ffmpeg -i 2019.mp4 -s 368*640 -c:a copy 2010.mp4
~ ffmpeg -i 2019.mp4 -s 540*960 -c:a copy 2010.mp4
~ ffmpeg -i 2019.mp4 -filter:v scale = 640:480 -c:a copy 2020.mp4
8、视频静音输出
~ ffmpeg -i 2019.mp4 -an 2010.mp4
9、视频中提取图像
~ ffmpeg -i 2019.mp4 -r 1 -f image2 image-%2d.png
-r:帧速度,每秒提取帧到图像的数字
例子:7s视频,1(9张);2(16张);3(24张)
image2:图片格式
10、裁剪视频
11、转换具体(截取)部分
12、指定视频屏幕高度比
13、指定裁剪
14、多个时间戳分段切割
15、拼接多个视频
16、添加字幕
17、添加海报图像到音频文件
18、获取一个m3u8的相关信息
~ ffprobe http://record.linkv.fun/oc/yolo-16219273817041483061--20210525072327.m3u8
19、域名
~ffmpeg -re -i 16208725908701709528.flv -vcodec copy -acodec copy -f flv -y rtmp://qa.scdn.oclive.fusionv.com/yolo/xxxx
20、查看流/Video信息
~ ffprobe -print_format json -show_streams 2019.flv
{
Input #0, flv, from '2019.flv':
Metadata:
encoder : Lavf58.12.100
Duration: 00:00:41.20, start: 0.133000, bitrate: 1036 kb/s
Stream #0:0: Video: h264 (High), yuv420p(progressive), 540x960, 1000 kb/s, 15 fps, 15 tbr, 1k tbn, 30 tbc
Stream #0:1: Audio: aac (HE-AACv2), 44100 Hz, stereo, fltp, 32 kb/s
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_time_base": "1/30",
"codec_tag_string": "[0][0][0][0]",
"codec_tag": "0x0000",
"width": 540,
"height": 960,
"coded_width": 544,
"coded_height": 960,
"has_b_frames": 2,
"pix_fmt": "yuv420p",
"level": 31,
"chroma_location": "left",
"field_order": "progressive",
"refs": 1,
"is_avc": "true",
"nal_length_size": "4",
"r_frame_rate": "15/1",
"avg_frame_rate": "15/1",
"time_base": "1/1000",
"start_pts": 133,
"start_time": "0.133000",
"bit_rate": "1000000",
"bits_per_raw_sample": "8",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"profile": "HE-AACv2",
"codec_type": "audio",
"codec_time_base": "1/44100",
"codec_tag_string": "[0][0][0][0]",
"codec_tag": "0x0000",
"sample_fmt": "fltp",
"sample_rate": "44100",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/1000",
"start_pts": 133,
"start_time": "0.133000",
"bit_rate": "32000",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
}
}
]
}
21、播放YUV:
~ ffplay -video_size 1080x2220 mini_yuvj420p_1080_2220.yuv
22、mp4转YUV:
~ ffmpeg -i mp4_file yuv_file
23、mp4修改分辨率:
~ ffmpeg -i clean_mp4 -vf scale=1080:1024 denoised_mp4 -hide_banner
24、VMAF比较两个视频:
~ python run_vmaf.py yuv420p 1080 2220 demo.yuv demo.yuv –out-fmt json
例子2:python ./vmaf/script/run_vmaf.py yuv420p 640 360 test/resource/test_flv_yuv/2019.yuv test/resource/test_flv_yuv/2019_1.yuv --out-fmt json
25、mp3转mav格式
~ffmpeg -i input.mp3 -acodec pcm_s16le -ac 1 -ar 8000 output.wav