音视频处理 ffmpeg初级开发 命令行工具-实用命令
Posted MY CUP OF TEA
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了音视频处理 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 <string> E..V....... Set the encoding preset (cf. x264 --fullhelp) (default "medium")
-tune <string> E..V....... Tune the encoding params (cf. x264 --fullhelp)
-profile <string> E..V....... Set profile restrictions (cf. x264 --fullhelp)
-fastfirstpass <boolean> E..V....... Use fast settings when encoding first pass (default true)
-level <string> E..V....... Specify level (as defined by Annex A)
-passlogfile <string> E..V....... Filename for 2 pass stats
-wpredp <string> E..V....... Weighted prediction for P-frames
-a53cc <boolean> E..V....... Use A53 Closed Captions (if available) (default true)
-x264opts <string> E..V....... x264 options
-crf <float> E..V....... Select the quality for constant quality mode (from -1 to FLT_MAX) (default -1)
-crf_max <float> E..V....... In CRF mode, prevents VBV from lowering quality beyond this point. (from -1 to FLT_MAX) (default -1)
-qp <int> E..V....... Constant quantization parameter rate control method (from -1 to INT_MAX) (default -1)
-aq-mode <int> 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 <float> E..V....... AQ strength. Reduces blocking and blurring in flat and textured areas. (from -1 to FLT_MAX) (default -1)
-psy <boolean> E..V....... Use psychovisual optimizations. (default auto)
-psy-rd <string> E..V....... Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.
-rc-lookahead <int> E..V....... Number of frames to look ahead for frametype and ratecontrol (from -1 to INT_MAX) (default -1)
-weightb <boolean> E..V....... Weighted prediction for B-frames. (default auto)
-weightp <int> 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 <boolean> E..V....... Calculate and print SSIM stats. (default auto)
-intra-refresh <boolean> E..V....... Use Periodic Intra Refresh instead of IDR frames. (default auto)
-bluray-compat <boolean> E..V....... Bluray compatibility workarounds. (default auto)
-b-bias <int> E..V....... Influences how often B-frames are used (from INT_MIN to INT_MAX) (default INT_MIN)
-b-pyramid <int> 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 <boolean> E..V....... One reference per partition, as opposed to one reference per macroblock (default auto)
-8x8dct <boolean> E..V....... High profile 8x8 transform. (default auto)
-fast-pskip <boolean> E..V....... (default auto)
-aud <boolean> E..V....... Use access unit delimiters. (default auto)
-mbtree <boolean> E..V....... Use macroblock tree ratecontrol. (default auto)
-deblock <string> E..V....... Loop filter parameters, in <alpha:beta> form.
-cplxblur <float> E..V....... Reduce fluctuations in QP (before curve compression) (from -1 to FLT_MAX) (default -1)
-partitions <string> E..V....... A comma-separated list of partitions to consider. Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all
-direct-pred <int> 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 <int> E..V....... Limit the size of each slice in bytes (from -1 to INT_MAX) (default -1)
-stats <string> E..V....... Filename for 2 pass stats
-nal-hrd <int> 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 <int> E..V....... AVC-Intra class 50/100/200/300/480 (from -1 to 480) (default -1)
-me_method <int> 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 <int> 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 <boolean> E..V....... If forcing keyframes, force them as IDR frames. (default false)
-coder <int> 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 <int> E..V....... Strategy to choose between I/P/B-frames (from -1 to 2) (default -1)
-chromaoffset <int> E..V....... QP difference between chroma and luma (from INT_MIN to INT_MAX) (default 0)
-sc_threshold <int> E..V....... Scene change threshold (from INT_MIN to INT_MAX) (default -1)
-noise_reduction <int> E..V....... Noise reduction (from INT_MIN to INT_MAX) (default -1)
-udu_sei <boolean> E..V....... Use user data unregistered SEI if available (default false)
-x264-params <dictionary> 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
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
- ffmpeg -i input-video -vn -c:a copy output-audio
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
- 同时分离音频和视频流
- 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
- ffmpeg -ss 5 -i input.mp4 -t 10 -c:v copy -c:a copy output.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 <input> -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命令查看图片信息 数据信息较少
- 包括:文件名,图像格式,图像大小,图像深度,颜色空间,文件大小,用户时间等,例如:
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] WeighteLinux下安装ffmpeg
ffmpeg是一个很强大的音视频处理工具,官网是:http://ffmpeg.org/ 官网介绍ffmpeg是:一个完整的、跨平台的解决方案,可以记录、转换和传输音频和视频。ffmpeg既可以播放视频,也提供命令行工具来处理视频,另外还有强大的视频处理库用于开发,下面是以Linux为例介绍ffmpeg的安装流程的简单的命令行对视频进行转码操作,是ffmpeg中最最简单的入门内容.
首先去官网下载源码包,这里下载的是最新的ffmpeg-3.3.1.tar.bz2,下载之后上传至Linux准备安装,首先解压安装包:
tar -xjvf ffmpeg-3.3.1.tar.bz2
cd ffmpeg-3.3.1/
如果现在直接执行configure配置的话,可能会报如下的错误:
错误的意思是 yasm/nasm 包不存在或者很旧,可以使用--disable-yasm禁用这个选项编译,yasm是一款汇编器,并且是完全重写了nasm的汇编环境,接收nasm和gas语法,支持x86和amd64指令集,所以这里安装一下yasm即可,下载地址是:http://yasm.tortall.net/Download.html 进入后下载1.3.0的源码包,执行下面命令安装:
tar -xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure
make
make install
编译参数都是默认的,直接安装到系统中即可,安装成功之后继续回到ffmpeg解压后的目录,执行下面命令编译并安装:
./configure --enable-shared --prefix=/monchickey/ffmpeg
make
make install
编译过程有点长,耐心等待完成之后执行 cd /monchickey/ffmpeg/ 进入安装目录,查看一下发现有bin,include,lib,share这4个目录,其中bin是ffmpeg主程序二进制目录,include是C/C++头文件目录,lib是编译好的库文件目录,share是文档目录,然后进入bin目录,执行 ./ffmpeg -version 查看当前版本的详细信息,默认情况下一般会报libavdevice.so.57: cannot open shared object file: No such file or directory,原因是lib目录未加载到链接到系统库中,系统ld目录列表在/etc/ld.so.conf中,打开文件会发现,里面引用了/etc/ld.so.conf.d/下面所有的.conf文件,比如mariadb-x86_64.conf我们只需要创建一个文件并写入lib路径即可,执行命令: vim /etc/ld.so.conf.d/ffmpeg.conf 然后添加一行内容: /monchickey/ffmpeg/lib 之后保存并退出,然后执行 ldconfig 使配置生效,现在再次执行 ./ffmpeg -version 显示就正常了
然后可以根据需要将bin目录添加至环境变量中以保证任何时候都能使用ffmpeg命令,下面测试一下对视频进行转码:
首先由一个avi格式的视频文件,大小是37M,现在使用ffmpeg转换为mp4格式,执行下面命令:
ffmpeg -i test.avi out.mp4
确认之后,看到屏幕滚动开始处理,大约半分钟之后视频就转换完毕了,转换后mp4视频大小是17M,具体可以下载下来看一下
现在ffmpeg安装和最简单的命令行视频转换就完成了,实际上ffmpeg命令行工具可以有很多参数不用编程就可以实现强大的功能,这个非常牛
以上是关于音视频处理 ffmpeg初级开发 命令行工具-实用命令的主要内容,如果未能解决你的问题,请参考以下文章
音视频开发FFmpeg适合新手入门,Linux OS 环境下 FFmpeg 操作指南
音视频开发FFmpeg适合新手入门,Linux OS 环境下 FFmpeg 操作指南