前言
本文讲解 FFmpeg 常用命令,并进行实践。
有关 FFmpeg 的入门及编译等内容可以参考我之前的博客:
一、学习资料参考
- 适合入门后再看
- 适合入门后再看
- 初学者可以参考着看一看,里面有些复杂的可以跳过
- 适合提升的时候用
- 里面既有小白入门的也有比较难的
- 用于提升的时候用
二、FFmpeg 选项
1、主要选项
查看 ffmpeg 的版本
ffmpeg -version
上图红框内为编译选项,编译选项支持编解码的格式、封装的格式及网络协议等等第三方包。其中比较常用的:
- 音频相关:
libmp3lame
- 视频相关:
libx264
、libx265
、libvpx
、libxvid
、avisynth
使用 MediaInfo 对原视频文件 SampleVideo_1280x720_20mb.mp4
进行分析:
使用 MediaInfo 对 flv 格式原视频文件 SampleVideo_1280x720_20mb.flv
进行分析:
flv
文件默认视频编码格式为 sorenson spark
,默认音频编码格式为 mp3
,即:Flv: [sorenson spark(vcodec) + mp3(acodec)]
以下表格内三种写法是等价的:
音频 | 视频 | 字幕 |
-codec:a | -codec:v | -codec:s |
-c:a | -c:v | -c:s |
-acodec | -vcodec | -scodec |
①、主要命令选项
-f fmt (input/output)
:指定输入或者输出文件格式(封装格式,视频容器)。常规可省略,而使用依据扩展名(文件的前几百 K 的内容,智能分析)的自动指定,但一些选项需要强制明确设定。-i filename(input)
:指定输入文件。-y(global)
:默认自动覆盖输出文件,而不再询问确认。-n( global)
:不覆盖输出文件,如果输出文件已经存在则立即退出。-t duration( input/output)
:限制输入/输出的时间。如果是在-i
前面,就是限定从输入中读取多少时间的数据;如果是用于限定输出文件,则表示写入多少时间数据后就停止。duration 可以是以秒为单位的数值或者 hh:mm:ss[.xxx] 格式的时间值。注意 -to 和 -t 是互斥的,-t 有更高优先级。-to position (output)
:只写入 position 时间后就停止,position 可以是以秒为单位的数值或者 hh:mm:ss[.xxx] 格式的时间值。注意 -to 和 -t 是互斥的,-t 有更高优先级。-ss position (input/output)
:当在 -i 前,表示定位输入文件到 position 指定的位置。注意可能一些格式是不支持精确定位的,所以 ffmpeg 可能是定位到最接近 position(在之前)的可定位点。position 可以是以秒为单位的数值或者 hh:mm:ss[.xxx] 格式的时间值。-codec[:stream_specifier] codec (input/output,per-stream)
:为特定的文件选择编/解码模式,对于输出文件就是编码器, 对于输入或者某个流就是解码器。选项参数中 codec 是编解码器的名字,或者是 copy(仅对输出文件)则意味着流数据直接复制而不再编码。
使用下面命令可以检测 ffmepg 所支持的所有编码器的格式
ffmpeg.exe -encoders • 1
回显如下:
PS D:\Work\test> ffmpeg.exe -encoders ffmpeg version 6.0-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers built with gcc 12.2.0 (Rev10, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband libavutil 58. 2.100 / 58. 2.100 libavcodec 60. 3.100 / 60. 3.100 libavformat 60. 3.100 / 60. 3.100 libavdevice 60. 1.100 / 60. 1.100 libavfilter 9. 3.100 / 9. 3.100 libswscale 7. 1.100 / 7. 1.100 libswresample 4. 10.100 / 4. 10.100 libpostproc 57. 1.100 / 57. 1.100 Encoders: V..... = Video A..... = Audio S..... = Subtitle .F.... = Frame-level multithreading ..S... = Slice-level multithreading ...X.. = Codec is experimental ....B. = Supports draw_horiz_band .....D = Supports direct rendering method 1 ------ V....D a64multi Multicolor charset for Commodore 64 (codec a64_multi) V....D a64multi5 Multicolor charset for Commodore 64, extended with 5th color (colram) (codec a64_multi5) V....D alias_pix Alias/Wavefront PIX image V..... amv AMV Video V....D apng APNG (Animated Portable Network Graphics) image V....D asv1 ASUS V1 V....D asv2 ASUS V2 V....D libaom-av1 libaom AV1 (codec av1) V....D av1_nvenc NVIDIA NVENC av1 encoder (codec av1) V..... av1_qsv AV1 (Intel Quick Sync Video acceleration) (codec av1) V....D av1_amf AMD AMF AV1 encoder (codec av1) V....D avrp Avid 1:1 10-bit RGB Packer V..X.D avui Avid Meridien Uncompressed V....D ayuv Uncompressed packed MS 4:4:4:4 VF...D bitpacked Bitpacked V....D bmp BMP (Windows and OS/2 bitmap) VF...D cfhd GoPro CineForm HD V....D cinepak Cinepak V....D cljr Cirrus Logic AccuPak V.S..D vc2 SMPTE VC-2 (codec dirac) VFS..D dnxhd VC3/DNxHD V....D dpx DPX (Digital Picture Exchange) image VFS..D dvvideo DV (Digital Video) VF...D exr OpenEXR image V.S..D ffv1 FFmpeg video codec #1 VF...D ffvhuff Huffyuv FFmpeg variant V....D fits Flexible Image Transport System V....D flashsv Flash Screen Video V....D flashsv2 Flash Screen Video Version 2 V..... flv FLV / Sorenson Spark / Sorenson H.263 (Flash Video) (codec flv1) V....D gif GIF (Graphics Interchange Format) V..... h261 H.261 V..... h263 H.263 / H.263-1996 V.S... h263p H.263+ / H.263-1998 / H.263 version 2 V....D libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264) V....D libx264rgb libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264) V....D h264_amf AMD AMF H.264 Encoder (codec h264) V....D h264_mf H264 via MediaFoundation (codec h264) V....D h264_nvenc NVIDIA NVENC H.264 encoder (codec h264) V..... h264_qsv H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (Intel Quick Sync Video acceleration) (codec h264) VF...D hdr HDR (Radiance RGBE format) image V....D libx265 libx265 H.265 / HEVC (codec hevc) V....D hevc_amf AMD AMF HEVC encoder (codec hevc) V....D hevc_mf HEVC via MediaFoundation (codec hevc) V....D hevc_nvenc NVIDIA NVENC hevc encoder (codec hevc) V..... hevc_qsv HEVC (Intel Quick Sync Video acceleration) (codec hevc) VF...D huffyuv Huffyuv / HuffYUV V....D jpeg2000 JPEG 2000 VF.... libopenjpeg OpenJPEG JPEG 2000 (codec jpeg2000) VF...D jpegls JPEG-LS VF...D ljpeg Lossless JPEG VF...D magicyuv MagicYUV video VFS... mjpeg MJPEG (Motion JPEG) V..... mjpeg_qsv MJPEG (Intel Quick Sync Video acceleration) (codec mjpeg) V.S... mpeg1video MPEG-1 video V.S... mpeg2video MPEG-2 video V..... mpeg2_qsv MPEG-2 video (Intel Quick Sync Video acceleration) (codec mpeg2video) V.S... mpeg4 MPEG-4 part 2 V....D libxvid libxvidcore MPEG-4 part 2 (codec mpeg4) V..... msmpeg4v2 MPEG-4 part 2 Microsoft variant version 2 V..... msmpeg4 MPEG-4 part 2 Microsoft variant version 3 (codec msmpeg4v3) V..... msvideo1 Microsoft Video-1 V....D pam PAM (Portable AnyMap) image V....D pbm PBM (Portable BitMap) image V....D pcx PC Paintbrush PCX image V....D pfm PFM (Portable FloatMap) image V....D pgm PGM (Portable GrayMap) image V....D pgmyuv PGMYUV (Portable GrayMap YUV) image V....D phm PHM (Portable HalfFloatMap) image VF...D png PNG (Portable Network Graphics) image V....D ppm PPM (Portable PixelMap) image VF...D prores Apple ProRes VF...D prores_aw Apple ProRes (codec prores) VFS... prores_ks Apple ProRes (iCodec Pro) (codec prores) VF...D qoi QOI (Quite OK Image format) image V....D qtrle QuickTime Animation (RLE) video V....D r10k AJA Kona 10-bit RGB Codec V....D r210 Uncompressed RGB 10-bit VF...D rawvideo raw video V....D roqvideo id RoQ video (codec roq) V....D rpza QuickTime video (RPZA) V..... rv10 RealVideo 1.0 V..... rv20 RealVideo 2.0 V....D sgi SGI image V....D smc QuickTime Graphics (SMC) V....D snow Snow V..... speedhq NewTek SpeedHQ V....D sunrast Sun Rasterfile image V....D svq1 Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1 V....D targa Truevision Targa image V....D libtheora libtheora Theora (codec theora) VF...D tiff TIFF image VF...D utvideo Ut Video VF...D v210 Uncompressed 4:2:2 10-bit V....D v308 Uncompressed packed 4:4:4 V....D v408 Uncompressed packed QT 4:4:4:4 V....D v410 Uncompressed 4:4:4 10-bit V.S..D vbn Vizrt Binary Image V..... vnull null video V....D libvpx libvpx VP8 (codec vp8) V....D libvpx-vp9 libvpx VP9 (codec vp9) V..... vp9_qsv VP9 video (Intel Quick Sync Video acceleration) (codec vp9) VF...D wbmp WBMP (Wireless Application Protocol Bitmap) image V....D libwebp_anim libwebp WebP image (codec webp) V....D libwebp libwebp WebP image (codec webp) V..... wmv1 Windows Media Video 7 V..... wmv2 Windows Media Video 8 V..... wrapped_avframe AVFrame to AVPacket passthrough V....D xbm XBM (X BitMap) image V....D xface X-face image V....D xwd XWD (X Window Dump) image V....D y41p Uncompressed YUV 4:1:1 12-bit V....D yuv4 Uncompressed packed 4:2:0 VF...D zlib LCL (LossLess Codec Library) ZLIB V....D zmbv Zip Motion Blocks Video A....D aac AAC (Advanced Audio Coding) A....D aac_mf AAC via MediaFoundation (codec aac) A....D ac3 ATSC A/52A (AC-3) A....D ac3_fixed ATSC A/52A (AC-3) (codec ac3) A....D ac3_mf AC3 via MediaFoundation (codec ac3) A....D adpcm_adx SEGA CRI ADX ADPCM A....D adpcm_argo ADPCM Argonaut Games A....D g722 G.722 ADPCM (codec adpcm_g722) A....D g726 G.726 ADPCM (codec adpcm_g726) A....D g726le G.726 little endian ADPCM ("right-justified") (codec adpcm_g726le) A....D adpcm_ima_alp ADPCM IMA High Voltage Software ALP A....D adpcm_ima_amv ADPCM IMA AMV A....D adpcm_ima_apm ADPCM IMA Ubisoft APM A....D adpcm_ima_qt ADPCM IMA QuickTime A....D adpcm_ima_ssi ADPCM IMA Simon & Schuster Interactive A....D adpcm_ima_wav ADPCM IMA WAV A....D adpcm_ima_ws ADPCM IMA Westwood A....D adpcm_ms ADPCM Microsoft A....D adpcm_swf ADPCM Shockwave Flash A....D adpcm_yamaha ADPCM Yamaha A....D alac ALAC (Apple Lossless Audio Codec) A....D libopencore_amrnb OpenCORE AMR-NB (Adaptive Multi-Rate Narrow-Band) (codec amr_nb) A....D libvo_amrwbenc Android VisualOn AMR-WB (Adaptive Multi-Rate Wide-Band) (codec amr_wb) A..... anull null audio A....D aptx aptX (Audio Processing Technology for Bluetooth) A....D aptx_hd aptX HD (Audio Processing Technology for Bluetooth) A....D comfortnoise RFC 3389 comfort noise generator A....D dfpwm DFPWM1a audio A..X.D dca DCA (DTS Coherent Acoustics) (codec dts) A....D eac3 ATSC A/52 E-AC-3 A....D flac FLAC (Free Lossless Audio Codec) A....D g723_1 G.723.1 A....D libgsm libgsm GSM (codec gsm) A....D libgsm_ms libgsm GSM Microsoft variant (codec gsm_ms) A..X.D mlp MLP (Meridian Lossless Packing) A....D mp2 MP2 (MPEG audio layer 2) A....D mp2fixed MP2 fixed point (MPEG audio layer 2) (codec mp2) A....D libmp3lame libmp3lame MP3 (MPEG audio layer 3) (codec mp3) A....D mp3_mf MP3 via MediaFoundation (codec mp3) A....D nellymoser Nellymoser Asao A..X.D opus Opus A....D libopus libopus Opus (codec opus) A....D pcm_alaw PCM A-law / G.711 A-law A....D pcm_bluray PCM signed 16|20|24-bit big-endian for Blu-ray media A....D pcm_dvd PCM signed 16|20|24-bit big-endian for DVD media A....D pcm_f32be PCM 32-bit floating point big-endian A....D pcm_f32le PCM 32-bit floating point little-endian A....D pcm_f64be PCM 64-bit floating point big-endian A....D pcm_f64le PCM 64-bit floating point little-endian A....D pcm_mulaw PCM mu-law / G.711 mu-law A....D pcm_s16be PCM signed 16-bit big-endian A....D pcm_s16be_planar PCM signed 16-bit big-endian planar A....D pcm_s16le PCM signed 16-bit little-endian A....D pcm_s16le_planar PCM signed 16-bit little-endian planar A....D pcm_s24be PCM signed 24-bit big-endian A....D pcm_s24daud PCM D-Cinema audio signed 24-bit A....D pcm_s24le PCM signed 24-bit little-endian A....D pcm_s24le_planar PCM signed 24-bit little-endian planar A....D pcm_s32be PCM signed 32-bit big-endian A....D pcm_s32le PCM signed 32-bit little-endian A....D pcm_s32le_planar PCM signed 32-bit little-endian planar A....D pcm_s64be PCM signed 64-bit big-endian A....D pcm_s64le PCM signed 64-bit little-endian A....D pcm_s8 PCM signed 8-bit A....D pcm_s8_planar PCM signed 8-bit planar A....D pcm_u16be PCM unsigned 16-bit big-endian A....D pcm_u16le PCM unsigned 16-bit little-endian A....D pcm_u24be PCM unsigned 24-bit big-endian A....D pcm_u24le PCM unsigned 24-bit little-endian A....D pcm_u32be PCM unsigned 32-bit big-endian A....D pcm_u32le PCM unsigned 32-bit little-endian A....D pcm_u8 PCM unsigned 8-bit A....D pcm_vidc PCM Archimedes VIDC A....D real_144 RealAudio 1.0 (14.4K) (codec ra_144) A....D roq_dpcm id RoQ DPCM A..X.D s302m SMPTE 302M A....D sbc SBC (low-complexity subband codec) A..X.D sonic Sonic A..X.D sonicls Sonic lossless A....D libspeex libspeex Speex (codec speex) A..X.D truehd TrueHD A....D tta TTA (True Audio) A..X.D vorbis Vorbis A....D libvorbis libvorbis (codec vorbis) A....D wavpack WavPack A....D wmav1 Windows Media Audio 1 A....D wmav2 Windows Media Audio 2 S..... ssa ASS (Advanced SubStation Alpha) subtitle (codec ass) S..... ass ASS (Advanced SubStation Alpha) subtitle S..... dvbsub DVB subtitles (codec dvb_subtitle) S..... dvdsub DVD subtitles (codec dvd_subtitle) S..... mov_text 3GPP Timed Text subtitle S..... srt SubRip subtitle (codec subrip) S..... subrip SubRip subtitle S..... text Raw text subtitle S..... ttml TTML subtitle S..... webvtt WebVTT subtitle S..... xsub DivX subtitles (XSUB)
FFmpeg常用命令行讲解及实战一(二)https://developer.aliyun.com/article/1472391