======================

分为三部分:

1.ffmpeg介绍,及简单使用

2.ffprobe介绍,及简单使用

3.ffplay介绍,及简单使用

======================

在很多情况下转码使用的是ffmpeg。具体怎么操作,我们可以通过ffmpeg --help查看帮助文档来进行操作。

ffmpeg --help              //获得基础的帮助信息

ffmpeg --help  long    //获得高级参数部分

ffmpeg --help  full       //获得全部的帮助信息

usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
....
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
-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
-sources device     list sources of the input device
-sinks device       list sinks of the output device
-hwaccels           show available HW acceleration methods

ffmpeg --help  full

....

ffmpeg --help  long

....

ffmpeg的基本转码原理:

ffmpeg  -i output.avi -vcodec mpeg4 -b:v 200k -r 15 -an output.mp4ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developersbuilt with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-28)............libswresample   2.  0.101 /  2.  0.101libpostproc    54.  0.100 / 54.  0.100
Input #0, avi, from 'output.avi':Metadata:encoder         : Lavf57.25.100Duration: 00:15:09.06, start: 0.000000, bitrate: 402 kb/sStream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 1152x720 [SAR 1:1 DAR 8:5], 204 kb/s, 5 fps, 5 tbr, 5 tbn, 5 tbcStream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 44100 Hz, stereo, fltp, 192 kb/s
Output #0, mp4, to 'output.mp4':Metadata:encoder         : Lavf57.25.100Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1152x720 [SAR 1:1 DAR 8:5], q=2-31, 200 kb/s, 15 fps, 15360 tbn, 15 tbcMetadata:encoder         : Lavc57.24.102 mpeg4.......

从上面的信息可以看出:

1>转封装格式从AVI格式到MP4
2>视频编码是mpeg4,没变
3>视频的码率从204k专成了200k
4>视频的祯率从5fps转成了15fps
5>(-an)转码后没有了音频

整个流程依然是: 解封装->解码(音频,视频)->编码(音频,视频)->封装。

=======================================================================================

ffprobe多么媒体信息查看工具的介绍:

ffprobe --help查看相应的帮助信息。

usage: ffprobe [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
-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
-cpuflags flags     force specific cpu flags
-hide_banner hide_banner  do not show program banner
-sources device     list sources of the input device
-sinks device       list sinks of the output device
-f format           force format
-unit               show unit of the displayed values
-prefix             use SI prefixes for the displayed values
-byte_binary_prefix  use binary prefixes for byte units
-sexagesimal        use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units
-pretty             prettify the format of displayed values, make it more human readable
-print_format format  set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)
-of format          alias for -print_format
-select_streams stream_specifier  select the specified streams
-sections           print sections structure and section information, and exit
-show_data          show packets data
-show_data_hash     show packets data hash
-show_error         show probing error
-show_format        show format/container info
-show_frames        show frames info
-show_format_entry entry  show a particular entry from the format/container info
-show_entries entry_list  show a set of specified entries
-show_packets       show packets info
-show_programs      show programs info
-show_streams       show streams info
-show_chapters      show chapters info
-count_frames       count the number of frames per stream
-count_packets      count the number of packets per stream
-show_program_version  show ffprobe version
-show_library_versions  show library versions
-show_versions      show program and library versions
-show_pixel_formats  show pixel format descriptions
-show_private_data  show private data
-private            same as show_private_data
-bitexact           force bitexact output
-read_intervals read_intervals  set read intervals
-default            generic catch all option
-i input_file       read specified file

ffprobe -show_packets 111.mp4可以查看多媒体数据包信息:

[PACKET]           //为其中一个音频数据包的内容
codec_type=audio                            //codec_type  类型 :视频包,音频包
stream_index=1                              //stream索引
pts=40087459                                //pts   多媒体的显示时间
pts_time=909.012676
dts=40087459                                //dts 多媒体解码时间值
dts_time=909.012676                         //
duration=1024                               //多媒体包占用的时间
duration_time=0.023220
convergence_duration=N/A
convergence_duration_time=N/A
size=348                                    //size  多媒体包的大小
pos=31528832                                //pos   多媒体包杂文件偏移的位置
flags=K                                     //flags  多媒体包标记,如关键包与非关键包的标记
[/PACKET]
[PACKET]          //其中一个视频数据包
codec_type=video
stream_index=0
pts=4493000
pts_time=898.600000
dts=4493000
dts_time=898.600000
duration=1000
duration_time=0.200000
convergence_duration=N/A
convergence_duration_time=N/A
size=27135
pos=30760905
flags=_
[/PACKET]

ffprobe -show_data  -show_packets 111.mp4   可以查看包中的具体数据。

linux下查看十六进制数据:xxd 111.mp4

ffprobe -show_format 111.mp4 可以查看多媒体的封装格式,是使用FORMAT标签括起来的:

[FORMAT]
filename=111.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=909.038000                 //文件的总时长
size=31529180                       //文件的大小  字节
bit_rate=277472                     //文件的码率  bit/s
probe_score=100
TAG:major_brand=mp42
TAG:minor_version=0
TAG:compatible_brands=isommp42
TAG:creation_time=2015-05-05 19:37:53
TAG:artist=
TAG:description=
TAG:title=
[/FORMAT]

因此我们可以使用该命令查看比如flv  ,   wmv ,  avi等格式的封装数据。

ffprobe -show_frames  111.mp4 查看视频文件中的帧信息;FRAME标签括起来

[FRAME]
media_type=video
stream_index=0
key_frame=1                                //是否为关键帧
pkt_pts=4544000
pkt_pts_time=908.800000
pkt_dts=4544000
pkt_dts_time=908.800000
best_effort_timestamp=4544000
best_effort_timestamp_time=908.800000
pkt_duration=1000
pkt_duration_time=0.200000
pkt_pos=31454676
pkt_size=58465
width=1152
height=720
pix_fmt=yuv420p
sample_aspect_ratio=1:1
pict_type=I                                //帧的类型  I  ,P  ,B 帧
coded_picture_number=4544
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
[/FRAME]

ffprobe -show_streams  111.mp4 查看视频文件中的流信息;STREAM标签括起来

[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/10
codec_tag_string=avc1
codec_tag=0x31637661
width=1152
height=720
coded_width=1152
coded_height=720
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=8:5
pix_fmt=yuv420p
level=31
color_range=tv
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
timecode=N/A
refs=3
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=5/1
avg_frame_rate=5/1
time_base=1/5000
start_pts=0
start_time=0.000000
duration_ts=4545000
duration=909.000000
bit_rate=150173
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=4545
nb_read_frames=N/A
nb_read_packets=N/A
....
TAG:creation_time=2015-05-05 19:37:54
TAG:language=eng
TAG:handler_name=Mainconcept MP4 Video Media Handler
TAG:encoder=AVC Coding
[/STREAM]

另外介绍几个输出对应格式的指令:

ffprobe   -of   xml  -show_streams  111.mp4得到xml的输出格式

ffprobe   -of   ini  -show_streams  111.mp4 得到INI的格式输出

ffprobe   -of   flat -show_streams  111.mp4 得到FLAT的格式输出

ffprobe   -of  json  -show_streams  111.mp4 得到JSON的格式输出

ffprobe   -of  csv  -show_streams  111.mp4 得到CSV的格式输出,输出后可以使用对应软件绘制表格和相应的图形。

======================================================================================

ffplay工具常见使用方法介绍:

在编译ffpmpeg的时候,时需要SDL的,才能够使用ffplay。

ffplay的用途比较多,做视频播放器。做音视频的分析器的工具也很常见。

首先,通样是从帮助文档开始。ffplay --help

usage: ffplay [options] input_fileMain 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
-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
-nodisp             disable graphical display
-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 videoAdvanced 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)
-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

如一些简单的例子:

ffplay   -ss   30   -t   10   111.mp4

ffplay   -window_title "hello world"   111.mp4

ffplay   -window_title  "播放测试"   rtmp://https://v.youku.com/v_show/id_XMzcxMDMzNTY0MA==.html?from=miniplay-1.0.0&f=&firstTime=

ffplay高级参数,见上面表的:Advanced options,列举出的内容。

例如:

ffplay -vcodec h264 111.mp4     强制使用H.264解码MPEG4的视频等。

如果希望使用ffplay给视频加入字幕文件,你可以通过加载ASS或者SRT字幕文件来实现。比如,以SRT的字幕来实验。

1.我们首先需要编辑SRT字幕文件:

1
00:00:01.000--> 00:00:30.000
test by zhangsan2
00:00:30.001 --> 00:00:60.000
test by lisi3
00:01:01.000  --> 00:01:30.000
test by wangwu

2.通过filter将字幕加载到播放器数据中:

ffplay -window_title  "test_srt"  -vf  "subtitles=111.mp4.srt"   111.mp4

然后就可以播放了。

关于字幕部分,会用到--enable-libass,要在编译的时候需要libass这个库

可以参考这篇博客 https://blog.csdn.net/evsqiezi/article/details/52396986

外挂字幕与内嵌字幕

外挂字幕相对于内嵌字幕来说对视频的质量损害就会小很多,外挂的意思就是 在视频之外单独运行的一种字幕文件,对视频本身的分辨率损害很小甚至为零。而内嵌的字面意思就是将视频连带外挂字幕用专有的录制软件重新将视频录制一遍,成为一个新的视频;这种方法虽然解决了视频体积过大和播放器不兼容等问题,但是在重新录制视频过程当中会无意识的损害原视频本身的码率,使重新录制出来的 视频分辨率大大不如原视频,所以在选择外挂与内嵌字幕时需结合自身情况考虑视频需要进行选择。

//

ffplay -showmode 1 111.mp4

ffplay -vismv pf  111.mp4        查看B帧和P帧预测信息

ffmpeg工具的简单使用相关推荐

  1. 如何用FFmpeg编写一个简单播放器详细步骤介绍

    如何用FFmpeg编写一个简单播放器详细步骤介绍(转载) FFMPEG是一个很好的库,可以用来创建视频应用或者生成特定的工具.FFMPEG几乎为你把所有的繁重工作都做了,比如解码.编码.复用和解复用. ...

  2. Java 利用ffmpeg工具实现视频MP4转m3u8

    Java 利用ffmpeg工具实现视频MP4转m3u8(一) 前言 (一)ffmpeg工具转码 1.如何安装ffmpeg工具 2.如何使用ffmpeg工具进行视频转码 (二)播放m3u8文件 1.vi ...

  3. FFMpeg视频开发与应用基础——使用FFMpeg工具与SDK-殷汶杰-专题视频课程

    FFMpeg视频开发与应用基础--使用FFMpeg工具与SDK-41668人已学习 课程介绍         FFMpeg是当今为的面向音视频开发的开源工程,广泛应用于多种音视频的客户端.播放器和流媒 ...

  4. 02 ffmpeg工具详解【全】

    ffmpeg是FFmpeg源代码编译后生成的一个可执行程序,其可以作为命令行工具使用.它是一个非常全能的视频和音频处理器,可以对音视频进行编码.解码.转封装以及字幕处理等操作.其工作流程也非常简单: ...

  5. 【FFmpeg】ffmpeg工具源码分析(一):main函数

    ffmpeg工具经常用来转换.生成媒体文件,下面是它的源码分析(一):main函数 ffmpeg版本:4.2.1 int main(int argc, char **argv) {int i, ret ...

  6. 反编译工具jad简单用法

    反编译工具jad简单用法 下载地址: [url]http://58.251.57.206/down1?cid=B99584EFA6154A13E5C0B273C3876BD4CC8CE672& ...

  7. 【bat脚本】使用ffmpeg工具剥离某一个声道

    使用ffmpeg工具剥离某一个声道 @echo off set work_path=whole set human_path=left_channel :E :cd %work_path% : mkd ...

  8. 编程软件python图片-python Plotly绘图工具的简单使用

    1.plotly库的相关介绍 1)相关说明 plotly是一个基于javascript的绘图库,plotly绘图种类丰富,效果美观: 易于保存与分享plotly的绘图结果,并且可以与Web无缝集成: ...

  9. FFmpeg资料来源简单分析:libswscale的sws_getContext()

    ===================================================== FFmpeg库函数的源代码的分析文章: [骨架] FFmpeg源码结构图 - 解码 FFmp ...

最新文章

  1. IDEA函数调用关系图插件
  2. apache源码安装
  3. fastText中的子词嵌入和高效文本分类:简单高效性能好
  4. 【转】性能监控 -- 应用服务器常见监控指标
  5. spring aop execution表达式
  6. 缺省参数-缺省参数的注意事项
  7. Java8新特性--CompletableFuture
  8. python逻辑型数据也叫什么_Python入门 | 运算符和数据类型
  9. psycopg2.errors.UndefinedTable: relation “xxxx“ does not exist
  10. 【Hive】动态分区插入
  11. 什么是SQL Server GETDATE()函数?
  12. Maven 打包错误:%JAVA_HOME%/../lib/tools.jar
  13. Oracle v$sql,v$sqlarea,v$sqltext区别
  14. windows查看WIFI无线网络密码
  15. 堡垒机全称是什么?是运维安全审计系统吗?
  16. linux查找历史记录内容,linux中查看历史记录
  17. 基于2D多边形的碰撞检测和响应
  18. 2012, PPSN,Geometric Semantic Genetic Programming,GSGP
  19. Android开发的单词本APP项目介绍及源码(大作业)
  20. 污水处理常用指标、公式及水质标准

热门文章

  1. 科学家实现了通过意念同时控制两个假肢完成食物的切割和喂食
  2. .NET实现工资管理系统
  3. Linux内核相关论坛问题回复(1)
  4. 计算机的英语词汇牛津,牛津小学英语词汇表.PDF
  5. 一些前端开发实用的函数—1(jquery)
  6. (英文版)吴恩达机器学习第四周笔记
  7. J2EE与javaweb的区别
  8. 对Habit Browser浏览器网页翻译问题的凑合解决方法
  9. 机器学习(二)聚类的DBSCAN方法及学生上网聚类分析
  10. redo和undo 详解