[总结]FFMPEG命令行工具之ffplay详解

ffplay为ffmpeg的简单可移植的播放器,但它不仅是播放器,它可以作为测试ffmpeg的codec引擎,format引擎,以及filter引擎的工具,并且也可以做可视化的媒体参数分析。此文将包含ffplay基本所有的命令

0 让我们从-h帮助命令开始,步步为营

ffplay -h > ffplay_help.txt

帮助命令完整输出包含约7300+行,因此我将命令输出重定向到ffplay_help.txt文件中。我们主要关注的是Main options和Advanced options部分

Simple media player
usage: ffplay [options] input_file

Main options:
-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
-colors             show available color names
-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
-sources device     list sources of the input device
-sinks device       list sinks of the output device
-x width            force displayed width                          
-y height           force displayed height
-s size             set frame size (WxH or abbreviation)
-fs                 force full screen
-an                 disable audio
-vn                 disable video
-sn                 disable subtitling
-ss pos             seek to a given position in seconds
-t duration         play  "duration" seconds of audio/video
-bytes val          seek by bytes 0=off 1=on -1=auto
-seek_interval seconds  set seek interval for left/right keys, in seconds
-nodisp             disable graphical display
-noborder           borderless window
-volume volume      set startup volume 0=min 100=max
-f fmt              force format
-window_title window title  set window title
-af filter_graph    set audio filters
-showmode mode      select show mode (0 = video, 1 = waves, 2 = RDFT)
-i input_file       read specified file
-codec decoder_name  force decoder
-autorotate         automatically rotate video

Advanced options:
-cpuflags flags     force specific cpu flags                      
-hide_banner hide_banner  do not show program banner
-ast stream_specifier  select desired audio stream
-vst stream_specifier  select desired video stream
-sst stream_specifier  select desired subtitle stream
-pix_fmt format     set pixel format
-stats              show status
-fast               non spec compliant optimizations
-genpts             generate pts
-drp                let decoder reorder pts 0=off 1=on -1=auto
-lowres             
-sync type          set audio-video sync. type (type=audio/video/ext)
-autoexit           exit at the end
-exitonkeydown      exit on key down
-exitonmousedown    exit on mouse down
-loop loop count    set number of times the playback shall be looped
-framedrop          drop frames when cpu is too slow
-infbuf             don't limit the input buffer size (useful with realtime streams)
-left x pos         set the x position for the left of the window
-top y pos          set the y position for the top of the window
-vf filter_graph    set video filters
-rdftspeed msecs    rdft speed
-default            generic catch all option
-acodec decoder_name  force audio decoder
-scodec decoder_name  force subtitle decoder
-vcodec decoder_name  force video decoder
-find_stream_info   read and decode the streams to fill missing information with heuristics
-filter_threads     number of filter threads per graph

按照ffplay所以作用分为三部分来介绍上诉的命令:作为播放器进行视频播放;作为ffmpeg测试工具的测试功能;作为可视化媒体分析工具;Main options中前面大多数命令请查阅 [总结]FFMPEG命令行工具之ffprobe详解,此处不再重复说明。

作为本篇文章分析样本的媒体文件信息如下:

ffplay version N-93151-gff03418348 Copyright (c) 2003-2019 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20190212
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 47.102 / 58. 47.102
  libavformat    58. 26.101 / 58. 26.101
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2018-12-16T09:44:36.000000Z
  Duration: 00:25:53.41, start: 0.000000, bitrate: 269 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 170 kb/s, 29 fps, 29 tbr, 14848 tbn, 58 tbc (default)
    Metadata:
      creation_time   : 2018-12-16T09:44:36.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 12/16/2018.
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2018-12-16T09:44:36.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 12/16/2018.
  78.80 A-V: -0.013 fd=  13 aq=   16KB vq=   11KB sq=    0B f=0/0
PS E:\study\ffmpeg\builds\Static> ffprobe -show_streams .\1.mp4
ffprobe version N-93151-gff03418348 Copyright (c) 2007-2019 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20190212
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 47.102 / 58. 47.102
  libavformat    58. 26.101 / 58. 26.101
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '.\1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2018-12-16T09:44:36.000000Z
  Duration: 00:25:53.41, start: 0.000000, bitrate: 269 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 170 kb/s, 29 fps, 29 tbr, 14848 tbn, 58 tbc (default)
    Metadata:
      creation_time   : 2018-12-16T09:44:36.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 12/16/2018.
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2018-12-16T09:44:36.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 12/16/2018.
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=Main
codec_type=video
codec_time_base=1/58
codec_tag_string=avc1
codec_tag=0x31637661
width=1280
height=720
coded_width=1280
coded_height=720
has_b_frames=1
sample_aspect_ratio=1:1
display_aspect_ratio=16:9
pix_fmt=yuv420p
level=31
color_range=tv
color_space=bt709
color_transfer=bt709
color_primaries=bt709
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=29/1
avg_frame_rate=29/1
time_base=1/14848
start_pts=0
start_time=0.000000
duration_ts=23065088
duration=1553.413793
bit_rate=170245
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=45049
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:creation_time=2018-12-16T09:44:36.000000Z
TAG:language=und
TAG:handler_name=ISO Media file produced by Google Inc. Created on: 12/16/2018.
[/STREAM]
[STREAM]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
profile=LC
codec_type=audio
codec_time_base=1/44100
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=44100
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/44100
start_pts=0
start_time=0.000000
duration_ts=68505600
duration=1553.414966
bit_rate=96000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=66900
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:creation_time=2018-12-16T09:44:36.000000Z
TAG:language=eng
TAG:handler_name=ISO Media file produced by Google Inc. Created on: 12/16/2018.
[/STREAM]

1 视频播放功能相关参数介绍

1.1  设置播放界面大小相关参数

1.1.1 -x width          :force displayed width 

     由上文交代的媒体文件信息得知,原始的视频宽度为1280个像素。那么我们尝试分别将width设置为500 1280 1500,看将会发生什么事情,视频将如何被展示:

ffplay -i 1.mp4 -x 500                                                                 

ffplay -i 1.mp4 -x 1280 

ffplay -i 1.mp4 -x 1500

我们发现,在只设置宽度的情况下,视频宽度按照设置大小显示,视频也将进行相应的缩放,保持DAR 16:9的宽高比显示。

1.1.2 -y height          :force displayed height

按照-x参数的逻辑,在只设置-y参数的情况下,分别设置-y参数为500,720,900,得出的结论与1.1.1是类似的,所以此处不再将同样效果的图片贴出,节省空间。

注意:在这儿尝试下将-x -y同时设置看看将输出什么效果的图像

测试参数:宽高比大于原始宽高比,宽高比等于原始宽高比,宽高比小于原始宽高比。

ffplay  -i 1.mp4 -x 1000 -y 300 -window_title "1000x300"                 

                          

ffplay - i 1.mp4 -x 640 -y 360 -window_title "640x360"

ffplay - i 1.mp4 -x 640 -y 500 -window_title "640x500"

PS: 由本组测试数据可知窗体大小会按照-x -y指定大小显示,但是若二者之比与原始视频的宽高不成比例时,那么将出现左右,或者上下的黑边,中间的视频仍将按照DAR(display aspect ratio)所示比例正常显示。

1.1.3 -s size              : set frame size (WxH or abbreviation)

此命令时同时设置宽高,但是执行结果却让人感到意外,提示-s这个参数已经被弃用,请使用-video_size,紧接着又输出-vide_size参数不存在的消息。

但搜索ffplay -h输出可以找到-video_size,如下图所示:

于是我又执行ffplay -i 1.mp4 -video_size 1200x400,得到仍是无法找到-video_size。这是否是个bug?

1.1.4 -fs                 :force full screen 

视频窗口将按全屏显示,窗体的标题栏也将被隐藏,若是电脑显示器的纵横比和视频本身的DAR不一致时,窗体上也将出现黑边。本人电脑为16:9的显示器,测试媒体文件1.mp4的DAR也为16:9,因此全屏显示此视频不出现黑边。如下图所示

1.2  设置播放界面位置

1.2.1 -left x pos           :set the x position for the left of the window

设置播放器窗体在电脑屏幕的初始横坐标,单位为像素。
1.2.2 -top y pos           :set the y position for the top of the window

设置播放器窗体在电脑屏幕的初始纵坐标,单位为像素。

例: ffplay -i 1.mp4 -left 100 -top 100

播放器窗体初始显示位置,将是在距离屏幕左上角纵横都为100像素的地方显示。这儿其实没什么太多要讲的,其实就是控制一个窗体在电脑屏幕上的位置,在-left -top设置不同值时会导致窗体在屏幕上显示不全或者完全不在屏幕显示范围内的情况出现,做过界面开发的人都很容易理解,此处也就不再多做赘述。

2  测试功能相关参数介绍

3 可视化数据分析功能相关参数介绍

猜你喜欢

转载自blog.csdn.net/ice_ly000/article/details/87906003