FFmpeg 常用命令

    xiaoxiao2022-07-13  135

    FFmpeg 常用命令

    查看

    ffmpeg -h // 帮助 ffmpeg -version // 版本信息 ffmepg -devices // 查看可用设备 ffmpeg -i input.mp4 // 查看视频信息

    00:00:46.61 视频时长 3949kb/s 码率 h264:视频编码格式 avc1:苹果公司开发的复合h264规范的格式 yuv420p:视频颜色编码方式 960x400:分辨率 SAR 1:1 :图像采集时,采集的宽高点阵的点数比值 DAR:图像宽高比 PAR:像素的长宽比 23.98 fps: 帧率 23.98 tbr: 帧率 24k tbn: 文件层的时间精度1S=24k,一秒增加24k 47.95 tbc:视频层的时间精度1S=47.95,一秒增加47.95 aac:音频编码格式 mp4a: stereo:立体声 fltp:音频帧格式

    视频转码

    ffmpeg -i input.mp4 -vcodec h264 -s 352*278 -an -f m4v test.264 ffmpeg -i input.mp4 -vcodec h264 -bf 0 -g 25 -s 352*278 -an -f m4v test.264 // -vf B帧数目控制, -g 关键帧间隔控制, -s 分辨率控制

    音视频封装

    ffmpeg -i input.mp4 -i input.aac -vcodec copy -acodec copy output.mp4

    提取音频视频流

    ffmpeg -i input.mp4 -acodec copy -vn output.aac // 提取音频流,-acodec 设定音频编解码器,-vn 不处理视频 ffmpeg -i input.mp4 -acodec aac -vn output.aac // 提取音频流 ffmpeg -i input.mp4 -vcodec copy -an output.mp4 // 提取视频流 -vcodec 设定视频编解码器 -an 不处理音频

    添加字幕

    ffmpeg -i input.mp4 -vf subtitles=text.srt output.mp4

    视频剪切

    ffmpeg -ss 00:00:15 -t 00:00:05 -i input.mp4 -vcodec copy -acodec copy output.mp4 // -ss表示开始切割的时间,-t表示要切多少。上面就是从15秒开始,切5秒钟出来

    码率控制

    ffmpeg -i input.mp4 -b:v 2000k output.mp4 ffmpeg -i input.mp4 -b:v 2000k -bufsize 2000 output.mp4 // -bufsize 缓冲区 ffmpeg -i input.mp4 -b:v 2000k -bufsize 2000k -maxrate 2500k -minrate 1500k output.mp4 // 最大最小域值

    编码格式转换

    ffmpeg -i input.mp4 -vcodec h264 output.mp4 ffmpeg -i input.mp4 -c:v libx265 output.mpt // 添加了外部的x265

    只提取视频ES数据

    ffmpeg -i input.mp4 -vcodec copy -an -f m4v output.h264

    改变视频宽高

    ffmpeg -i input.mp4 -vf scale=960:540 output.mp4 ffmpeg -i input.mp4 -vf scale=960:-1 output.mp4 // 保持宽高比,注意宽要能被2出尽,不然报错

    增加水印

    ffmpeg -i input.mp4 -i logo.png -filter_complex overlay output.mp4 ffmpeg -i input.mp4 -i logo.png -filter_complex overlay=W-w output.mp4 // 右上角 ffmpeg -i input.mp4 -i logo.png -filter_complex overlay=0:H-h output.mp4 // 左下角 ffmpeg -i input.mp4 -i logo.png -filter_complex overlay=W-w:H-h output.mp4 // 右下角

    去除水印

    ffmpeg -i input.mp4 -vf delogo=1:1:144:144:1 output.mp4 // -vf delogo=x:y:w:h[:show], x:y离左上角坐标,设0报错,w:h logo宽高,show设置一个绿色的矩形,默认0

    截取视频图像*

    ffmpeg -i input.mp4 -r 1 -q:v 2 -f image2 pic-d.jpeg // -r 每一秒几帧,-q:v 存储jpeg的图像质量,一般2是高质量 ffmpeg -i input.mp4 -ss 00:00:20 -t 10 -r 1 -q:v 2 -f image2 pic-d.jpeg

    序列帧与视频的相互转换

    ffmpeg -i 001.mp3 -i example.%d.jpg -s 1024x768 -vcodec mpeg4 rebuild.mp4 // 把图片序列帧和音频文件利用mpeg4编码方式合成视频文件darkdoor.avi ffmpeg -i input.mp4 example.%d.jpg // 把视频文件导出成序列帧

    Help

    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 type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf See 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 -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 methods Global 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 errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success. -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 -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 string=string add metadata -program title=string:st=number... 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 disposition Video options: -vframes number set the number of video frames to output -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 -ab bitrate audio bitrate (please use -b:a) -b bitrate video bitrate (please use -b:v) -dn disable data Audio 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) -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
    最新回复(0)