FFMPEG 基本概念

  • CODEC: code, decode
  • Container: file format, such as flv, mkv, avi
  • Stream: audio, video, cc, …
  • Freame: I P B
  • Mux / Demux
  • fps
  • bps

ffmpeg

  • 查询 h264 解码器:
    ffmpeg -decoders | grep h264
    1
    2
    VFS..D h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
    V....D libopenh264 OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
  • 查询 h264 编码器
    ffmpeg -encoders | grep h264

    1
    2
    3
    4
    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 libopenh264 OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
    V....D h264_videotoolbox VideoToolbox H.264 Encoder (codec h264)
  • 转码示例 cpu
    ./ffmpeg -i ~/Downloads/a.MOV -acodec aac -ar 12000 -ab 32 -s 360x640 -qscale 6 b.mp4

  • gpu
    ./ffmpeg -hwaccel videotoolbox -c:v libopenh264 -i ~/Downloads/a.MOV -c:v hevc_videotoolbox -acodec aac -ar 12000 -ab 32k -s 360x640 -qscale 6 b.mp4

  • use gpu convert hevc to h264
    ./ffmpeg -hwaccel videotoolbox -c:v hevc -i ~/Downloads/a.MOV -c:v h264_videotoolbox -acodec aac -ar 24000 -ab 8k -s 720x1280 -r 12 -b 1m b.mp4

ffprobe

https://ffmpeg.org/ffprobe.html

  • check the format of the container used by a multimedia stream
  • check the format of and type of each media stream contained in a multimedia stream

Notice Note

  • can check url
  • defalut output is stdout
  • output format is specified by the print-format option

SI unit?

Stream spedifiers

  • example:

    1
    2
    3
    // `-codec:a:1 ac3`, `a:1` matches the 2nd audio stream
    // `-b:a 128k`, `-b:a` matches all audio streams
    // no stream specifier matches all streams
  • stream_index, stream numbering is based on the order of the streams as detected by libavformat except when a program ID is also specified

  • stream_type[:additional_stream_specifier]:

    • v or V for video
    • a for audio
    • s for subtitle
    • d for data
    • t for attachments
      Note:
      1. v matches all video streams, V only matches video streams which are not attached pritures, video thumbnails or cover arts
      2. if additional_stream_specifier is used, then it matches streams which both have this type and match the additional_stream_specifier
  • p:program_id[:additional_steam_specifier]

  • #stream_id or i:stream_id: e.g. PID in MPEG-TS container

  • m:key[:value], matches streams with the metadata tag key having the specified value

  • u, matches streams with usable configuration, the codes must be defined and the essential information such as video dimension or audio sample rate must be present.
    Note: in ffmpeg, matching by metadata will only work properly for input files.

    bsf: bitstream_filter

ffprobe 示例

ffprobe [input source]
output:

1
2
3
4
5
6
7
8
9
10
11
12
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2023-02-18T11:52:04.000000Z
com.apple.quicktime.location.accuracy.horizontal: 13.644440
com.apple.quicktime.location.ISO6709: +40.0713+116.4351+040.260/
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 13 Pro Max
com.apple.quicktime.software: 16.2
com.apple.quicktime.creationdate: 2023-02-18T19:52:04+0800
Duration: 00:02:03.30, start: 0.000000, bitrate: 48358 kb/s

location.accuracy.horizontal

location.ISO6709