淮安网站制作设计,汕头seo网站优化,兰州东方商易文化传播有限责任公司,电子商务网站建设报告范文原文网址#xff1a;ffmpeg命令详解_IT利刃出鞘的博客-CSDN博客
简介
本文介绍ffmpeg命令的用法。
命令示例
1.mp4和avi的基本互转
ffmpeg -i D:\input.mp4 E:\output.avi
ffmpeg -i D:\input.avi E:\output.mp4
-i 表示input#xff0c;即输入。后面填一个输入地址和一…原文网址ffmpeg命令详解_IT利刃出鞘的博客-CSDN博客
简介
本文介绍ffmpeg命令的用法。
命令示例
1.mp4和avi的基本互转
ffmpeg -i D:\input.mp4 E:\output.avi
ffmpeg -i D:\input.avi E:\output.mp4
-i 表示input即输入。后面填一个输入地址和一个输出地址这种方式没有指定任何参数和解码器都用默认会发现转换得到的文件压缩严重avi文件只有200kbps的码率。
2.mp4和avi的无损互转
mp4转换avi
ffmpeg -i D:\input.mp4 -qscale 0 E:\output.avi
或者
ffmpeg -i D:\input.mp4 -c copy E:\output.avi
这里更推荐第一种方式-qscale表示质量控制0表示0损失现在的ffmpeg已经采用qsacle取代了原来的sameq方式。
第二种方式 -c copy表明会把原视频的所有流一模一样的复制即不进行解码和重新编码这种情况下得到的avi文件需要额外的解码器如potplayer才能打开win10自带的是不行的。
注-c copy包含了-c:v copy(视频流-c:a copy音频流等所有流。另外其他写法如-vcodec -codec:v与-c:v copy是同义的其余以此类推。
avi转mp4
ffmpeg -i D:\input.mp4 -c:v copy -c:a copy E:\output.avi -y
-y表示不用确认覆盖文件如果有重名的文件一般会在命令行向用户确认。
mp4转avi就直接copy就可以了win10自带也能播。
3.截取视频片段
ffmpeg -i input.avi -c:v copy -c:a copy -ss 00:00:00 -to 00:00:30 cutout.avi -y
这是截取30s的和前面一样如果只是截取视频片段就不要重新编码了一个-c copy搞定。 -ss后面跟的是时间位置开始时间 -to 结束时间。
4.批量截取视频图片
for /R %v IN (*.avi) do ( ffmpeg -i %v -r 1 -f image2 %v%d.jpeg)
假设一个视频文件夹里有很多avi文件我想每一个avi文件都间隔一帧截图就是这条语句了。for…IN…do是命令行的循环格式。%v是文件名%d是自动递增的数字名。-r定义的是间隔多少帧截图一次。
5.把大量图片组合成视频
ffmpeg -f image2 -framerate 30 -i %d.jpg xxx.avi
-framerate设定帧数这里设成了30也就是一秒30张图片%d表示从1开始的图片这里推荐大家一个软件renamer免费版的就足够使用了可以快速批量重命名文件不用每次写重命名代码了。
命令详解
用法
ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... options 全局参数infile options 输入文件参数infile 输入文件outfile options 输出文件参数outfile 输出文件
全局选项 参数 说明 -loglevel loglevel 设置日志登记具体用法可以通过man ffmpeg查看例如ffmpeg -loglevel verbose -i 1080p.mp4可选quiet panic fatal error warning info verbose debug trace -v loglevel 设置日志登记具体用法可以通过man ffmpeg查看例如ffmpeg -v verbose -i 1080p.mp4可选quiet panic fatal error warning info verbose debug trace -report 生成一个报告报告的名字是ffmpeg自动生成的例如ffmpeg -report -i 1080p.mp4想要自定义文件以及日志等级可以使用宏FFREPORT例如FFREPORTfileffreport.log:level32 ffmpeg -i 1080p.mp4 -max_alloc bytes 设置通过ffmpeg的malloc函数系列设置在堆上分配块的最大大小限制。嵌入式设备可能会用到这个选项 -y 覆盖输出文件 -n 切勿覆盖输出文件 -ignore_unknown 忽略未知的流类型 -filter_threads 定义用于处理过滤器管道的线程数。每个管道将生成一个线程池其中包含许多可用于并行处理的线程。默认是可用CPU的数量 -filter_complex_threads 定义用于处理filter_complex图的线程数。类似于filter_threads但仅用于-filter_complex图形。默认值为可用 CPU 的数量 -stats 编码期间打印进度报告 -max_error_rate maximum 在所有输入中设置解码帧失败的比例当超过时ffmpeg将返回退出代码69。超过此阈值不会终止处理。值的范围是0到1之间的浮点数。默认值为2/3 -bits_per_raw_sample number 设置每个原始样本的位数 -vol volume 改变音量 volume默认值是256也就是它把音量分为256等分例如要把音量放大为原来的两倍(2562)ffmpeg -vol 512 -y -i bugua.mp3 output.mp3
输入输出选项 选项 说明 例子 -f fmt force format 设置输入容器是mp4 ffmpeg -i bugua.mp3 -f mp4 output.m4a -c codec codec name 设置输入编码格式是ac3 ffmpeg -y -i bugua.mp3 -c ac3 output.m4a -codec codec codec name 设置输入编码格式是ac3 ffmpeg -y -i bugua.mp3 -codec ac3 output.m4a -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 设置只录制前50秒 ffmpeg -i bugua.mp3 -t 50 output.mp3 -to time_stop record or transcode stop time 设置只录制前50秒 ffmpeg -i bugua.mp3 -t 50 output.mp3 -fs limit_size set the limit file size in bytes 设置输出文件大小限制在0.1MB ffmpeg -y -i bugua.mp3 -fs 0.1MB output.mp3 -ss time_off set the start time offset 设置从第50秒开始录制 fmpeg -ss 50 -y -i bugua.mp3 output.mp3 -sseof time_off set the start time offset relative to EOF 设置从倒数第50秒开始录制 ffmpeg -sseof -50 -y -i bugua.mp3 output.mp3 -seek_timestamp 此选项使用-ss选项在输入文件中启用或禁用按时间戳搜索。默认情况下它是禁用的。如果启用则-ss选项的参数被视为实际时间戳并且不会被文件的开始时间偏移。这仅适用于不从时间戳 0 开始的文件例如传输流 - -timestamp time 在容器中设置录制时间戳 -metadata stringstring 设置修改容器这一层的metadata 设置标题 ffmpeg -i in.avi -metadata title“my title” out.flv -program titlestring:stnumber… 添加或者修改program的Metadata 设置program标题 ffmpeg -y -i 1080p.mp4 -program title“XXXXXX”:st1 -c copy output.mp4 -target type 指定目标文件类型 (“vcd”, “svcd”, “dvd”, “dv” or “dv50” with optional prefixes “pal-”, “ntsc-” or “film-”) ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg -apad 音频填充(追加) 在音频文件的最后追加10秒静音 ffmpeg -y -i bugua.mp3 -af “apadpad_dur10” output.mp3 -frames number 设置要输出的帧数 只写入200帧 ffmpeg -i 1080p.mp4 -frames 200 -c copy output.mp4 -filter filter_graph 设置简单的filter(不对音视频内容进行任何处理的filter) 把视频帧的PTS设置为原来的0.5倍 ffmpeg -y -i 1080p.mp4 -filter:v “setpts0.5PTS” output.mp4 -filter_script filename read stream filtergraph description from a file - -reinit_filter reinit filtergraph on input parameter changes - -discard 允许从流中丢弃特定的流或帧。使用值all会丢弃所有的流在解复用时从流中选择要丢弃的帧并非所有解复用器都支持 去掉视频中的音频 ffmpeg -y -discard:a all -i 1080p.mp4 -c copy output.mp4 -disposition 设定特定的流作为默认流 使第二个音频流成为默认流 ffmpeg -i in.mkv -c copy -disposition:a:1 default out.mkv
视频选项 选项 说明 例子 -vframes number set the number of video frames to output 输出200帧 ffmpeg -y -i 1080p.mp4 -vframes 200 output.mp4 -r rate set frame rate (Hz value, fraction or abbreviation) 设置输出帧率为10帧 ffmpeg -y -i 1080p.mp4 -r 10 -vframes 500 output.mp4 -fpsmax rate set max frame rate (Hz value, fraction or abbreviation) 设置最大帧率为15帧 ffmpeg -y -i 1080p.mp4 -fpsmax 15 -vframes 500 output.mp4 -s size set frame size (WxH or abbreviation) 把视频裁剪为640x480 ffmpeg -y -i 1080p.mp4 -s 640x480 -vframes 500 output.mp4 -aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777) 视频比例改为4:3 ffmpeg -y -i 1080p.mp4 -aspect 4:3 -vframes 500 output.mp4 -bits_per_raw_sample number set the number of bits per raw sample - -vn disable video 只输出音频 ffmpeg -y -i 1080p.mp4 -vn -c copy output.mp4 -vcodec codec force video codec (‘copy’ to copy stream) 设置输出编码器为libx265 ffmpeg -y -i 1080p.mp4 -vframes 500 -vcodec libx265 output.mp4 -timecode hh:mm:ss[:;.]ff set initial TimeCode value. - -pass n select the pass number (1 to 3) - -vf filter_graph set video filters 逆时针旋转 ffmpeg -y -i 1080p.mp4 -vframes 300 -vf “transpose2” output.mp4 -ab bitrate audio bitrate (please use -b:a) 设置音频输出码率为56k ffmpeg -y -i 1080p.mp4 -ab 56k -vn output.mp4 -b bitrate video bitrate (please use -b:v) 设置视频输出码率为256k ffmpeg -y -i 1080p.mp4 -b 256k -an output.mp4 -dn disable data -
音频选项 选项 说明 例子 -aframes number set the number of audio frames to output 只写入1000帧音频数据 ffmpeg -y -i 1080p.mp4 -vn -aframes 1000 output.mp4 -aq quality set audio quality (不同的编码器使用不同的数字表示不同的码率) 这里以MP3为例把码率设置为245kbps左右 ffmpeg -y -i bugua.mp3 -aq -0 output.mp3 -ar rate set audio sampling rate (in Hz) 重采样为16k ffmpeg -y -i 1080p.mp4 -vn -aframes 1000 -ar 16000 output.mp4 -ac channels set number of audio channels 改为双声道 ffmpeg -y -i 1080p.mp4 -vn -aframes 1000 -ac 2 output.mp4 -an disable audio 只输出视频 ffmpeg -y -i 1080p.mp4 -an -c copy output.mp4 -acodec codec force audio codec (‘copy’ to copy stream) 强制使用ac3编码器 ffmpeg -y -i 1080p.mp4 -vn -aframes 1000 -acodec ac3 output.mp4 -vol volume change audio volume (256normal) 把声音调为原来的2倍 ffmpeg -y -i 1080p.mp4 -vn -aframes 1000 -vol 512 output.mp4 -af filter_graph set audio filters 写入音频之前先进行afade处理 ffmpeg -y -i 1080p.mp4 -vn -aframes 1000 -af afade output.mp4
副标题选项 选项 说明 例子 -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 -
查看帮助文档
简单文档
可以用此命令查看详解
ffmpeg --help
结果
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...Getting help:-h -- print basic options-h long -- print more options-h full -- print all options (including all format and codec specific options, very long)-h typename -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocolSee man ffmpeg for detailed description of the options.Print help / information / capabilities:
-L show license
-h topic show help
-? topic show help
-help topic show help
--help topic show help
-version show version
-buildconf show build configuration
-formats show available formats
-muxers show available muxers
-demuxers show available demuxers
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-dispositions show available stream dispositions
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
-hwaccels show available HW acceleration methodsGlobal options (affect whole program instead of just one file):
-loglevel loglevel set logging level
-v loglevel set logging level
-report generate a report
-max_alloc bytes set maximum size of a single allocated block
-y overwrite output files
-n never overwrite output files
-ignore_unknown Ignore unknown stream types
-filter_threads number of non-complex filter threads
-filter_complex_threads number of threads for -filter_complex
-stats print progress report during encoding
-max_error_rate maximum error rate ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.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
-sseof time_off set the start time offset relative to EOF
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time set the recording timestamp (now to set the current time)
-metadata stringstring add metadata
-program titlestring:stnumber... add program with specified streams
-target type specify target file type (vcd, svcd, dvd, dv or dv50 with optional prefixes pal-, ntsc- or film-)
-apad audio pad
-frames number set the number of frames to output
-filter filter_graph set stream filtergraph
-filter_script filename read stream filtergraph description from a file
-reinit_filter reinit filtergraph on input parameter changes
-discard discard
-disposition dispositionVideo options:
-vframes number set the number of video frames to output
-r rate set frame rate (Hz value, fraction or abbreviation)
-fpsmax rate set max 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)
-display_rotation angle set pure counter-clockwise rotation in degrees for stream(s)
-display_hflip set display horizontal flip for stream(s) (overrides any display rotation if it is not set)
-display_vflip set display vertical flip for stream(s) (overrides any display rotation if it is not set)
-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 dataAudio options:
-aframes number set the number of audio frames to output
-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)
-ab bitrate audio bitrate (please use -b:a)
-af filter_graph set audio filtersSubtitle 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
细节文档 命令 说明 ffmpeg -L 显示License ffmpeg -version 显示当前版本 ffmpeg help -buildconf 显示编译此ffmpeg的configuration ffmpeg help -formats 显示支持的文件格式同时显示muxers和demuxers ffmpeg help -muxers 显示支持的muxers格式 ffmpeg help -demuxers 显示支持的demuxers格式 ffmpeg help -devices 显示支持的设备包括音视频设备 ffmpeg help -codecs 显示支持的格式同时显示视频、音频、字幕、帧内编码、有损压缩和无损压缩的解编码支持情况 ffmpeg help -decoders 显示支持的解码器 ffmpeg help -encoders 显示支持的编码器 ffmpeg help -bsfs 显示支持的二进制流过滤器例如h264_metadata、h264_mp4toannexb、hevc_mp4toannexb等 ffmpeg help -protocols 显示支持的可用的协议区分Input和Output例如file、http、hls、rtmp、rtp、pipe、tee等 ffmpeg help -filters 显示支持的可用的过滤器 ffmpeg help -pix_fmts 显示支持的可用的像素格式 ffmpeg help -layouts 显示支持的声道布局例如mono、stereo、2.1、2.0、3.0、5.0、5.1等 ffmpeg help -sample_fmts 显示支持的音频采样格式例如u8、s16、s32、flt等 ffmpeg help -colors 显示支持的颜色 ffmpeg help -sources device 列出输入设备的源 ffmpeg help -sinks device 列出输出设备的槽(节点) ffmpeg help -hwaccels 显示可用的硬件加速方法