ffmpeg使用详解

1、Mac安装请点击这里


ffmpeg使用详解_第1张图片

2、使用介绍:

显示ffmpeg使用的基本信息命令:ffmpeg -h
显示ffmpeg使用的高级信息命令:ffmpeg -h long
显示ffmpeg使用的所有信息命令:ffmpeg -h full
也可以打印到文件中查看详细的内容:ffmpeg -h long > ffmpeg_h_long.log
粗略查找:
win用: ffmpeg -encoders | findstr x264
mac用: ffmpeg -encoders | grep x264 查找流中包含x264的
详细查找(一般是先用上边的粗略查找查找出具体型号再用下边的详细查找):
ffmpeg -h type = name
ffmpeg -h encoder=libx264

案例1:

ffmpeg -i 1.mp4 -codec copy -ss 200 -t 10 -f flv out.flv
-codec copy 使用原视频的编解码方法
-ss 200 表示从200毫秒开始截取
-t 10 表示截取10毫秒,其实最终结果是视频总共有11毫秒
-f flv 表示输出的格式为flv 格式 这个可以忽略,则就按照自己写的那个后缀解析即
ffmpeg -i 1.mp4 -codec copy -ss 200 -t 10 out.mp4 则解析成mp4

案例2:

ffmpeg -i out.mp4 -b:a 192k -ar 48000 -ac 2 -acodec libmp3lame -aframes 200 out2.mp4
-b:a 192k 音频码率为192k
-ar 48000 采样率为48000
-ac 2 声音通道数为2
-acodec libmp3lame 声音的编解码器为 libmp3lame
-aframes 200 音频帧数为200

案例3:

ffmpeg -i out.mp4 -vframes 300 -b:v 300k -r 30 -s 640x480 -aspect 16:9 -vcodec libx265 out3.mp4
需要注意的是这里边的640x480 中的x是x而不是*
libx265 这个最好是复制
ffmpeg使用详解_第2张图片

案例3:

ffmpeg -i out.mp4 -acodec copy -vn audio.mp4 抽取音频(只有声音没有画面)

案例4:

ffmpeg -i out.mp4 -vcodec copy -an video.mp4 抽取视频(没声音只有画面)

案例5:

ffmpeg -i test.mp4 -acodec libmp3lame -vn test.mp3
ffmpeg -i out.mp4 -codec:a libmp3lame -vn test2.mp3 这两种写法不一样但是效果是一样的
即 -acodec等价于-codec:a 同理 -vcodec 等价于 -codec:v
ffmpeg使用详解_第3张图片

ffmpeg使用详解_第4张图片
ffmpeg使用详解_第5张图片

视频抽取图片案例:

ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 1 -s 640x360 ./video_test/test.jpg
-y 如果video_test目录下有test.jpg则覆盖了,不用输入是否覆盖,不写-y则会显示交互内容
-vframes 1 输出一帧,可以写多帧例如:
ffmpeg -i test.mp4 -y -f image2 -ss 00:00:02 -vframes 10 -s 640x360 ./video_test/test%02d.jpg
-vframes 10 即抽出连续的10帧 如果是多帧即像现在这个的则需要将输出结果进行格式化:如下
test%02d.jpg %02d 即和c语言的格式化输出的格式是一样的,即d:十进制输出,2 即输出的为两位数,0 即不足两位的在其前边补充0 例如:
ffmpeg使用详解_第6张图片

视频抽取图片案例:

ffmpeg -i test.mp4 -t 3 -s 640x360 -r 5 -v quiet ./video_test/frame%03d.jpg
-t 3 意思是抽取前三秒数据
-r 5 意思是每秒抽取5帧数据
-v quiet 意思是终端执行完此命令后不会显示无管的多余信息
ffmpeg使用详解_第7张图片

图片合成视频案例:

ffmpeg -f image2 -i ./video_test/frame%03d.jpg -y -r 5 ./video_test/test.mp4
-y 如果video_test目录下有test.mp4这个文件则直接覆盖了
-r 5 每秒几帧

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 type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol
    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
-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 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 decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.
-vol volume         change audio volume (256=normal)

Advanced global options:
-cpuflags flags     force specific cpu flags
-cpucount count     force specific cpu count
-hide_banner hide_banner  do not show program banner
-copy_unknown       Copy unknown stream types
-recast_media       allow recasting stream type in order to force a decoder of different media type
-benchmark          add timings for benchmarking
-benchmark_all      add timings for each task
-progress url       write program-readable progress information
-stdin              enable or disable interaction on standard input
-timelimit limit    set max runtime in seconds in CPU user time
-dump               dump each input packet
-hex                when dumping packets, also dump the payload
-vsync              video sync method
-frame_drop_threshold   frame drop threshold
-async              audio sync method
-adrift_threshold threshold  audio drift threshold
-copyts             copy timestamps
-start_at_zero      shift input timestamps to start at 0 when using copyts
-copytb mode        copy input stream time base when stream copying
-dts_delta_threshold threshold  timestamp discontinuity delta threshold
-dts_error_threshold threshold  timestamp error delta threshold
-xerror error       exit on error
-abort_on flags     abort on the specified condition flags
-filter_complex graph_description  create a complex filtergraph
-lavfi graph_description  create a complex filtergraph
-filter_complex_script filename  read complex filtergraph description from a file
-auto_conversion_filters  enable automatic conversion filters globally
-stats_period time  set the period at which ffmpeg updates stats and -progress output
-debug_ts           print timestamp debugging info
-psnr               calculate PSNR of compressed frames
-vstats             dump video coding statistics to file
-vstats_file file   dump video coding statistics to file
-vstats_version     Version of the vstats format to use.
-qphist             show QP histogram
-sdp_file file      specify a file in which to print sdp information
-init_hw_device args  initialise hardware device
-filter_hw_device device  set hardware device used when filtering

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

Advanced per-file options:
-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]  set input stream mapping
-map_channel file.stream.channel[:syncfile.syncstream]  map an audio channel from one stream to another
-map_chapters input_file_index  set chapters mapping
-accurate_seek      enable/disable accurate seeking with -ss
-itsoffset time_off  set the input ts offset
-itsscale scale     set the input ts scale
-dframes number     set the number of data frames to output
-re                 read input at native frame rate; equivalent to -readrate 1
-readrate speed     read input at specified rate
-shortest           finish encoding within shortest input
-bitexact           bitexact mode
-copyinkf           copy initial non-keyframes
-copypriorss        copy or discard frames before start time
-tag fourcc/tag     force codec tag/fourcc
-q q                use fixed quality scale (VBR)
-qscale q           use fixed quality scale (VBR)
-profile profile    set profile
-attach filename    add an attachment to the output file
-dump_attachment filename  extract an attachment into a file
-stream_loop loop count  set number of times input stream shall be looped
-thread_queue_size  set the maximum number of queued packets from the demuxer
-find_stream_info   read and decode the streams to fill missing information with heuristics
-bits_per_raw_sample number  set the number of bits per raw sample
-autorotate         automatically insert correct rotate filters
-autoscale          automatically insert a scale filter at the end of the filter graph
-muxdelay seconds   set the maximum demux-decode delay
-muxpreload seconds  set the initial demux-decode delay
-time_base ratio    set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)
-enc_time_base ratio  set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). two special values are defined - 0 = use frame rate (video) or sample rate (audio),-1 = match source time base
-bsf bitstream_filters  A comma-separated list of bitstream filters
-fpre filename      set options from indicated preset file
-max_muxing_queue_size packets  maximum number of packets that can be buffered while waiting for all streams to initialize
-muxing_queue_data_threshold bytes  set the threshold after which max_muxing_queue_size is taken into account
-dcodec codec       force data codec ('copy' to copy stream)

Video 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)
-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

Advanced Video options:
-pix_fmt format     set pixel format
-rc_override override  rate control override for specific intervals
-passlogfile prefix  select two pass log file name prefix
-psnr               calculate PSNR of compressed frames
-vstats             dump video coding statistics to file
-vstats_file file   dump video coding statistics to file
-vstats_version     Version of the vstats format to use.
-intra_matrix matrix  specify intra matrix coeffs
-inter_matrix matrix  specify inter matrix coeffs
-chroma_intra_matrix matrix  specify intra matrix coeffs
-top                top=1/bottom=0/auto=-1 field first
-vtag fourcc/tag    force video tag/fourcc
-qphist             show QP histogram
-force_fps          force the selected framerate, disable the best supported framerate selection
-streamid streamIndex:value  set the value of an outfile streamid
-force_key_frames timestamps  force key frames at specified timestamps
-hwaccel hwaccel name  use HW accelerated decoding
-hwaccel_device devicename  select a device for HW acceleration
-hwaccel_output_format format  select output format used with HW accelerated decoding
-vbsf video bitstream_filters  deprecated
-vpre preset        set the video options to the indicated preset

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

Advanced Audio options:
-atag fourcc/tag    force audio tag/fourcc
-sample_fmt format  set sample format
-channel_layout layout  set channel layout
-guess_layout_max   set the maximum number of channels to try to guess the channel layout
-absf audio bitstream_filters  deprecated
-apre preset        set the audio options to the indicated preset

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

你可能感兴趣的:(python,配置,Linux,音视频,python,服务器)