ffmpeg常用命令

1)常用命令

1、最简单转换命令

ffmpeg -i input.mp4 output.mkv

2、更加精准的控制转换命令

ffmpeg -i input.mp4 -c:v vp9 -c:a libvorbis output.mkv

(-c:v 控制视频格式, -c:a 控制音频格式)

3、调节比特率

ffmpeg -i GVG-981.mp4 -c:v libx264 -b:v 2M -maxrate 2M -bufsize 1M GVG-981-out.mp4

ffmpeg -i input.webm -c:a copy -c:v vp9 -b:v 1M output.mkv

(-b:v 1M 代表着视频的比特率变成1Mb

This will copy the audio (-c:a copy) from input.webm and convert the video to a VP9 codec (-c:v vp9) with a bit rate of 1M/s (-b:v), all bundled up in a Matroska container (output.mkv).)

4、调节帧率

ffmpeg -i 002.mp4 -filter:v fps=fps=29.97 002-out.mp4

ffmpeg -i input.webm -c:a copy -c:v vp9 -r 30 output.mkv

(This creates a new Matroska with the audio stream copied over and the video stream's frame rate forced to 30 frames per second, instead of using the frame rate from the input (-r 30).)

5、调节视频尺寸(分辨率)

ffmpeg -i FC2PPV-402422-1.mp4 -c:a copy -s 854x480 FC2PPV-402422-1-out.mp4

ffmpeg -i input.mkv -c:a copy -s 1280x720 output.mkv

(声音原封不动拷贝过去,视频编码格式不变,只是尺寸调整到1280x720)

6、截取部分视频(时长)

ffmpeg -i input.mkv -c:a copy -c:v copy -ss 00:01:00 -t 10 output.mkv

(音视频格式不变, 从00:01:00开始拷贝10s过去)

7、 提取关键帧

ffmpeg -skip_frame nokey -i 480P_2000K_204282351.mp4 -vsync 0 -r 30 -f image2 480P_2000K_204282351%02d.png

8,使用 ffmpeg 命令将 raw.mp4 的音频替换为 out.wav 的音频

ffmpeg -i raw.mp4 -i out.wav -map 0:v -map 1:a -c:v copy -c:a copy replaced_audio.mp4

8、对视频进行帧提取

您可以使用以下命令将视频分解成图片序列:

ffmpeg -i input.mp4 -vf fps=1 frame_%04d.png

这条命令将 input.mp4 视频分解成图片序列,每秒保存一帧。输出的文件名为 frame_0001.png、frame_0002.png 等。您可以根据需要更改输入文件名、帧率和输出文件名模式。

ffmpeg -i .\input.mp4 -vf 'select=gte(n,1),setpts=PTS-STARTPTS' 'input/%05d.png'

ffmpeg -i .\input.mp4 -vf 'select=gte(n,1),setpts=0.5*PTS' 'input/%05d.png'

ffmpeg -i .\input.mp4 -vf 'select=between(n,{START_FRAME},{END_FRAME}),setpts=0.5*PTS' 'input/%05d.png'

setpts的具体参数含义如下:

复制代码
Start counting PTS from zero

setpts=PTS-STARTPTS

Apply fast motion effect:

setpts=0.5*PTS

Apply slow motion effect:

setpts=2.0*PTS

Set fixed rate of 25 frames per second:

setpts=N/(25*TB)

Set fixed rate 25 fps with some jitter:

setpts='1/(25*TB) * (N + 0.05 * sin(N*2*PI/25))'

Apply an offset of 10 seconds to the input PTS:

setpts=PTS+10/TB

Generate timestamps from a "live source" and rebase onto the current timebase:

setpts='(RTCTIME - RTCSTART) / (TB * 1000000)'

Generate timestamps by counting samples:

asetpts=N/SR/TB

9、从png序列生成视频文件

ffmpeg -y -r {TARGET_FPS} -f image2 -pattern_type glob -i '*.png' '/content/gdrive/My Drive/{OUTPUT_FILE_PATH}'

2)命令基本语法

注意:这里面的非方括号部分(蓝字)都是必须得有的。

全局选项:

Global options (affect whole program instead of just one file:

-loglevel loglevel set libav* logging level

-v loglevel set libav* logging level

-report generate a report

-max_alloc bytes set maximum size of a single allocated block

-y overwrite output files

-n do not overwrite output files

-stats print progress report during encoding

-bits_per_raw_sample number set the number of bits per raw sample

-vol volume change audio volume (256=normal)

输入输出选项:

Per-file main options:

-f fmt force format

-c codec codec name

-codec codec codec name

-pre preset preset name

-map_metadata outfile,metadata:infile,metadata set metadata information of outfile from infile

-t duration record or transcode "duration" seconds of audio/video

-to time_stop record or transcode stop time

-fs limit_size set the limit file size in bytes

-ss time_off set the start time offset

-timestamp time set the recording timestamp ('now' to set the current time)

-metadata string=string add metadata

-target type specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...)

-frames number set the number of frames to record

-filter filter_graph set stream filtergraph

-reinit_filter reinit filtergraph on input parameter changes

Video options:

-vframes number set the number of video frames to record

-r rate set frame rate (Hz value, fraction or abbreviation)

-s size set frame size (WxH or abbreviation)

-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)

-bits_per_raw_sample number set the number of bits per raw sample

-vn disable video

-vcodec codec force video codec ('copy' to copy stream)

-timecode hh:mm:ss:;.ff set initial TimeCode value.

-pass n select the pass number (1 to 3)

-vf filter_graph set video filters

-b bitrate video bitrate (please use -b:v)

-dn disable data

Audio options:

-aframes number set the number of audio frames to record

-aq quality set audio quality (codec-specific)

-ar rate set audio sampling rate (in Hz)

-ac channels set number of audio channels

-an disable audio

-acodec codec force audio codec ('copy' to copy stream)

-vol volume change audio volume (256=normal)

-af filter_graph set audio filters

Subtitle options:

-s size set frame size (WxH or abbreviation)

-sn disable subtitle

-scodec codec force subtitle codec ('copy' to copy stream)

-stag fourcc/tag force subtitle tag/fourcc

-fix_sub_duration fix subtitles duration

-canvas_size size set canvas size (WxH or abbreviation)

-spre preset set the subtitle options to the indicated preset

相关推荐
开开心心就好2 天前
课堂随机点名工具,绿色版免安装双击即用
java·服务器·前端·ffmpeg·音视频·perl·symfony
小鹿软件办公2 天前
不依赖 FFmpeg 也能录屏?ShareX 22 新增录屏等十余款新工具
ffmpeg·sharex·免费录屏工具
lll23526917792 天前
Android APP短视频音频提取,主流工具怎么选
ffmpeg·音视频
成都旺小宝科技3 天前
首访决策人没来,AI一客一策两天成交!
大数据·人工智能·机器学习·ffmpeg·语音识别
余槐i3 天前
加了Cookie yt-dlp仍报HTTP 403:3个容易漏的请求头差异
python·http·ffmpeg·开发工具·yt-dlp
余槐i3 天前
yt-dlp 线程开到 16 反而更慢:1000 个视频的实测与限速原因
性能优化·ffmpeg·自动化·开发工具·yt-dlp
Maxwin4 天前
Manim 竖屏画布选 9×16 还是 4.5×8?从 font_size 和每单位像素数说起
python·ffmpeg
FlightYe4 天前
音视频修炼之容器与协议(一):MP4和MOV的box剖析
android·linux·c++·ffmpeg·音视频
开开心心就好8 天前
手机虚拟化学实验室,混合燃烧都能模拟
jupyter·智能手机·ffmpeg·计算机外设·电脑·音视频·visual studio
VidDown8 天前
用户说“卡顿“,服务器一切正常:播放质量监测与 QoE 指标
运维·服务器·ffmpeg·音视频·视频