音视频处理 ffmpeg初级开发 命令行工具-实用命令

参考链接

  • ffmpeg Documentation
  • 作者:smallest_one  链接:FFmpeg命令行工具-实用命令 - 简书

目录

  • 1,help命令使用
    • 1.1 ffmpeg命令的语法结构
    • 1.2 获取详细的help信息
    • 1.3 打印帮助或者支持能力的信息
    • 1.4 全局选项
    • 1.5 文件选项
    • 1.6 视频/音频/字幕相关选项
  • 2,流选择选项
  • 3,视频封装解封装
    • 3.1 视频格式转换
    • 3.2 分离/合并视频音频流
    • 3.3 截取视频片段
    • 3.4 视频转换为m3u8格式
    • 3.5 把视频文件推送到rtmp服务器
    • 3.6 对视频进行切片
  • 4,视频解码编码
    • 4.1 视频截图
    • 4.2 视频/图片尺寸修改
    • 4.3 分离视频的YUV通道分量
    • 4.4 图片序列与视频的互相转换
  • 5,视频filter
    • 5.1 视频加水印overlay
    • 5.2 视频旋转transpose
    • 5.3 调色3DLutFilter
    • 5.4 图像/视频转换成黑白的hue
    • 5.5 裁剪视频crop
    • 5.6 视频尺寸缩放scale
    • 5.7 视频中去水印delogo
    • 5.8 给视频或图像加上黑边pad
    • 5.9 计算psnr/ssim
    • 5.10 视频按时间拼接
    • 5.11 视频左右拼接
    • 5.12 打印视频帧的一些信息showinfo
    • 5.13 生成纯色的图片
    • 5.14 打印帧序号/pts到视频帧水印drawtext
  • 6,音频解码编码     PCM原始数据和WAV格式转换
  • 7,音频filter             倍速atempo
  • 8,字幕相关
    • 8.1 字幕文件转换
    • 8.2 集成字幕到视频文件
  • 9,ffplay命令
    • 9.1 ffplay播放yuv视频数据
    • 9.2 ffplay播放PCM音频数据
    • 9.3 ffplay播放音频并显示波形图
    • 9.4 ffplay指定显示宽高
  • 10,ffprobe命令
    • 10.1 ffprobe查看媒体文件的信息
    • 10.2 ffprobe查看时间戳
  • 11,其他
    • 11.1 ffmpeg或ffplay 打开 DEBUG 日志输出
    • 11.2 FFmpeg命令日志输出到文件
    • 11.3 打印支持DirectShow的设备列表

1,help命令使用

  • ffmpeg -help
  • 终端打印帮助信息
  • 打印ffmpeg以及各个模块的版本信息
chy-cpabe@ubuntu:~/ffmpeg-source/ffmpeg$ ffmpeg -help
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
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)

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

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

1.1 ffmpeg命令的语法结构

  • ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
  • options:对输入和输出均有影响的选项
  • [[infile options] -i infile]  指定输入选项和输入文件  ... 表示可以包含多个输入文件
  • {[outfile options] outfile} 指定输出选项和输出文件 ... 表示可以包含多个输出文件

1.2 获取详细的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/protocol
    See man ffmpeg for detailed description of the options.
  •  -h long: 打印更多的选项参数
  • -h full: 打印所有的选项参数,包括所有针对于format和codec的选项,信息特别的长
  • -h type=name: 打印指定名称的decoder/encoder/demuxer/muxer/filter的所有选项信息
  • man ffmpeg: 查看ffmpeg的帮助手册
  • 特别注意:
    • 重点使用 -h type=name
    • 例如,查看libx264支持的参数  ffmpeg -h encoder=libx264
chy-cpabe@ubuntu:~/ffmpeg-source/ffmpeg$ ffmpeg -h encoder=libx264
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Encoder libx264 [libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:
    General capabilities: dr1 delay threads 
    Threading capabilities: other
    Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21
libx264 AVOptions:
  -preset                 E..V....... Set the encoding preset (cf. x264 --fullhelp) (default "medium")
  -tune                   E..V....... Tune the encoding params (cf. x264 --fullhelp)
  -profile                E..V....... Set profile restrictions (cf. x264 --fullhelp) 
  -fastfirstpass         E..V....... Use fast settings when encoding first pass (default true)
  -level                  E..V....... Specify level (as defined by Annex A)
  -passlogfile            E..V....... Filename for 2 pass stats
  -wpredp                 E..V....... Weighted prediction for P-frames
  -a53cc                 E..V....... Use A53 Closed Captions (if available) (default true)
  -x264opts               E..V....... x264 options
  -crf                     E..V....... Select the quality for constant quality mode (from -1 to FLT_MAX) (default -1)
  -crf_max                 E..V....... In CRF mode, prevents VBV from lowering quality beyond this point. (from -1 to FLT_MAX) (default -1)
  -qp                        E..V....... Constant quantization parameter rate control method (from -1 to INT_MAX) (default -1)
  -aq-mode                   E..V....... AQ method (from -1 to INT_MAX) (default -1)
     none            0            E..V.......
     variance        1            E..V....... Variance AQ (complexity mask)
     autovariance    2            E..V....... Auto-variance AQ
     autovariance-biased 3            E..V....... Auto-variance AQ with bias to dark scenes
  -aq-strength             E..V....... AQ strength. Reduces blocking and blurring in flat and textured areas. (from -1 to FLT_MAX) (default -1)
  -psy                   E..V....... Use psychovisual optimizations. (default auto)
  -psy-rd                 E..V....... Strength of psychovisual optimization, in : format.
  -rc-lookahead              E..V....... Number of frames to look ahead for frametype and ratecontrol (from -1 to INT_MAX) (default -1)
  -weightb               E..V....... Weighted prediction for B-frames. (default auto)
  -weightp                   E..V....... Weighted prediction analysis method. (from -1 to INT_MAX) (default -1)
     none            0            E..V.......
     simple          1            E..V.......
     smart           2            E..V.......
  -ssim                  E..V....... Calculate and print SSIM stats. (default auto)
  -intra-refresh         E..V....... Use Periodic Intra Refresh instead of IDR frames. (default auto)
  -bluray-compat         E..V....... Bluray compatibility workarounds. (default auto)
  -b-bias                    E..V....... Influences how often B-frames are used (from INT_MIN to INT_MAX) (default INT_MIN)
  -b-pyramid                 E..V....... Keep some B-frames as references. (from -1 to INT_MAX) (default -1)
     none            0            E..V.......
     strict          1            E..V....... Strictly hierarchical pyramid
     normal          2            E..V....... Non-strict (not Blu-ray compatible)
  -mixed-refs            E..V....... One reference per partition, as opposed to one reference per macroblock (default auto)
  -8x8dct                E..V....... High profile 8x8 transform. (default auto)
  -fast-pskip            E..V....... (default auto)
  -aud                   E..V....... Use access unit delimiters. (default auto)
  -mbtree                E..V....... Use macroblock tree ratecontrol. (default auto)
  -deblock                E..V....... Loop filter parameters, in  form.
  -cplxblur                E..V....... Reduce fluctuations in QP (before curve compression) (from -1 to FLT_MAX) (default -1)
  -partitions             E..V....... A comma-separated list of partitions to consider. Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all
  -direct-pred               E..V....... Direct MV prediction mode (from -1 to INT_MAX) (default -1)
     none            0            E..V.......
     spatial         1            E..V.......
     temporal        2            E..V.......
     auto            3            E..V.......
  -slice-max-size            E..V....... Limit the size of each slice in bytes (from -1 to INT_MAX) (default -1)
  -stats                  E..V....... Filename for 2 pass stats
  -nal-hrd                   E..V....... Signal HRD information (requires vbv-bufsize; cbr not allowed in .mp4) (from -1 to INT_MAX) (default -1)
     none            0            E..V.......
     vbr             1            E..V.......
     cbr             2            E..V.......
  -avcintra-class            E..V....... AVC-Intra class 50/100/200/300/480 (from -1 to 480) (default -1)
  -me_method                 E..V....... Set motion estimation method (from -1 to 4) (default -1)
     dia             0            E..V.......
     hex             1            E..V.......
     umh             2            E..V.......
     esa             3            E..V.......
     tesa            4            E..V.......
  -motion-est                E..V....... Set motion estimation method (from -1 to 4) (default -1)
     dia             0            E..V.......
     hex             1            E..V.......
     umh             2            E..V.......
     esa             3            E..V.......
     tesa            4            E..V.......
  -forced-idr            E..V....... If forcing keyframes, force them as IDR frames. (default false)
  -coder                     E..V....... Coder type (from -1 to 1) (default default)
     default         -1           E..V.......
     cavlc           0            E..V.......
     cabac           1            E..V.......
     vlc             0            E..V.......
     ac              1            E..V.......
  -b_strategy                E..V....... Strategy to choose between I/P/B-frames (from -1 to 2) (default -1)
  -chromaoffset              E..V....... QP difference between chroma and luma (from INT_MIN to INT_MAX) (default 0)
  -sc_threshold              E..V....... Scene change threshold (from INT_MIN to INT_MAX) (default -1)
  -noise_reduction           E..V....... Noise reduction (from INT_MIN to INT_MAX) (default -1)
  -udu_sei               E..V....... Use user data unregistered SEI if available (default false)
  -x264-params        E..V....... Override the x264 configuration using a :-separated list of key=value parameters

1.3 打印帮助或者支持能力的信息

  • 获取help信息
  • 打印各种格式支持的能力
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

1.4 全局选项

  •  全局选项说明
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)

1.5 文件选项

  • 针对每个文件可以指定的选项
  • 例:-f fmt指定的文件的格式
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

1.6 视频/音频/字幕相关选项

  •  针对视频/音频/字幕相关的选项
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

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

2,流选择选项

  • 媒体格式如Mp4、AVI等内部包含了多种类型的流
    • FFmpeg可以识别5种流类型
    • 音频 audio a
    • 附件 attachment t
    • 数据 data d
    • 字幕 subtitle s
    • 视频 video v
  • 使用 -map选择需要的流,语法如下 file_number:stream_type[:stream_number]
    • file_number:       文件索引
    • stream_number  流索引 
  • 特别的流选择指令
    • -map 0  选择所有的流类型和其中所有的流
    • -map i:v  选择文件i中的所有视频流
    • -map i:a  选择文件i中的所有音频流
    • -map i:s  选择文件i中的所有字幕流

3,视频封装解封装

3.1 视频格式转换

  • FFmpeg笔记--vcodec和-c:v,-acodec和-c:a的区别?_木杉的博客-CSDN博客_ffmpeg vcodec
  • ffmpeg - Difference between -c:v and -vcodec, and -c:a and -acodec? - Super User
  • avi 转 MP4
  •  ffmpeg -i /home/chy-cpabe/Videos/video_avi.avi -c:a copy -c:v copy /home/chy-cpabe/Videos/avi_2_mp4.mp4

音视频处理 ffmpeg初级开发 命令行工具-实用命令_第1张图片

  •  mp4 转 ts
  • ffmpeg系列之mp4与ts格式转换_starmier的博客-CSDN博客_ffmpeg mp4转ts
chy-cpabe@ubuntu:~/ffmpeg-source/ffmpeg$ ffmpeg -i /home/chy-cpabe/Videos/avi_2_mp4.mp4 /home/chy-cpabe/Videos/mp4_2_ts.ts
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/chy-cpabe/Videos/avi_2_mp4.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.23.100
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1632 kb/s
  Stream #0:0[0x1](und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1500 kb/s, 24 fps, 24 tbr, 12288 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg2video (native))
  Stream #0:1 -> #0:1 (mp3 (mp3float) -> mp2 (native))
Press [q] to stop, [?] for help
Output #0, mpegts, to '/home/chy-cpabe/Videos/mp4_2_ts.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.23.100
  Stream #0:0(und): Video: mpeg2video (Main), yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 24 fps, 90k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.27.100 mpeg2video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
  Stream #0:1(und): Audio: mp2, 44100 Hz, stereo, s16, 384 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.27.100 mp2
frame= 1082 fps=622 q=31.0 Lsize=    4504kB time=00:00:45.04 bitrate= 819.1kbits/s speed=25.9x    
video:1968kB audio:2111kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 10.405245%

3.2 分离/合并视频音频流

  • 分离音频流
    • ffmpeg -i input-video -vn -c:a copy output-audio
      • -vn:表示不要视频
      • -acodec copy:表示拷贝输入视频的音频流
      • 输出文件 例如 output.wav
chy-cpabe@ubuntu:~/ffmpeg-source/ffmpeg$ ffmpeg -i /home/chy-cpabe/Videos/video_avi.avi -vn -c:a copy /home/chy-cpabe/Videos/video_avi.wav
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, avi, from '/home/chy-cpabe/Videos/video_avi.avi':
  Metadata:
    software        : Lavf54.59.106
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1640 kb/s
  Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1501 kb/s, 24 fps, 24 tbr, 24 tbn
  Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 128 kb/s
Output #0, wav, to '/home/chy-cpabe/Videos/video_avi.wav':
  Metadata:
    software        : Lavf54.59.106
    ISFT            : Lavf59.23.100
  Stream #0:0: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 128 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=     704kB time=00:00:45.03 bitrate= 128.0kbits/s speed=6.41e+03x    
video:0kB audio:704kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.014572%
  • 分离视频流
    • ffmpeg -i input-video -c:v copy -an output-video
      • -an:表示不要音频
      • -vcodec copy:表示拷贝输入视频的视频流
  • 同时分离音频和视频流
    • ffmpeg -i input-video -c:v copy -an output-video -c:a copy -vn output-audio
    • ffmpeg -i /home/chy-cpabe/Videos/video_avi.avi -c:v copy -an /home/chy-cpabe/Videos/video_mp4_1.mp4 -c:a copy -vn /home/chy-cpabe/Videos/video_avi_1.wav
      
  • 合并视频音频流
    • ffmpeg -i video_file -i audio_file -c:v copy -c:a copy output_file
    • ffmpeg -i /home/chy-cpabe/Videos/video_avi_1.wav -i /home/chy-cpabe/Videos/video_mp4_1.mp4 -c:v copy -c:v copy /home/chy-cpabe/Videos/merge.mp4
      

3.3 截取视频片段

  • 截取视频片段
    • ffmpeg -ss 5 -i input.mp4 -t 10 -c:v copy -c:a copy output.mp4
      • -ss 5指定从输入视频第5秒开始截取,-t 10指明最多截取10秒
      • 而-c:v copy -c:a copy标示视频与音频的编码不发生改变,而是直接复制,这样会大大提升速度,因为这样就不需要完全解码视频
      • 例子:ffmpeg -ss 5 -i merge.mp4 -t 10 -c:v copy -c:a copy merge_5-15.mp4
    • 截取10s到20s
      • 这个存在一个问题:音频数据流与先前保持不变,视频数据流 只显示10-20的数据
      • ffmpeg -i input.mp4 -c:v libx264 -filter:v select="between(t\, 10\, 20)" out.mp4
  • 从头截取前10帧
    • ffmpeg -i input.mp4 -c:v libx264 -filter:v select="gt(n\, -1)" -vframes 10 out.mp4
    • ffmpeg -i input.mp4 -c:v libx264 -filter:v select="between(n\, 0\, 9)" out.mp4
  • 中间截取 10-20 帧
    • ffmpeg -i input.mp4 -c:v libx264 -filter:v select="between(n\, 10\, 20)" out.mp4

3.4 视频转换为m3u8格式

  • ffmpeg -i yoona.mp4 -c copy -map 0 -f segment -segment_list yoona.m3u8 -segment_time 10 yoona-%04d.ts

    • 形成一个以m3u8结尾的视频文件,并进一步进行数据切分,形成以 yoona-%04d.ts命名规则以ts结尾的的视频切片

  • ffmpeg -i output20.mp4 -codec copy  -hls_list_size 0  -hls_wrap 0 -strict -2  -vbsf h264_mp4toannexb -absf aac_adtstoasc -f hls -hls_base_url https://test.com/ test.m3u8
    • -hls_time n: 设置每片的长度,默认值为2。单位为秒。即EXTINF tag对应的值。hls_time设置后效果不一定准确,会受到关键帧大小及其他因素影响。如果需要相对非常准确的切片,可以添加hls_flags的子参数split_by_time来保证生成的切片能够与hls_time设置的切片时长差不多。split_by_time参数必须与hls_time配合使用,并且使用split_by_time参数有可能会影响首画面体验,例如花屏或者首画面显示慢的问题,因为视频的第一帧不一定是关键帧。
    • -hls_list_size n:设置播放列表保存的最多条目,设置为0会保存有所片信息,默认值为5。为了解决这个问题,需要指定参数-hls_list_size 0,这样就能包含所有的片段。
    • -hls_wrap n:设置多少片之后开始覆盖,如果设置为0则不会覆盖,默认值为0.这个选项能够避免在磁盘上存储过多的 片,而且能够限制写入磁盘的最多的片的数量。
    • -hls_start_number n:设置播放列表中sequence number的值为number,默认值为0。注意:播放列表的sequence number 对每个segment来说都必须是唯一的,而且它不能和片的文件名(当使用wrap选项时,文件名有可能会重复使用)混淆
    • h264_mp4toannexb: h264有两种封装,一种是annexb模式,传统模式,有startcode,SPS和PPS是在ES中,vlc里打开编码器信息中显示h264;一种是mp4模式,一般mp4 ,mkv会有,没有startcode,SPS和PPS以及其它信息被封装在container中,每一个frame前面是这个frame的长度,vlc里打开编码器信息中显示avc1。很多解码器只支持annexb这种模式,因此需要将mp4做转换。
    • aac_adtstoasc:将AAC编码器编码后的原始码流(ADTS头 + ES流)封装为MP4或者FLV或者MOV等格式时,需要先将ADTS头转换为MPEG-4 AudioSpecficConfig (将音频相关编解码参数提取出来),并将原始码流中的ADTS头去掉(只剩下ES流);相反,从MP4或者FLV或者MOV等格式文件中解封装出AAC码流(只有ES流)时,需要在解析出的AAC码流前添加ADTS头(含音频相关编解码参数)
    • hls_base_url 参数用于为M3U8列表的文件路径设置前置基本路径参数,因为在FFmpeg中生成M3U8时写入的TS切片路径默认为M3U8生成的路径相同,但是实际上TS所存储的路径既可以为本地绝对路径,也可以为相对路

3.5 把视频文件推送到rtmp服务器

  • ffmpeg -re -i jack.mp4 -c copy -f flv rtmp://host/live/test        
  • 需要搭建 支持rtmp协议的服务器

3.6 对视频进行切片

  • 均匀切片
    • ffmpeg -i input.mp4 -c copy -f segment -segment_format mp4 -segment_time 300 -reset_timestamps 1 test_output-%d.mp4 
    • 将input.mp4 切换为5分钟时长的视频片段  300 / 60 = 5
    • 使用ffmpeg -h muxer=segment 查询segment muxer的参数
  • 按照时间点进行视频裁剪
    • ffmpeg -i input.mp4 -c copy -f segment -segment_format mp4 -segment_times 60,120,150 -reset_timestamps 1 test_output-%d.mp4 
    • 在第60秒 120秒 150秒 这三个时间点进行数据切片

4,视频解码编码

4.1 视频截图

  • 获取指定时间点的截图
ffmpeg -ss 01:23:45 -i input -vframes 1 -q:v 2 output.jpg

-i input file           the path to the input file
-ss 01:23:45            seek the position to the specified timestamp
-vframes 1              only handle one video frame
-q:v 2                  to control output quality. Full range is a linear scale of 1-31 where a lower value results in a higher quality. 2-5 is a good range to try.
output.jpg              output filename, should have a well-known extension
  • 截取指定帧序号的图像 帧序号从0开始
  • ffmpeg -i -vf "select=eq(n\,34)" -vframes 1 out.png
  • 例子:ffmpeg -i test.mp4 -vf "select=eq(n\,6)" -vframes 1 output_1.png 

4.2 视频/图片尺寸修改

  • 安装imagemagick,apt-get install imagemagick
  • 用identify命令查看图片信息 数据信息较少 
  • 包括:文件名,图像格式,图像大小,图像深度,颜色空间,文件大小,用户时间等,例如:

  • 参考链接
  • ImageMagick(2) identify展示图像详细信息_落叶_小唱的博客-CSDN博客 
chy-cpabe@ubuntu:~/Videos$ identify -verbose output.png 
Image: output.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 1920x1080+0+0
  Resolution: 1x1
  Print size: 1920x1080
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Pixels: 2073600
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 131.067 (0.513989)
      standard deviation: 56.6858 (0.222297)
      kurtosis: -1.2
      skewness: -0.241095
      entropy: 0.923994
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 147.134 (0.576995)
      standard deviation: 62.2514 (0.244123)
      kurtosis: -1.2576
      skewness: -0.216637
      entropy: 0.933398
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 147.762 (0.579459)
      standard deviation: 66.8398 (0.262117)
      kurtosis: -1.27695
      skewness: -0.220383
      entropy: 0.936936
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 141.988 (0.556814)
      standard deviation: 62.0647 (0.243391)
      kurtosis: -1.15139
      skewness: -0.182663
      entropy: 0.931443
  Rendering intent: Perceptual
  Gamma: 0.50994
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1920x1080+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2022-05-15T00:04:35-07:00
    date:modify: 2022-05-15T00:04:35-07:00
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.50994 (See Gamma, above)
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 2
    png:IHDR.color_type: 2 (Truecolor)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 1920, 1080
    png:pHYs: x_res=1, y_res=1, units=0
    signature: 102364a6ba97efa6c6693cdca6ecbc0df735fa8532195c0c7b21aec0c3e254f9
  Artifacts:
    filename: output.png
    verbose: true
  Tainted: False
  Filesize: 2.39MB
  Number pixels: 2.074M
  Pixels per second: 29.62MB
  User time: 0.050u
  Elapsed time: 0:01.070
  Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
  • 修改 图片的储存大小为先前的一半
  • ffmpeg -i sample.jpg -s w*h out.jpg  
  • ffmpeg -i output.png -s 960*540 output_change.png

4.3 分离视频的YUV通道分量

  • ffmpeg -i jack.mp4 -filter_complex "extractplanes=y+u+v[y][u][v]" -map "[y]" jack_y.mp4 -map "[u]" jack_u.mp4 -map "[v]" jack_v.mp4    
  • https://zh.wikipedia.org/zh-sg/YUV
chy-cpabe@ubuntu:~/Videos$ ffmpeg -i test.mp4 -filter_complex "extractplanes=y+u+v[y][u][v]" -map "[y]" out_y.mp4 -map "[u]" out_u.mp4 -map "[v]" out_v.mp4
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1mp42
    creation_time   : 2021-02-14T02:11:02.000000Z
  Duration: 00:00:23.36, start: 0.000000, bitrate: 6313 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 6147 kb/s, 23.98 fps, 23.98 tbr, 24k tbn (default)
    Metadata:
      creation_time   : 2021-02-14T02:11:02.000000Z
      handler_name    : ETI ISO Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Elemental H.264
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
      creation_time   : 2021-02-14T02:11:02.000000Z
      handler_name    : ETI ISO Audio Media Handler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (h264) -> extractplanes:default
  extractplanes -> Stream #0:0 (libx264)
  extractplanes -> Stream #1:0 (libx264)
  extractplanes -> Stream #2:0 (libx264)
Press [q] to stop, [?] for help
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284e9dc40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284eba2c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284ed4580] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284eee840] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284f08b00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284f22dc0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284f3d080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284f57340] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284e90c40] [swscaler @ 0x559284f72540] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559284f95b40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559284fafe00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559284fca0c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559284fe4380] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559284ffe640] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559285018900] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559285033b00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x55928504a140] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284f88b80] [swscaler @ 0x559285064400] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x55928508b680] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x5592850b4980] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x5592850dbe40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x5592850f3ec0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x559285123380] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x55928514a840] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x559285171d00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x559285189d80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55928507e6c0] [swscaler @ 0x5592851b9240] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284eb83c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f70680] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284ee6080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f55480] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f62440] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284eff1c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284e90c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f20f80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f2fd80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284eb83c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f70680] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284ee6080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f55480] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f62440] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284eff1c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284e90c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f20f80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f31bc0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284eb83c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f70680] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284ee6080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f55480] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f62440] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284eff1c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284e90c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f20f80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284ed2700] [swscaler @ 0x559284f2fd80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284fadf80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284fe2500] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285031c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284ff4f40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285001f00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285016ac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284f88b40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x5592850482c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285055280] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284fadf80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284fe2500] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285031c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284ff4f40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285001f00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285016ac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285023ac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284f8c840] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x5592850482c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284fadf80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284fe2500] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285031c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284ff4f40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285001f00] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285016ac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559285023ac0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x559284f8c840] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x559284fc8240] [swscaler @ 0x5592850482c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928515f080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285197340] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592851b5580] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592850bc280] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285175980] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592850da000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285091140] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285114380] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928513f580] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928515f080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285197340] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285150480] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592850b68c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285173c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592850da000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928507e4c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285094bc0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928512e880] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928515f080] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285197340] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285150480] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592850b68c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285173c40] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x5592850da000] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928507e4c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x559285094bc0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x5592851a8400] [swscaler @ 0x55928512e880] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x559283ebb640] using SAR=1/1
[libx264 @ 0x559283ebb640] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x559283ebb640] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x559283ebb640] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out_y.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1mp42
    encoder         : Lavf59.23.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuvj444p(pc, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 24k tbn
    Metadata:
      encoder         : Lavc59.27.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[libx264 @ 0x559283e909c0] using SAR=1/1
[libx264 @ 0x559283e909c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x559283e909c0] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 0x559283e909c0] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #1, mp4, to 'out_u.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1mp42
    encoder         : Lavf59.23.100
  Stream #1:0: Video: h264 (avc1 / 0x31637661), yuvj444p(pc, bt709, progressive), 960x540 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 24k tbn
    Metadata:
      encoder         : Lavc59.27.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[libx264 @ 0x559283ec5680] using SAR=1/1
[libx264 @ 0x559283ec5680] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x559283ec5680] profile High 4:4:4 Predictive, level 3.1, 4:4:4 8-bit
[libx264 @ 0x559283ec5680] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #2, mp4, to 'out_v.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1mp42
    encoder         : Lavf59.23.100
  Stream #2:0: Video: h264 (avc1 / 0x31637661), yuvj444p(pc, bt709, progressive), 960x540 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 24k tbn
    Metadata:
      encoder         : Lavc59.27.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame=  560 fps= 13 q=-1.0 Lq=-1.0 q=-1.0 size=   15581kB time=00:00:23.23 bitrate=5494.4kbits/s speed=0.556x    
video:17234kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x559283ebb640] frame I:3     Avg QP:20.11  size:127210
[libx264 @ 0x559283ebb640] frame P:204   Avg QP:22.05  size: 51523
[libx264 @ 0x559283ebb640] frame B:353   Avg QP:25.57  size: 14319
[libx264 @ 0x559283ebb640] consecutive B-frames:  3.2% 36.4%  5.4% 55.0%
[libx264 @ 0x559283ebb640] mb I  I16..4: 43.2%  0.0% 56.8%
[libx264 @ 0x559283ebb640] mb P  I16..4: 16.9%  0.0%  8.5%  P16..4: 39.6% 15.0%  5.4%  0.0%  0.0%    skip:14.6%
[libx264 @ 0x559283ebb640] mb B  I16..4:  1.7%  0.0%  0.7%  B16..8: 44.4%  5.9%  0.8%  direct: 2.2%  skip:44.2%  L0:43.1% L1:48.9% BI: 8.0%
[libx264 @ 0x559283ebb640] coded y,u,v intra: 28.8% 0.0% 0.0% inter: 14.0% 0.0% 0.0%
[libx264 @ 0x559283ebb640] i16 v,h,dc,p: 51% 24% 14% 11%
[libx264 @ 0x559283ebb640] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 18% 21%  5%  7%  5%  8%  4%  6%
[libx264 @ 0x559283ebb640] Weighted P-Frames: Y:5.4% UV:0.0%
[libx264 @ 0x559283ebb640] ref P L0: 65.1% 19.9% 10.6%  4.1%  0.3%
[libx264 @ 0x559283ebb640] ref B L0: 92.5%  6.0%  1.5%
[libx264 @ 0x559283ebb640] ref B L1: 98.6%  1.4%
[libx264 @ 0x559283ebb640] kb/s:5462.08
[libx264 @ 0x559283e909c0] frame I:13    Avg QP:12.93  size:  4437
[libx264 @ 0x559283e909c0] frame P:214   Avg QP:16.17  size:  2041
[libx264 @ 0x559283e909c0] frame B:333   Avg QP:16.81  size:   871
[libx264 @ 0x559283e909c0] consecutive B-frames:  3.2% 51.1%  4.3% 41.4%
[libx264 @ 0x559283e909c0] mb I  I16..4: 86.6%  0.0% 13.4%
[libx264 @ 0x559283e909c0] mb P  I16..4: 16.9%  0.0%  0.3%  P16..4: 24.3%  3.5%  1.7%  0.0%  0.0%    skip:53.3%
[libx264 @ 0x559283e909c0] mb B  I16..4:  0.4%  0.0%  0.0%  B16..8: 26.6%  1.8%  0.0%  direct: 0.1%  skip:71.0%  L0:44.5% L1:55.2% BI: 0.4%
[libx264 @ 0x559283e909c0] coded y,u,v intra: 1.9% 0.0% 0.0% inter: 0.9% 0.0% 0.0%
[libx264 @ 0x559283e909c0] i16 v,h,dc,p: 62% 23% 11%  4%
[libx264 @ 0x559283e909c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 38% 25% 33%  1%  1%  1%  1%  0%  0%
[libx264 @ 0x559283e909c0] Weighted P-Frames: Y:0.5% UV:0.0%
[libx264 @ 0x559283e909c0] ref P L0: 74.1%  3.1% 16.5%  6.2%  0.0%
[libx264 @ 0x559283e909c0] ref B L0: 88.4%  9.7%  1.9%
[libx264 @ 0x559283e909c0] ref B L1: 98.5%  1.5%
[libx264 @ 0x559283e909c0] kb/s:268.71
[libx264 @ 0x559283ec5680] frame I:12    Avg QP:13.33  size:  5060
[libx264 @ 0x559283ec5680] frame P:255   Avg QP:16.90  size:  2326
[libx264 @ 0x559283ec5680] frame B:293   Avg QP:17.38  size:   888
[libx264 @ 0x559283ec5680] consecutive B-frames:  3.9% 78.6%  1.1% 16.4%
[libx264 @ 0x559283ec5680] mb I  I16..4: 83.6%  0.0% 16.4%
[libx264 @ 0x559283ec5680] mb P  I16..4: 17.8%  0.0%  0.3%  P16..4: 26.9%  4.2%  2.1%  0.0%  0.0%    skip:48.6%
[libx264 @ 0x559283ec5680] mb B  I16..4:  0.3%  0.0%  0.0%  B16..8: 28.3%  1.9%  0.0%  direct: 0.1%  skip:69.3%  L0:40.1% L1:59.5% BI: 0.4%
[libx264 @ 0x559283ec5680] coded y,u,v intra: 1.9% 0.0% 0.0% inter: 1.4% 0.0% 0.0%
[libx264 @ 0x559283ec5680] i16 v,h,dc,p: 61% 23% 12%  4%
[libx264 @ 0x559283ec5680] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 38% 25% 34%  1%  1%  1%  1%  0%  0%
[libx264 @ 0x559283ec5680] Weighted P-Frames: Y:0.8% UV:0.0%
[libx264 @ 0x559283ec5680] ref P L0: 75.7%  4.3% 14.4%  5.5%  0.1%
[libx264 @ 0x559283ec5680] ref B L0: 88.6% 10.5%  0.9%
[libx264 @ 0x559283ec5680] ref B L1: 99.4%  0.6%
[libx264 @ 0x559283ec5680] kb/s:313.09

4.4 图片序列与视频的互相转换

  • ffmpeg -i %04d.jpg output.mp4     把0001.jpg、0002.jpg、0003.jpg等编码成output.mp4
  • ffmpeg -i input.mp4 %04d.jpg       把input.mp4变成0001.jpg等,%04d.jpg表示从1开始用0补全的4位整数为文件名的jpg文件序列

5,视频filter

5.1 视频加水印overlay

  • ffmpeg -i xizong.mp4 -i fleight.jpg -filter_complex "overlay=W-w-5:5" -codec:a copy xizong_fleight.mp4
  • 在右上角加水印,边距为5像素
  • 将一张图片作为水印 添加在 右上角

5.2 视频旋转transpose

  • 顺时针旋转90度
    • ffmpeg -i input -vf transpose=1 output
  • 顺时针旋转180度
    • ffmpeg -i in.mp4 -vf "transpose=1,transpose=1" out.mp4

5.3 调色3DLutFilter

  • 应用颜色查找表Lut,有‘nearest’、‘trilinear’、‘tetrahedral’三种插值算法
  • 命令行调用如下: ffmpeg -i log.mp4 -vf lut3d="file=DK79.cube"  out.mp4 
  • 存在问题 找不到 DK79.cube

5.4 图像/视频转换成黑白的

  • 图像转换成黑白的
    • ffmpeg -i sample.png -vf hue=s=0 output.png
  • 把视频转换为黑白的
    • ffmpeg -i julin_5s.mp4 -vf hue=s=0 -c:a copy julin_monochrome.mp4 

5.5 裁剪视频crop

  • 使用-crop选项,语法如下
  • crop=ow[:oh[:x[:y[:keep_aspect]]]]
    • ow、oh表示裁减之后输出视频的宽和高
    •  x、y表示在输入视频上开始裁减的横坐标和纵坐标
    • keep_aspect: 1表示保持裁剪后输出的纵横比与输入一致,0表示不保持
  • 裁剪输入视频的左三分之一
    • ffmpeg -i input -vf crop=iw/3:ih :0:0 output
  • 裁剪输入视频的中间三分之一
    • ffmpeg -i input -vf crop=iw/3:ih :iw/3:0 output
  • 裁剪输入视频的右三分之一:
    • ffmpeg -i input -vf crop=iw/3:ih :iw/3*2:0 output
  • 裁剪中间一半区域:
    • ffmpeg -i input -vf crop=iw/2:ih/2 output 

5.6 视频尺寸缩放scale

  • 将输入的1920*1080 缩小到 960*540 输出
  • ffmpeg -i input.mp4 -vf scale=960:540 output.mp4
  • 如果540不写,写成-1,即scale=960:-1, 那也是可以的,ffmpeg会通知缩放滤镜在输出时保持原始的宽高比。

5.7 视频中去水印delogo

  • 使用delogo filter
  • 它对logo周围像素的简单插值来实现。只需设置一个覆盖logo的矩形。在每个方向上,紧靠矩形外的下一个像素的值将用于计算矩形内的插值像素值。
  • 语法:-vf delogo=x:y:w:h[:t[:show]]
    • x:y 离左上角的坐标
    • w:h logo的宽和高
    • show:默认值0,若设置为1,指定区域的边界会绘制一个绿色的矩形框用于找到合适的x、y、w、h参数
  • 例子:ffmpeg -i pic_video.mp4 -filter_complex "delogo=x=1800:y=20:w=80:h=80:show=1" dellogo.mp4
  • 使用ffmpeg视频去水印__sleeping的博客-CSDN博客_ffmpeg去除视频水印

5.8 给视频或图像加上黑边pad

  • 比如一个输入视频尺寸是1280x534,想加上黑边变成1280x720,使用下面的命令可以实现
  • ffmpeg -i input.mp4 -vf pad=1280:720:0:93:black output.mp4
  • 按照从左到右的顺序依次为:“宽”、“高”、“X坐标”和“Y坐标”,宽和高指的是输入视频尺寸(包含加黑边的尺寸),X、Y指的是视频所在位置
  •  默认是加黑色的边,black可以不写。 上面的命令中93是根据(720-534) / 2计算得到
  • 如果视频原始1920x800的话,完整的语法应该是
  •  ffmpeg -i input.mp4 -vf 'scale=1280:534,pad=1280:720:0:93:black' 先将视频缩小到1280x534,然后在加入黑边变成1280x720,将1280x534的视频放置在x=0,y=93的地方。
  • 例子:ffmpeg -i pic_video.mp4 -vf 'scale=1280:534,pad=1280:720:0:93:red' red_dellogo.mp4 

5.9 计算psnr/ssim

  • 分析 psnr 主要是针对转码前的视频和转码后的视频的对比
  • 如果转码是降分辨率,对比的时候,还需要对源视频加 -s widthxhigh,保证分辨率一致再做 psnr 和 ssim 的计算
  • psnr
  • ffmpeg -i src.mp4  -i dst.mp4  -lavfi psnr="stats_file=psnr.log" -f null -
  • ssim
  • ffmpeg -i src.mp4  -i dst.mp4  -lavfi ssim="stats_file=ssim.log" -f null -
  • 同时计算psnr和ssim
  • ffmpeg -i main.mpg -i ref.mpg -lavfi  "ssim;[0:v][1:v]psnr" -f null - 

实际操作

  • 计算psnr和ssim主要目的是  视频转码前后的对比
  • 因此,第一步  将avi格式的视频转换为MP4格式的视频
  • ffmpeg -i test_avi.avi -c:a copy -c:v copy avi_2_mp4.mp4
  • 计算 psnr
  • ffmpeg -i test_avi.avi -i avi_2_mp4.mp4 -lavfi psnr="stats_file=psnr.log" -f null -
chy-cpabe@ubuntu:~/Videos$ ffmpeg -i test_avi.avi -i avi_2_mp4.mp4 -lavfi psnr="stats_file=psnr.log" -f null -
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, avi, from 'test_avi.avi':
  Metadata:
    software        : Lavf54.59.106
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1640 kb/s
  Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1501 kb/s, 24 fps, 24 tbr, 24 tbn
  Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 128 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'avi_2_mp4.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.23.100
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1632 kb/s
  Stream #1:0[0x1](und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1500 kb/s, 24 fps, 24 tbr, 12288 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #1:1[0x2](und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (mpeg4) -> psnr (graph 0)
  Stream #1:0 (mpeg4) -> psnr (graph 0)
  psnr:default (graph 0) -> Stream #0:0 (wrapped_avframe)
  Stream #0:1 -> #0:1 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[Parsed_psnr_0 @ 0x55b9216da140] not matching timebases found between first input: 1/24 and second input 1/12288, results may be incorrect!
Output #0, null, to 'pipe:':
  Metadata:
    software        : Lavf54.59.106
    encoder         : Lavf59.23.100
  Stream #0:0: Video: wrapped_avframe, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 24 fps, 24 tbn
    Metadata:
      encoder         : Lavc59.27.100 wrapped_avframe
  Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.27.100 pcm_s16le
frame= 1082 fps=0.0 q=-0.0 Lsize=N/A time=00:00:45.12 bitrate=N/A speed=54.4x    
  • 计算 ssim
  • ffmpeg -i test_avi.avi -i avi_2_mp4.mp4 -lavfi ssim="stats_file=ssim.log" -f null -
chy-cpabe@ubuntu:~/Videos$ ffmpeg -i test_avi.avi -i avi_2_mp4.mp4 -lavfi ssim="stats_file=ssim.log" -f null -
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, avi, from 'test_avi.avi':
  Metadata:
    software        : Lavf54.59.106
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1640 kb/s
  Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1501 kb/s, 24 fps, 24 tbr, 24 tbn
  Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 128 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'avi_2_mp4.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.23.100
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1632 kb/s
  Stream #1:0[0x1](und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1500 kb/s, 24 fps, 24 tbr, 12288 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #1:1[0x2](und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (mpeg4) -> ssim (graph 0)
  Stream #1:0 (mpeg4) -> ssim (graph 0)
  ssim:default (graph 0) -> Stream #0:0 (wrapped_avframe)
  Stream #0:1 -> #0:1 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[Parsed_ssim_0 @ 0x5588afcef640] not matching timebases found between first input: 1/24 and second input 1/12288, results may be incorrect!
Output #0, null, to 'pipe:':
  Metadata:
    software        : Lavf54.59.106
    encoder         : Lavf59.23.100
  Stream #0:0: Video: wrapped_avframe, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 24 fps, 24 tbn
    Metadata:
      encoder         : Lavc59.27.100 wrapped_avframe
  Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.27.100 pcm_s16le
frame= 1082 fps=0.0 q=-0.0 Lsize=N/A time=00:00:45.12 bitrate=N/A speed=  49x    
video:499kB audio:7758kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_ssim_0 @ 0x5588afcef640] SSIM Y:1.000000 (inf) U:1.000000 (inf) V:1.000000 (inf) All:1.000000 (inf)
  •  同时计算 psnr 和 ssim
  • ffmpeg -i test_avi.avi -i avi_2_mp4.mp4 -lavfi "ssim;[0:v][1:v]psnr" -f null -
chy-cpabe@ubuntu:~/Videos$ ffmpeg -i test_avi.avi -i avi_2_mp4.mp4 -lavfi "ssim;[0:v][1:v]psnr" -f null -
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, avi, from 'test_avi.avi':
  Metadata:
    software        : Lavf54.59.106
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1640 kb/s
  Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1501 kb/s, 24 fps, 24 tbr, 24 tbn
  Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, fltp, 128 kb/s
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'avi_2_mp4.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf59.23.100
  Duration: 00:00:45.13, start: 0.000000, bitrate: 1632 kb/s
  Stream #1:0[0x1](und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 1500 kb/s, 24 fps, 24 tbr, 12288 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #1:1[0x2](und): Audio: mp3 (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (mpeg4) -> ssim (graph 0)
  Stream #0:0 (mpeg4) -> psnr (graph 0)
  Stream #1:0 (mpeg4) -> ssim (graph 0)
  Stream #1:0 (mpeg4) -> psnr (graph 0)
  ssim:default (graph 0) -> Stream #0:0 (wrapped_avframe)
  psnr:default (graph 0) -> Stream #0:1 (wrapped_avframe)
  Stream #0:1 -> #0:2 (mp3 (mp3float) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[Parsed_ssim_0 @ 0x564524f58100] not matching timebases found between first input: 1/24 and second input 1/12288, results may be incorrect!
[Parsed_psnr_1 @ 0x564524f58540] not matching timebases found between first input: 1/24 and second input 1/12288, results may be incorrect!
Output #0, null, to 'pipe:':
  Metadata:
    software        : Lavf54.59.106
    encoder         : Lavf59.23.100
  Stream #0:0: Video: wrapped_avframe, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 24 fps, 24 tbn (default)
    Metadata:
      encoder         : Lavc59.27.100 wrapped_avframe
  Stream #0:1: Video: wrapped_avframe, yuv420p(progressive), 480x360 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 24 fps, 24 tbn
    Metadata:
      encoder         : Lavc59.27.100 wrapped_avframe
  Stream #0:2: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
    Metadata:
      encoder         : Lavc59.27.100 pcm_s16le
frame= 1082 fps=855 q=-0.0 Lq=-0.0 size=N/A time=00:00:45.12 bitrate=N/A speed=35.7x    
video:997kB audio:7758kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_ssim_0 @ 0x564524f58100] SSIM Y:1.000000 (inf) U:1.000000 (inf) V:1.000000 (inf) All:1.000000 (inf)
[Parsed_psnr_1 @ 0x564524f58540] PSNR y:inf u:inf v:inf average:inf min:inf max:inf

5.10 视频按时间拼接

  • 使用 FFmpeg 的 concat工具 进行多个视频的拼接
  • 首先创建一个文本文件,包含需要拼接的文件的列表

音视频处理 ffmpeg初级开发 命令行工具-实用命令_第2张图片

  • 命令:ffmpeg -f concat -i filelist.txt -c copy concat.mp4
  • 如果文件列表编码格式不一致,好像会出现问题

5.11 视频左右拼接

  • 命令
  • ffmpeg -ss 00:05:00 -i v1.mp4 -ss 00:05:00 -i v2.mp4 -filter_complex "[0:v]crop=iw/2:ih:0:0[v1];[1:v]crop=iw/2:ih:iw/2:0[v2];[v1][v2]hstack[v3];[v3]drawbox=iw/2-1:0:2:ih[v4]" -map [v4] -map 0:a -c:a copy -c:v libx264 -t 00:01:00 -y out.mp4

5.12 打印视频帧的一些信息showinfo

  • 命令 ffmpeg -hide_banner  -i  v.mp4 -vf showinfo -frames:v 1 -f null /dev/null
chy-cpabe@ubuntu:~/Videos$ ffmpeg -hide_banner -i merge_out.mp4 -vf showinfo -frames:v 1 -f null /dev/null 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'merge_out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.23.100
  Duration: 00:00:12.01, start: 0.000000, bitrate: 6159 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 5965 kb/s, 23.98 fps, 23.98 tbr, 24k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 159 kb/s (default)
    Metadata:
      handler_name    : ETI ISO Audio Media Handler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
  Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[Parsed_showinfo_0 @ 0x55e361c8ca80] config in time_base: 1/24000, frame_rate: 24000/1001
[Parsed_showinfo_0 @ 0x55e361c8ca80] config out time_base: 0/0, frame_rate: 0/0
[Parsed_showinfo_0 @ 0x55e361c8ca80] n:   0 pts:      0 pts_time:0       pos:    39765 fmt:yuv420p sar:1/1 s:1920x1080 i:P iskey:1 type:I checksum:E0A9A036 plane_checksum:[24B5FB04 BEEA8563 06F21FC0] mean:[150 131 117] stdev:[48.8 2.5 2.7]
[Parsed_showinfo_0 @ 0x55e361c8ca80]   side data - User Data Unregistered:
[Parsed_showinfo_0 @ 0x55e361c8ca80] UUID=dc45e9bd-e6d9-48b7-962c-d820d923eeef
[Parsed_showinfo_0 @ 0x55e361c8ca80] User Data=78323634202d20636f7265203135322072323835342065396135393033202d20482e3236342f4d5045472d342041564320636f646563202d20436f70796c65667420323030332d32303137202d20687474703a2f2f7777772e766964656f6c616e2e6f72672f783236342e68746d6c202d206f7074696f6e733a2063616261633d31207265663d33206465626c6f636b3d313a303a3020616e616c7973653d3078333a3078313133206d653d686578207375626d653d37207073793d31207073795f72643d312e30303a302e3030206d697865645f7265663d31206d655f72616e67653d3136206368726f6d615f6d653d31207472656c6c69733d31203878386463743d312063716d3d3020646561647a6f6e653d32312c313120666173745f70736b69703d31206368726f6d615f71705f6f66667365743d2d3220746872656164733d3132206c6f6f6b61686561645f746872656164733d3220736c696365645f746872656164733d30206e723d3020646563696d6174653d3120696e7465726c616365643d3020626c757261795f636f6d7061743d3020636f6e73747261696e65645f696e7472613d3020626672616d65733d3320625f707972616d69643d3220625f61646170743d3120625f626961733d30206469726563743d3120776569676874623d31206f70656e5f676f703d3020776569676874703d32206b6579696e743d323530206b6579696e745f6d696e3d3233207363656e656375743d343020696e7472615f726566726573683d302072635f6c6f6f6b61686561643d34302072633d637266206d62747265653d31206372663d32332e302071636f6d703d302e36302071706d696e3d302071706d61783d3639207170737465703d342069705f726174696f3d312e34302061713d313a312e303000
[Parsed_showinfo_0 @ 0x55e361c8ca80] 
[Parsed_showinfo_0 @ 0x55e361c8ca80] color_range:unknown color_space:unknown color_primaries:unknown color_trc:unknown
Output #0, null, to '/dev/null':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.23.100
  Stream #0:0(und): Video: wrapped_avframe, yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.27.100 wrapped_avframe
  Stream #0:1(und): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      handler_name    : ETI ISO Audio Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc59.27.100 pcm_s16le
[Parsed_showinfo_0 @ 0x55e361c8ca80] n:   1 pts:   1001 pts_time:0.0417083 pos:   226274 fmt:yuv420p sar:1/1 s:1920x1080 i:P iskey:0 type:B checksum:BEF57B91 plane_checksum:[90B31BAC 69027BD1 6593E405] mean:[149 131 117] stdev:[48.9 2.5 2.7]
[Parsed_showinfo_0 @ 0x55e361c8ca80] color_range:unknown color_space:unknown color_primaries:unknown color_trc:unknown
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.33 bitrate=N/A speed=3.57x    
video:0kB audio:63kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

5.13 生成纯色的图片

  • ffmpeg -f lavfi -i color=Black:640x480 -frames:v 1 -y black.jpg
  • FFmpeg Filters Documentation
chy-cpabe@ubuntu:~/Videos$ ffmpeg -f lavfi -i color=blue:1920*1080 -frames:v 1 -y blue.jpg
ffmpeg version N-106797-g580fb6a8c9 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, lavfi, from 'color=blue:1920*1080':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c59e32c0] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5a26680] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5a69600] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5aaa680] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5aed600] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5b30580] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5b71600] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5bb4580] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x55e4c59d5c40] [swscaler @ 0x55e4c5bf5600] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'blue.jpg':
  Metadata:
    encoder         : Lavf59.23.100
  Stream #0:0: Video: mjpeg, yuvj420p(pc, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn
    Metadata:
      encoder         : Lavc59.27.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
frame=    1 fps=0.0 q=2.2 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=1.62x    
video:12kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

5.14 打印帧序号/pts到视频帧水印drawtext

  • 打印帧序号                 缺乏msyh.ttf文件  无法执行
  • ffmpeg -i test.mp4 -vf drawtext=fontcolor=red:fontsize=40:fontfile=msyh.ttf:line_spacing=7:text=%{n}:x=50:y=50 -vsync 0  -y out.mp4
  • 打印帧pts                 缺乏msyh.ttf文件  无法执行
  • ffmpeg -i test.mp4 -vf drawtext=fontcolor=red:fontsize=30:fontfile=msyh.ttf:line_spacing=7:text=%{pts}:x=50:y=50  -vsync 0  -y out.mp4
  • 打印帧类型  ffmpeg -i test.mp4 -vf                 缺乏msyh.ttf文件  无法执行 drawtext=fontcolor=red:fontsize=20:fontfile=msyh.ttf:line_spacing=7:text=%{pict_type}:x=50:y=50 -vsync 0 -y out.mp4
  • 把视频的pts[时间戳]添加为视频水印,精度到毫秒   存在问题
  • ffmpeg -i test.mp4 -vf “drawtext=fontsize=60:text=’%{pts:hms}’” -c:v libx264 -c copy -f mp4 output.mp4 -y 
chy-cpabe@ubuntu:~/Videos$ ffmpeg -i test.mp4 -vf "drawtext=fontsize=60:text='%{pts:hms}'" -c:v libx264 -c:a copy -f mp4 out.mp4 
[Parsed_drawtext_0 @ 0x55c79b280d00] No font filename provided
[AVFilterGraph @ 0x55c79b27f9c0] Error initializing filter 'drawtext' with args 'fontsize=60:text=%{pts:hms}'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

6,音频解码编码     

PCM原始数据和WAV格式转换

  • wav格式转换为PCM裸流
  • ffmpeg -i xizong.wav -f f32le -ar 44100 -acodec pcm_f32le output_f32le.raw   
  • 参数说明:
    • -f f32le … 浮点数32为小字端的采样格式
    • -ar 44100 … 采样频率
    • -ac 2 … 声道数量
  • 使用命令 将 MP3格式的数据转化为 wav格式的数据
    • $ ffmpeg -i sample.mp3 -acodec pcm_s16le -ar 44100 sample.wav
    • audio - Convert mp3 to wav using FFmpeg for VBR - Super User

7,音频filter             

倍速atempo

  • 速度减半
    • ffmpeg -i input.mp3 -af atempo=0.5 output.mp3
  • 2倍速率
    • ffmpeg -i input.mp3 -af atempo=2 output.mp3

8,字幕相关

8.1 字幕文件转换

  • 字幕文件的类型有很多,常见的有 .srt 和 .ass文件等
//将.srt文件转换成.ass文件
ffmpeg -i subtitle.srt subtitle.ass

将.ass文件转换成.srt文件
ffmpeg -i subtitle.ass subtitle.srt

8.2 集成字幕到视频文件

  • ffmpeg -i input.mp4 -i subtitles.srt -c:s mov_text -c:v copy -c:a copy output.mp4
  • 出问题 

9,ffplay命令

9.1 ffplay播放yuv视频数据

ffplay -f <文件格式> -pix_fmt <像素格式> -video_size <视频尺寸> <文件名>
示例:
ffplay -f rawvideo -pix_fmt yuv420p -video_size 848x480 yuv_video
  • ffplay -f rawvideo  -pixel_format yuyv422 -video_size 848*480 test_YUV.yuv
  • ffplay 播放yuv视频_sunxiaopengsun的博客-CSDN博客_ffplay播放yuv 
  • ffmpeg mp4转yuv - zhaogaojian - 博客园

9.2 ffplay播放PCM音频数据

ffplay -f <格式名> -ac <声道数> -ar <采样率> <文件名>
示例:
ffplay -f f32le -ac 1 -ar 48000 pcm_audio
  • 例子   ffplay -f s16be -ac 1 -ar 16000 mp3_pcm.pcm 
  • 前提操作:MP3 转 PCM
    • 使用范例:
      • 大段数据格式 ffmpeg -i test.mp3 -f s16be -ar 16000 -ac 1 -acodec pcm_s16be pcm16k.pcm
      • 小端数据格式 ffmpeg -i test.mp3 -f s16le -ar 16000 -ac 1 -acodec pcm_s16le pcm16k.pcm
    • 说明:
      • -acodec pcm_s16be:输出pcm格式,采用signed 16编码,字节序为大尾端(小尾端为le)
      • -ar 16000: 采样率为16000
      • -ac 1: 声道数为1 
  • 例子 ffmpeg -i 漠河舞厅.mp3 -f s16be -ar 16000 -ac 1 -acodec pcm_s16be mp3_pcm.pcm
  • ffmpeg mp3转pcm指令_keepGoing_keepGoing的博客-CSDN博客_ffmpeg mp3转pcm

9.3 ffplay播放音频并显示波形图

  • ffplay -showmode 1 simple.mp4

音视频处理 ffmpeg初级开发 命令行工具-实用命令_第3张图片

9.4 ffplay指定显示宽高

  • ffplay -x 1208 -y 720 avi_2_mp4.mp4 

10,ffprobe命令

10.1 ffprobe查看媒体文件的信息

  • ffprobe target.mp4 -show_format -show_streams -print_format json -loglevel fatal
    • -print_format json: 结果以json格式呈现
    • -show_format: 打印封装格式信息,在format节点中
    •  -show_streams: 打印流信息,在streams节点中
chy-cpabe@ubuntu:~/Videos$ ffprobe test.mp4 -show_format -show_streams -print_format json -loglevel fatal
{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "High",
            "codec_type": "video",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1920,
            "height": 1080,
            "coded_width": 1920,
            "coded_height": 1080,
            "closed_captions": 0,
            "film_grain": 0,
            "has_b_frames": 1,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 40,
            "color_range": "tv",
            "color_space": "bt709",
            "color_transfer": "bt709",
            "color_primaries": "bt709",
            "chroma_location": "left",
            "field_order": "progressive",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "id": "0x1",
            "r_frame_rate": "24000/1001",
            "avg_frame_rate": "24000/1001",
            "time_base": "1/24000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 560560,
            "duration": "23.356667",
            "bit_rate": "6147092",
            "bits_per_raw_sample": "8",
            "nb_frames": "560",
            "extradata_size": 60,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "creation_time": "2021-02-14T02:11:02.000000Z",
                "language": "und",
                "handler_name": "ETI ISO Video Media Handler",
                "vendor_id": "[0][0][0][0]",
                "encoder": "Elemental H.264"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "id": "0x2",
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 1118656,
            "duration": "23.305333",
            "bit_rate": "160137",
            "nb_frames": "1094",
            "extradata_size": 2,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "creation_time": "2021-02-14T02:11:02.000000Z",
                "language": "und",
                "handler_name": "ETI ISO Audio Media Handler",
                "vendor_id": "[0][0][0][0]"
            }
        }
    ],
    "format": {
        "filename": "test.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "23.356667",
        "size": "18431676",
        "bit_rate": "6313118",
        "probe_score": 100,
        "tags": {
            "major_brand": "M4V ",
            "minor_version": "1",
            "compatible_brands": "isomavc1mp42",
            "creation_time": "2021-02-14T02:11:02.000000Z"
        }
    }
}

10.2 ffprobe查看时间戳

  • 首先,将MP4视频数据转化为 ts数据
  • ffmpeg -i input.mp4 output.ts
  • 查看视频dts
ffprobe -show_packets -select_streams v 1.ts | grep dts_time
chy-cpabe@ubuntu:~/Videos$ ffprobe -show_packets -select_streams v test_ts.ts | grep dts_time
ffprobe version N-106797-g580fb6a8c9 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, mpegts, from 'test_ts.ts':
  Duration: 00:00:23.37, start: 1.431689, bitrate: 3724 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
  Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
  Stream #0:1[0x101](und): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 384 kb/s
dts_time=1.400000
dts_time=1.441711
dts_time=1.483422
dts_time=1.525133
dts_time=1.566833
dts_time=1.608544
dts_time=1.650256
dts_time=1.691967
dts_time=1.733667
dts_time=1.775378
dts_time=1.817089
dts_time=1.858800
dts_time=1.900500
dts_time=1.942211
dts_time=1.983922
dts_time=2.025633
dts_time=2.067333
dts_time=2.109044
dts_time=2.150756
dts_time=2.192467
dts_time=2.234167
dts_time=2.275878
dts_time=2.317589
dts_time=2.359300
dts_time=2.401000
dts_time=2.442711
dts_time=2.484422
dts_time=2.526133
dts_time=2.567833
dts_time=2.609544
dts_time=2.651256
dts_time=2.692967
dts_time=2.734667
dts_time=2.776378
dts_time=2.818089
dts_time=2.859800
dts_time=2.901500
dts_time=2.943211
dts_time=2.984922
dts_time=3.026633
dts_time=3.068333
dts_time=3.110044
dts_time=3.151756
dts_time=3.193467
dts_time=3.235167
dts_time=3.276878
dts_time=3.318589
dts_time=3.360300
dts_time=3.402000
dts_time=3.443711
dts_time=3.485422
dts_time=3.527133
dts_time=3.568833
dts_time=3.610544
dts_time=3.652256
dts_time=3.693967
dts_time=3.735667
dts_time=3.777378
dts_time=3.819089
dts_time=3.860800
dts_time=3.902500
dts_time=3.944211
dts_time=3.985922
dts_time=4.027633
dts_time=4.069333
dts_time=4.111044
dts_time=4.152756
dts_time=4.194467
dts_time=4.236167
dts_time=4.277878
dts_time=4.319589
dts_time=4.361300
dts_time=4.403000
dts_time=4.444711
dts_time=4.486422
dts_time=4.528133
dts_time=4.569833
dts_time=4.611544
dts_time=4.653256
dts_time=4.694967
dts_time=4.736667
dts_time=4.778378
dts_time=4.820089
dts_time=4.861800
dts_time=4.903500
dts_time=4.945211
dts_time=4.986922
dts_time=5.028633
dts_time=5.070333
dts_time=5.112044
dts_time=5.153756
dts_time=5.195467
dts_time=5.237167
dts_time=5.278878
dts_time=5.320589
dts_time=5.362300
dts_time=5.404000
dts_time=5.445711
dts_time=5.487422
dts_time=5.529133
dts_time=5.570833
dts_time=5.612544
dts_time=5.654256
dts_time=5.695967
dts_time=5.737667
dts_time=5.779378
dts_time=5.821089
dts_time=5.862800
dts_time=5.904500
dts_time=5.946211
dts_time=5.987922
dts_time=6.029633
dts_time=6.071333
dts_time=6.113044
dts_time=6.154756
dts_time=6.196467
dts_time=6.238167
dts_time=6.279878
dts_time=6.321589
dts_time=6.363300
dts_time=6.405000
dts_time=6.446711
dts_time=6.488422
dts_time=6.530133
dts_time=6.571833
dts_time=6.613544
dts_time=6.655256
dts_time=6.696967
dts_time=6.738667
dts_time=6.780378
dts_time=6.822089
dts_time=6.863800
dts_time=6.905500
dts_time=6.947211
dts_time=6.988922
dts_time=7.030633
dts_time=7.072333
dts_time=7.114044
dts_time=7.155756
dts_time=7.197467
dts_time=7.239167
dts_time=7.280878
dts_time=7.322589
dts_time=7.364300
dts_time=7.406000
dts_time=7.447711
dts_time=7.489422
dts_time=7.531133
dts_time=7.572833
dts_time=7.614544
dts_time=7.656256
dts_time=7.697967
dts_time=7.739667
dts_time=7.781378
dts_time=7.823089
dts_time=7.864800
dts_time=7.906500
dts_time=7.948211
dts_time=7.989922
dts_time=8.031633
dts_time=8.073333
dts_time=8.115044
dts_time=8.156756
dts_time=8.198467
dts_time=8.240167
dts_time=8.281878
dts_time=8.323589
dts_time=8.365300
dts_time=8.407000
dts_time=8.448711
dts_time=8.490422
dts_time=8.532133
dts_time=8.573833
dts_time=8.615544
dts_time=8.657256
dts_time=8.698967
dts_time=8.740667
dts_time=8.782378
dts_time=8.824089
dts_time=8.865800
dts_time=8.907500
dts_time=8.949211
dts_time=8.990922
dts_time=9.032633
dts_time=9.074333
dts_time=9.116044
dts_time=9.157756
dts_time=9.199467
dts_time=9.241167
dts_time=9.282878
dts_time=9.324589
dts_time=9.366300
dts_time=9.408000
dts_time=9.449711
dts_time=9.491422
dts_time=9.533133
dts_time=9.574833
dts_time=9.616544
dts_time=9.658256
dts_time=9.699967
dts_time=9.741667
dts_time=9.783378
dts_time=9.825089
dts_time=9.866800
dts_time=9.908500
dts_time=9.950211
dts_time=9.991922
dts_time=10.033633
dts_time=10.075333
dts_time=10.117044
dts_time=10.158756
dts_time=10.200467
dts_time=10.242167
dts_time=10.283878
dts_time=10.325589
dts_time=10.367300
dts_time=10.409000
dts_time=10.450711
dts_time=10.492422
dts_time=10.534133
dts_time=10.575833
dts_time=10.617544
dts_time=10.659256
dts_time=10.700967
dts_time=10.742667
dts_time=10.784378
dts_time=10.826089
dts_time=10.867800
dts_time=10.909500
dts_time=10.951211
dts_time=10.992922
dts_time=11.034633
dts_time=11.076333
dts_time=11.118044
dts_time=11.159756
dts_time=11.201467
dts_time=11.243167
dts_time=11.284878
dts_time=11.326589
dts_time=11.368300
dts_time=11.410000
dts_time=11.451711
dts_time=11.493422
dts_time=11.535133
dts_time=11.576833
dts_time=11.618544
dts_time=11.660256
dts_time=11.701967
dts_time=11.743667
dts_time=11.785378
dts_time=11.827089
dts_time=11.868800
dts_time=11.910500
dts_time=11.952211
dts_time=11.993922
dts_time=12.035633
dts_time=12.077333
dts_time=12.119044
dts_time=12.160756
dts_time=12.202467
dts_time=12.244167
dts_time=12.285878
dts_time=12.327589
dts_time=12.369300
dts_time=12.411000
dts_time=12.452711
dts_time=12.494422
dts_time=12.536133
dts_time=12.577833
dts_time=12.619544
dts_time=12.661256
dts_time=12.702967
dts_time=12.744667
dts_time=12.786378
dts_time=12.828089
dts_time=12.869800
dts_time=12.911500
dts_time=12.953211
dts_time=12.994922
dts_time=13.036633
dts_time=13.078333
dts_time=13.120044
dts_time=13.161756
dts_time=13.203467
dts_time=13.245167
dts_time=13.286878
dts_time=13.328589
dts_time=13.370300
dts_time=13.412000
dts_time=13.453711
dts_time=13.495422
dts_time=13.537133
dts_time=13.578833
dts_time=13.620544
dts_time=13.662256
dts_time=13.703967
dts_time=13.745667
dts_time=13.787378
dts_time=13.829089
dts_time=13.870800
dts_time=13.912500
dts_time=13.954211
dts_time=13.995922
dts_time=14.037633
dts_time=14.079333
dts_time=14.121044
dts_time=14.162756
dts_time=14.204467
dts_time=14.246167
dts_time=14.287878
dts_time=14.329589
dts_time=14.371300
dts_time=14.413000
dts_time=14.454711
dts_time=14.496422
dts_time=14.538133
dts_time=14.579833
dts_time=14.621544
dts_time=14.663256
dts_time=14.704967
dts_time=14.746667
dts_time=14.788378
dts_time=14.830089
dts_time=14.871800
dts_time=14.913500
dts_time=14.955211
dts_time=14.996922
dts_time=15.038633
dts_time=15.080333
dts_time=15.122044
dts_time=15.163756
dts_time=15.205467
dts_time=15.247167
dts_time=15.288878
dts_time=15.330589
dts_time=15.372300
dts_time=15.414000
dts_time=15.455711
dts_time=15.497422
dts_time=15.539133
dts_time=15.580833
dts_time=15.622544
dts_time=15.664256
dts_time=15.705967
dts_time=15.747667
dts_time=15.789378
dts_time=15.831089
dts_time=15.872800
dts_time=15.914500
dts_time=15.956211
dts_time=15.997922
dts_time=16.039633
dts_time=16.081333
dts_time=16.123044
dts_time=16.164756
dts_time=16.206467
dts_time=16.248167
dts_time=16.289878
dts_time=16.331589
dts_time=16.373300
dts_time=16.415000
dts_time=16.456711
dts_time=16.498422
dts_time=16.540133
dts_time=16.581833
dts_time=16.623544
dts_time=16.665256
dts_time=16.706967
dts_time=16.748667
dts_time=16.790378
dts_time=16.832089
dts_time=16.873800
dts_time=16.915500
dts_time=16.957211
dts_time=16.998922
dts_time=17.040633
dts_time=17.082333
dts_time=17.124044
dts_time=17.165756
dts_time=17.207467
dts_time=17.249167
dts_time=17.290878
dts_time=17.332589
dts_time=17.374300
dts_time=17.416000
dts_time=17.457711
dts_time=17.499422
dts_time=17.541133
dts_time=17.582833
dts_time=17.624544
dts_time=17.666256
dts_time=17.707967
dts_time=17.749667
dts_time=17.791378
dts_time=17.833089
dts_time=17.874800
dts_time=17.916500
dts_time=17.958211
dts_time=17.999922
dts_time=18.041633
dts_time=18.083333
dts_time=18.125044
dts_time=18.166756
dts_time=18.208467
dts_time=18.250167
dts_time=18.291878
dts_time=18.333589
dts_time=18.375300
dts_time=18.417000
dts_time=18.458711
dts_time=18.500422
dts_time=18.542133
dts_time=18.583833
dts_time=18.625544
dts_time=18.667256
dts_time=18.708967
dts_time=18.750667
dts_time=18.792378
dts_time=18.834089
dts_time=18.875800
dts_time=18.917500
dts_time=18.959211
dts_time=19.000922
dts_time=19.042633
dts_time=19.084333
dts_time=19.126044
dts_time=19.167756
dts_time=19.209467
dts_time=19.251167
dts_time=19.292878
dts_time=19.334589
dts_time=19.376300
dts_time=19.418000
dts_time=19.459711
dts_time=19.501422
dts_time=19.543133
dts_time=19.584833
dts_time=19.626544
dts_time=19.668256
dts_time=19.709967
dts_time=19.751667
dts_time=19.793378
dts_time=19.835089
dts_time=19.876800
dts_time=19.918500
dts_time=19.960211
dts_time=20.001922
dts_time=20.043633
dts_time=20.085333
dts_time=20.127044
dts_time=20.168756
dts_time=20.210467
dts_time=20.252167
dts_time=20.293878
dts_time=20.335589
dts_time=20.377300
dts_time=20.419000
dts_time=20.460711
dts_time=20.502422
dts_time=20.544133
dts_time=20.585833
dts_time=20.627544
dts_time=20.669256
dts_time=20.710967
dts_time=20.752667
dts_time=20.794378
dts_time=20.836089
dts_time=20.877800
dts_time=20.919500
dts_time=20.961211
dts_time=21.002922
dts_time=21.044633
dts_time=21.086333
dts_time=21.128044
dts_time=21.169756
dts_time=21.211467
dts_time=21.253167
dts_time=21.294878
dts_time=21.336589
dts_time=21.378300
dts_time=21.420000
dts_time=21.461711
dts_time=21.503422
dts_time=21.545133
dts_time=21.586833
dts_time=21.628544
dts_time=21.670256
dts_time=21.711967
dts_time=21.753667
dts_time=21.795378
dts_time=21.837089
dts_time=21.878800
dts_time=21.920500
dts_time=21.962211
dts_time=22.003922
dts_time=22.045633
dts_time=22.087333
dts_time=22.129044
dts_time=22.170756
dts_time=22.212467
dts_time=22.254167
dts_time=22.295878
dts_time=22.337589
dts_time=22.379300
dts_time=22.421000
dts_time=22.462711
dts_time=22.504422
dts_time=22.546133
dts_time=22.587833
dts_time=22.629544
dts_time=22.671256
dts_time=22.712967
dts_time=22.754667
dts_time=22.796378
dts_time=22.838089
dts_time=22.879800
dts_time=22.921500
dts_time=22.963211
dts_time=23.004922
dts_time=23.046633
dts_time=23.088333
dts_time=23.130044
dts_time=23.171756
dts_time=23.213467
dts_time=23.255167
dts_time=23.296878
dts_time=23.338589
dts_time=23.380300
dts_time=23.422000
dts_time=23.463711
dts_time=23.505422
dts_time=23.547133
dts_time=23.588833
dts_time=23.630544
dts_time=23.672256
dts_time=23.713967
dts_time=23.755667
dts_time=23.797378
dts_time=23.839089
dts_time=23.880800
dts_time=23.922500
dts_time=23.964211
dts_time=24.005922
dts_time=24.047633
dts_time=24.089333
dts_time=24.131044
dts_time=24.172756
dts_time=24.214467
dts_time=24.256167
dts_time=24.297878
dts_time=24.339589
dts_time=24.381300
dts_time=24.423000
dts_time=24.464711
dts_time=24.506422
dts_time=24.548133
dts_time=24.589833
dts_time=24.631544
dts_time=24.673256
dts_time=24.714967
  • 查看视频pts
ffprobe -show_packets -select_streams v 1.ts | grep pts_time
chy-cpabe@ubuntu:~/Videos$ ffprobe -show_packets -select_streams v test_ts.ts | grep pts_time
ffprobe version N-106797-g580fb6a8c9 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/chy-cpabe/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/chy-cpabe/ffmpeg_build/include --extra-ldflags=-L/home/chy-cpabe/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/home/chy-cpabe/bin --enable-gpl --enable-gnutls --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
  libavutil      57. 24.101 / 57. 24.101
  libavcodec     59. 27.100 / 59. 27.100
  libavformat    59. 23.100 / 59. 23.100
  libavdevice    59.  6.100 / 59.  6.100
  libavfilter     8. 37.100 /  8. 37.100
  libswscale      6.  6.100 /  6.  6.100
  libswresample   4.  6.100 /  4.  6.100
  libpostproc    56.  5.100 / 56.  5.100
Input #0, mpegts, from 'test_ts.ts':
  Duration: 00:00:23.37, start: 1.431689, bitrate: 3724 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
  Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 90k tbn
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
  Stream #0:1[0x101](und): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 384 kb/s
pts_time=1.441711
pts_time=1.483422
pts_time=1.525133
pts_time=1.566833
pts_time=1.608544
pts_time=1.650256
pts_time=1.691967
pts_time=1.733667
pts_time=1.775378
pts_time=1.817089
pts_time=1.858800
pts_time=1.900500
pts_time=1.942211
pts_time=1.983922
pts_time=2.025633
pts_time=2.067333
pts_time=2.109044
pts_time=2.150756
pts_time=2.192467
pts_time=2.234167
pts_time=2.275878
pts_time=2.317589
pts_time=2.359300
pts_time=2.401000
pts_time=2.442711
pts_time=2.484422
pts_time=2.526133
pts_time=2.567833
pts_time=2.609544
pts_time=2.651256
pts_time=2.692967
pts_time=2.734667
pts_time=2.776378
pts_time=2.818089
pts_time=2.859800
pts_time=2.901500
pts_time=2.943211
pts_time=2.984922
pts_time=3.026633
pts_time=3.068333
pts_time=3.110044
pts_time=3.151756
pts_time=3.193467
pts_time=3.235167
pts_time=3.276878
pts_time=3.318589
pts_time=3.360300
pts_time=3.402000
pts_time=3.443711
pts_time=3.485422
pts_time=3.527133
pts_time=3.568833
pts_time=3.610544
pts_time=3.652256
pts_time=3.693967
pts_time=3.735667
pts_time=3.777378
pts_time=3.819089
pts_time=3.860800
pts_time=3.902500
pts_time=3.944211
pts_time=3.985922
pts_time=4.027633
pts_time=4.069333
pts_time=4.111044
pts_time=4.152756
pts_time=4.194467
pts_time=4.236167
pts_time=4.277878
pts_time=4.319589
pts_time=4.361300
pts_time=4.403000
pts_time=4.444711
pts_time=4.486422
pts_time=4.528133
pts_time=4.569833
pts_time=4.611544
pts_time=4.653256
pts_time=4.694967
pts_time=4.736667
pts_time=4.778378
pts_time=4.820089
pts_time=4.861800
pts_time=4.903500
pts_time=4.945211
pts_time=4.986922
pts_time=5.028633
pts_time=5.070333
pts_time=5.112044
pts_time=5.153756
pts_time=5.195467
pts_time=5.237167
pts_time=5.278878
pts_time=5.320589
pts_time=5.362300
pts_time=5.404000
pts_time=5.445711
pts_time=5.487422
pts_time=5.529133
pts_time=5.570833
pts_time=5.612544
pts_time=5.654256
pts_time=5.695967
pts_time=5.737667
pts_time=5.779378
pts_time=5.821089
pts_time=5.862800
pts_time=5.904500
pts_time=5.946211
pts_time=5.987922
pts_time=6.029633
pts_time=6.071333
pts_time=6.113044
pts_time=6.154756
pts_time=6.196467
pts_time=6.238167
pts_time=6.279878
pts_time=6.321589
pts_time=6.363300
pts_time=6.405000
pts_time=6.446711
pts_time=6.488422
pts_time=6.530133
pts_time=6.571833
pts_time=6.613544
pts_time=6.655256
pts_time=6.696967
pts_time=6.738667
pts_time=6.780378
pts_time=6.822089
pts_time=6.863800
pts_time=6.905500
pts_time=6.947211
pts_time=6.988922
pts_time=7.030633
pts_time=7.072333
pts_time=7.114044
pts_time=7.155756
pts_time=7.197467
pts_time=7.239167
pts_time=7.280878
pts_time=7.322589
pts_time=7.364300
pts_time=7.406000
pts_time=7.447711
pts_time=7.489422
pts_time=7.531133
pts_time=7.572833
pts_time=7.614544
pts_time=7.656256
pts_time=7.697967
pts_time=7.739667
pts_time=7.781378
pts_time=7.823089
pts_time=7.864800
pts_time=7.906500
pts_time=7.948211
pts_time=7.989922
pts_time=8.031633
pts_time=8.073333
pts_time=8.115044
pts_time=8.156756
pts_time=8.198467
pts_time=8.240167
pts_time=8.281878
pts_time=8.323589
pts_time=8.365300
pts_time=8.407000
pts_time=8.448711
pts_time=8.490422
pts_time=8.532133
pts_time=8.573833
pts_time=8.615544
pts_time=8.657256
pts_time=8.698967
pts_time=8.740667
pts_time=8.782378
pts_time=8.824089
pts_time=8.865800
pts_time=8.907500
pts_time=8.949211
pts_time=8.990922
pts_time=9.032633
pts_time=9.074333
pts_time=9.116044
pts_time=9.157756
pts_time=9.199467
pts_time=9.241167
pts_time=9.282878
pts_time=9.324589
pts_time=9.366300
pts_time=9.408000
pts_time=9.449711
pts_time=9.491422
pts_time=9.533133
pts_time=9.574833
pts_time=9.616544
pts_time=9.658256
pts_time=9.699967
pts_time=9.741667
pts_time=9.783378
pts_time=9.825089
pts_time=9.866800
pts_time=9.908500
pts_time=9.950211
pts_time=9.991922
pts_time=10.033633
pts_time=10.075333
pts_time=10.117044
pts_time=10.158756
pts_time=10.200467
pts_time=10.242167
pts_time=10.283878
pts_time=10.325589
pts_time=10.367300
pts_time=10.409000
pts_time=10.450711
pts_time=10.492422
pts_time=10.534133
pts_time=10.575833
pts_time=10.617544
pts_time=10.659256
pts_time=10.700967
pts_time=10.742667
pts_time=10.784378
pts_time=10.826089
pts_time=10.867800
pts_time=10.909500
pts_time=10.951211
pts_time=10.992922
pts_time=11.034633
pts_time=11.076333
pts_time=11.118044
pts_time=11.159756
pts_time=11.201467
pts_time=11.243167
pts_time=11.284878
pts_time=11.326589
pts_time=11.368300
pts_time=11.410000
pts_time=11.451711
pts_time=11.493422
pts_time=11.535133
pts_time=11.576833
pts_time=11.618544
pts_time=11.660256
pts_time=11.701967
pts_time=11.743667
pts_time=11.785378
pts_time=11.827089
pts_time=11.868800
pts_time=11.910500
pts_time=11.952211
pts_time=11.993922
pts_time=12.035633
pts_time=12.077333
pts_time=12.119044
pts_time=12.160756
pts_time=12.202467
pts_time=12.244167
pts_time=12.285878
pts_time=12.327589
pts_time=12.369300
pts_time=12.411000
pts_time=12.452711
pts_time=12.494422
pts_time=12.536133
pts_time=12.577833
pts_time=12.619544
pts_time=12.661256
pts_time=12.702967
pts_time=12.744667
pts_time=12.786378
pts_time=12.828089
pts_time=12.869800
pts_time=12.911500
pts_time=12.953211
pts_time=12.994922
pts_time=13.036633
pts_time=13.078333
pts_time=13.120044
pts_time=13.161756
pts_time=13.203467
pts_time=13.245167
pts_time=13.286878
pts_time=13.328589
pts_time=13.370300
pts_time=13.412000
pts_time=13.453711
pts_time=13.495422
pts_time=13.537133
pts_time=13.578833
pts_time=13.620544
pts_time=13.662256
pts_time=13.703967
pts_time=13.745667
pts_time=13.787378
pts_time=13.829089
pts_time=13.870800
pts_time=13.912500
pts_time=13.954211
pts_time=13.995922
pts_time=14.037633
pts_time=14.079333
pts_time=14.121044
pts_time=14.162756
pts_time=14.204467
pts_time=14.246167
pts_time=14.287878
pts_time=14.329589
pts_time=14.371300
pts_time=14.413000
pts_time=14.454711
pts_time=14.496422
pts_time=14.538133
pts_time=14.579833
pts_time=14.621544
pts_time=14.663256
pts_time=14.704967
pts_time=14.746667
pts_time=14.788378
pts_time=14.830089
pts_time=14.871800
pts_time=14.913500
pts_time=14.955211
pts_time=14.996922
pts_time=15.038633
pts_time=15.080333
pts_time=15.122044
pts_time=15.163756
pts_time=15.205467
pts_time=15.247167
pts_time=15.288878
pts_time=15.330589
pts_time=15.372300
pts_time=15.414000
pts_time=15.455711
pts_time=15.497422
pts_time=15.539133
pts_time=15.580833
pts_time=15.622544
pts_time=15.664256
pts_time=15.705967
pts_time=15.747667
pts_time=15.789378
pts_time=15.831089
pts_time=15.872800
pts_time=15.914500
pts_time=15.956211
pts_time=15.997922
pts_time=16.039633
pts_time=16.081333
pts_time=16.123044
pts_time=16.164756
pts_time=16.206467
pts_time=16.248167
pts_time=16.289878
pts_time=16.331589
pts_time=16.373300
pts_time=16.415000
pts_time=16.456711
pts_time=16.498422
pts_time=16.540133
pts_time=16.581833
pts_time=16.623544
pts_time=16.665256
pts_time=16.706967
pts_time=16.748667
pts_time=16.790378
pts_time=16.832089
pts_time=16.873800
pts_time=16.915500
pts_time=16.957211
pts_time=16.998922
pts_time=17.040633
pts_time=17.082333
pts_time=17.124044
pts_time=17.165756
pts_time=17.207467
pts_time=17.249167
pts_time=17.290878
pts_time=17.332589
pts_time=17.374300
pts_time=17.416000
pts_time=17.457711
pts_time=17.499422
pts_time=17.541133
pts_time=17.582833
pts_time=17.624544
pts_time=17.666256
pts_time=17.707967
pts_time=17.749667
pts_time=17.791378
pts_time=17.833089
pts_time=17.874800
pts_time=17.916500
pts_time=17.958211
pts_time=17.999922
pts_time=18.041633
pts_time=18.083333
pts_time=18.125044
pts_time=18.166756
pts_time=18.208467
pts_time=18.250167
pts_time=18.291878
pts_time=18.333589
pts_time=18.375300
pts_time=18.417000
pts_time=18.458711
pts_time=18.500422
pts_time=18.542133
pts_time=18.583833
pts_time=18.625544
pts_time=18.667256
pts_time=18.708967
pts_time=18.750667
pts_time=18.792378
pts_time=18.834089
pts_time=18.875800
pts_time=18.917500
pts_time=18.959211
pts_time=19.000922
pts_time=19.042633
pts_time=19.084333
pts_time=19.126044
pts_time=19.167756
pts_time=19.209467
pts_time=19.251167
pts_time=19.292878
pts_time=19.334589
pts_time=19.376300
pts_time=19.418000
pts_time=19.459711
pts_time=19.501422
pts_time=19.543133
pts_time=19.584833
pts_time=19.626544
pts_time=19.668256
pts_time=19.709967
pts_time=19.751667
pts_time=19.793378
pts_time=19.835089
pts_time=19.876800
pts_time=19.918500
pts_time=19.960211
pts_time=20.001922
pts_time=20.043633
pts_time=20.085333
pts_time=20.127044
pts_time=20.168756
pts_time=20.210467
pts_time=20.252167
pts_time=20.293878
pts_time=20.335589
pts_time=20.377300
pts_time=20.419000
pts_time=20.460711
pts_time=20.502422
pts_time=20.544133
pts_time=20.585833
pts_time=20.627544
pts_time=20.669256
pts_time=20.710967
pts_time=20.752667
pts_time=20.794378
pts_time=20.836089
pts_time=20.877800
pts_time=20.919500
pts_time=20.961211
pts_time=21.002922
pts_time=21.044633
pts_time=21.086333
pts_time=21.128044
pts_time=21.169756
pts_time=21.211467
pts_time=21.253167
pts_time=21.294878
pts_time=21.336589
pts_time=21.378300
pts_time=21.420000
pts_time=21.461711
pts_time=21.503422
pts_time=21.545133
pts_time=21.586833
pts_time=21.628544
pts_time=21.670256
pts_time=21.711967
pts_time=21.753667
pts_time=21.795378
pts_time=21.837089
pts_time=21.878800
pts_time=21.920500
pts_time=21.962211
pts_time=22.003922
pts_time=22.045633
pts_time=22.087333
pts_time=22.129044
pts_time=22.170756
pts_time=22.212467
pts_time=22.254167
pts_time=22.295878
pts_time=22.337589
pts_time=22.379300
pts_time=22.421000
pts_time=22.462711
pts_time=22.504422
pts_time=22.546133
pts_time=22.587833
pts_time=22.629544
pts_time=22.671256
pts_time=22.712967
pts_time=22.754667
pts_time=22.796378
pts_time=22.838089
pts_time=22.879800
pts_time=22.921500
pts_time=22.963211
pts_time=23.004922
pts_time=23.046633
pts_time=23.088333
pts_time=23.130044
pts_time=23.171756
pts_time=23.213467
pts_time=23.255167
pts_time=23.296878
pts_time=23.338589
pts_time=23.380300
pts_time=23.422000
pts_time=23.463711
pts_time=23.505422
pts_time=23.547133
pts_time=23.588833
pts_time=23.630544
pts_time=23.672256
pts_time=23.713967
pts_time=23.755667
pts_time=23.797378
pts_time=23.839089
pts_time=23.880800
pts_time=23.922500
pts_time=23.964211
pts_time=24.005922
pts_time=24.047633
pts_time=24.089333
pts_time=24.131044
pts_time=24.172756
pts_time=24.214467
pts_time=24.256167
pts_time=24.297878
pts_time=24.339589
pts_time=24.381300
pts_time=24.423000
pts_time=24.464711
pts_time=24.506422
pts_time=24.548133
pts_time=24.589833
pts_time=24.631544
pts_time=24.673256
pts_time=24.714967
pts_time=24.756667
  • 查看视频流前几帧的pts
ffprobe -v error -of compact -read_intervals  %+#10 -show_packets -select_streams v 1.ts
chy-cpabe@ubuntu:~/Videos$ ffprobe -v error -of compact -read_intervals %+#10 -show_packets -select_streams v test_ts.ts 
packet|codec_type=video|stream_index=0|pts=129754|pts_time=1.441711|dts=126000|dts_time=1.400000|duration=3753|duration_time=0.041700|size=111660|pos=564|flags=K_|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=133508|pts_time=1.483422|dts=129754|dts_time=1.441711|duration=3753|duration_time=0.041700|size=146109|pos=114680|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=137262|pts_time=1.525133|dts=133508|dts_time=1.483422|duration=3753|duration_time=0.041700|size=108658|pos=266584|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=141015|pts_time=1.566833|dts=137262|dts_time=1.525133|duration=3753|duration_time=0.041700|size=56978|pos=378068|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=144769|pts_time=1.608544|dts=141015|dts_time=1.566833|duration=3753|duration_time=0.041700|size=32869|pos=438792|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=148523|pts_time=1.650256|dts=144769|dts_time=1.608544|duration=3753|duration_time=0.041700|size=20103|pos=474888|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=152277|pts_time=1.691967|dts=148523|dts_time=1.650256|duration=3753|duration_time=0.041700|size=16245|pos=498388|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=156030|pts_time=1.733667|dts=152277|dts_time=1.691967|duration=3753|duration_time=0.041700|size=9676|pos=517564|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=159784|pts_time=1.775378|dts=156030|dts_time=1.733667|duration=3753|duration_time=0.041700|size=7591|pos=529972|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224

packet|codec_type=video|stream_index=0|pts=163538|pts_time=1.817089|dts=159784|dts_time=1.775378|duration=3753|duration_time=0.041700|size=6535|pos=540688|flags=__|side_data|side_data_type=MPEGTS Stream ID|id=224
  •  查看关键帧的pts
ffprobe -v error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=print_section=0 input.mp4 | awk -F',' '/K/ {print $1}'
  • 查看关键帧 帧间 的间隔
./ffprobe -of compact -select_streams v -show_packets  'test.mp4'| grep K_ | awk 'BEGIN{FS="|";last=-1}{split($5,a,"="); if(last != -1) {print "Keframe pos: " a[2] ", Interval: " a[2]-last " seconds"} else {print "Keyframe: " a[2]}; last=a[2]}'

11,其他

11.1 ffmpeg或ffplay 打开 DEBUG 日志输出

  • ffplay -v debug $URL
  • API中开启debug日志
    • av_log_set_level(AV_LOG_DEBUG);

11.2 FFmpeg命令日志输出到文件

  • 执行ffmpeg或者ffprobe输出重定向到文件的时候发现文件是空的。 可以采用下面的方式。
  • ffprobe xxx > file 2>&1
  • shell输出分好多种,
  • 0表示键盘输出,1表示屏幕输出,2表示错误输出。
  • cmd > file,只是把屏幕输出重定向到文件中。
  • 调用ffmpeg相关命令,打印信息都被终端认为是错误输出,但是一般情况下这种信息也会输出到屏幕上,所以我们可以在屏幕上看到它。但是,当我们想重定向到文件中,却被系统认为是错误输出而忽略。
  • 2>&1表示错误输出重定向到屏幕输出。
  • &标明其后面跟的是一个文件描述符,而不是一个文件名。

11.3 打印支持DirectShow的设备列表

  • 打印支持DirectShow的设备列表
    • ffmpeg -list_devices true -f dshow -i dummy
  • 打开名称为“Lenovo EasyCamera”的摄像头
    • ffmpeg -f dshow -i video="Lenovo EasyCamera" 

你可能感兴趣的:(音视频)