raspberry安装ffmpeg以及扩展了解

ffmpeg

sudo apt-get install ffmpeg

简介

FFmpeg的名称来自MPEG视频编码标准,前面的“FF”代表“Fast Forward”,FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。可以轻易地实现多种视频格式之间的相互转换。

FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.

FFmpeg是领先的多媒体框架,能够解码,编码,转码,mux, demux,流,过滤和播放几乎任何人类和机器创造的东西。它支持很多格式mp4,mp3。它们是由某个标准委员会、社区或公司设计的。具有高度的可移植性:FFmpeg可以在各种构建环境、机器架构和配置下,在Linux、Mac OS X、Microsoft Windows、bsd、Solaris等上编译、运行并通过。

了解参数

1.容器/文件(Conainer/File):即特定格式的多媒体文件,比如mp4、flv、mkv等。

2.媒体流(Stream):表示时间轴上的一段连续数据,如一段声音数据、一段视频数据或一段字幕数据,可以是压缩的,也可以是非压缩的,压缩的数据需要关联特定的编解码器。

3.数据帧/数据包(Frame/Packet):通常,一个媒体流是由大量的数据帧组成的,对于压缩数据,帧对应着编解码器的最小处理单元,分属于不同媒体流的数据帧交错存储于容器之中。

一般情况下:

Frame对应压缩前的数据,Packet对应压缩后的数据。

4.编解码器(Codec):以帧为单位实现压缩数据和原始数据之间的相互转换的

5.复用(mux):把不同的流按照某种容器的规则放入容器,这种行为叫做复用(mux)

6.解复用(mux):把不同的流从某种容器中解析出来,这种行为叫做解复用(demux)

7. 码率和帧率是视频文件的最重要的基本特征,对于他们的特有设置会决定视频质量。如果我们知道码率和时长那么可以很容易计算出输出文件的大小。

8.帧率:帧率也叫帧频率,帧率是视频文件中每一秒的帧数,肉眼想看到连续移动图像至少需要15帧。

9.码率:比特率(也叫码率,数据率)是一个确定整体视频/音频质量的参数,秒为单位处理的位数,码率和视频质量成正比,在视频文件中中比特率用bps来表达。

FFMPEG命令入门到提高

复用
在这里插入图片描述

编解码器
在这里插入图片描述

音视频处理流程

在这里插入图片描述

使用ffmpeg

1.分离视频音频流

ffmpeg -i input_file -vcodec copy -an output_file_video  //分离视频流
ffmpeg -i input_file -acodec copy -vn output_file_audio  //分离音频流
2.视频解复用

ffmpeg –i test.mp4 –vcodec copy –an –f m4v test.264
ffmpeg –i test.avi –vcodec copy –an –f m4v test.264
3.视频转码

ffmpeg –i test.mp4 –vcodec h264 –s 352*278 –an –f m4v test.264              //转码为码流原始文件
ffmpeg –i test.mp4 –vcodec h264 –bf 0 –g 25 –s 352*278 –an –f m4v test.264  //转码为码流原始文件
ffmpeg –i test.avi -vcodec mpeg4 –vtag xvid –qsame test_xvid.avi            //转码为封装文件
//-bf B帧数目控制,-g 关键帧间隔控制,-s 分辨率控制
4.视频封装

ffmpeg –i video_file –i audio_file –vcodec copy –acodec copy output_file
5.视频剪切

ffmpeg –i test.avi –r 1 –f image2 image-%3d.jpeg        //提取图片
ffmpeg -ss 0:1:30 -t 0:0:20 -i input.avi -vcodec copy -acodec copy output.avi    //剪切视频
//-r 提取图像的频率,-ss 开始时间,-t 持续时间
6.视频录制

ffmpeg –i rtsp://192.168.3.205:5555/test –vcodec copy out.avi
7.YUV序列播放

ffplay -f rawvideo -video_size 1920x1080 input.yuv
8.YUV序列转AVI
ffmpeg –s w*h –pix_fmt yuv420p –i input.yuv –vcodec mpeg4 output.avi


ffplay

一般用来进行播放控制设置,.

FFplay is a very simple and portable media player using the FFmpeg libraries and the SDL library. It is mostly used as a testbed for the various FFmpeg APIs.

ffplay

播放控制

在这里插入图片描述

命令播放

播放本地文件
    ffplay -window_title “test time” -ss 2 -t 10 -autoexit test.mp4
    ffplay buweishui.mp3

播放网络流
    ffplay -window_title “rtmp stream” rtmp://202.69.69.180:443/webcast/bshdlive-pc

强制解码器
    mpeg4 解码器: ffplay -vcodec mpeg4 test.mp4
    h264 解码器: ffplay -vcodec h264 test.mp4

禁用音频或视频
    禁用音频: ffplay test.mp4 -an
    禁用视频: ffplay test.mp4 -vn

播放 YUV 数据
    ffplay -pixel_format yuv420p -video_size 320x240 -framerate 5 yuv420p_320x240.yuv

播放 RGB 数据
    ffplay -pixel_format rgb24 -video_size 320x240 -i rgb24_320x240.rgb
    ffplay -pixel_format rgb24 -video_size 320x240 -framerate 5 -i rgb24_320x240.rgb
    
  播放 PCM 数据
    ffplay -ar 48000 -ac 2 -f f32le 48000_2_f32le.pcm
    -ar set audio sampling rate (in Hz) (from 0 to INT_MAX) (default 0)
    -ac set number of audio channels (from 0 to INT_MAX) (default 0)

滤镜处理

视频旋转
    ffplay -i test.mp4 -vf transpose=1

视频反转
    ffplay test.mp4 -vf hflip
    ffplay test.mp4 -vf vflip

视频旋转和反转
    ffplay test.mp4 -vf hflip,transpose=1

音频变速播放
    ffplay -i test.mp4 -af atempo=2

视频变速播放
    ffplay -i test.mp4 -vf setpts=PTS/2

音视频同时变速
    ffplay -i test.mp4 -vf setpts =PTS/2 -af atempo =2

更多参考

参数选项

选项 说明
-x width 强制显示宽带。
-y height 强制显示高度。
-video_size size
帧尺寸 设置显示帧存储 WxH 格式 )),仅适用于类似
原始 YUV 等没有包含帧大小 WxH 的视频 。
比如
: ffplay pixel_format yuv420p video_size 320x240 framerate 5 yuv420p_320x240.yuv

-pixel_format format 格式设置像素格式。
-fs 以全屏模式启动。
-an 禁用音频(不播放声音)
-vn 禁用视频(不播放视频)
-sn 禁用字幕(不显示字幕)
-ss pos
根据设置的秒进行定位拖动,注意时间单位:比如 ‘55’ 55
seconds, ‘12:03:45’ ,12 hours, 03 minutes and 45 seconds, ‘23.189’ 23.189
second

-t duration 设置播放视频 音频长度,时间单位如 ss 选项
-bytes 按字节进行定位拖动( 0=off 1=on -1=auto )。
-seek_interval interval 自定义左 右键定位拖动间隔(以秒为单位),默认值为 10 秒
-nodisp 关闭图形化显示窗口,视频将不显示
-noborder 无边框窗口
-volume vol 设置起始音量 。音量范围 [0 ~100]
-f fmt 强制使用设置的格式进行解析。比如 f s16le
-window_title title 设置窗口标题(默认为输入文件名)
-loop number 设置播放循环次数
-showmode mode
设置显示模式,可用的模式值: 0 显示视频,
1 显示音频波形, 2 显示音频频谱。缺省为 0 ,如果视频不存在则自动选择 2

-vf filtergraph 设置视频滤镜
-af filtergraph 设置音频滤镜
-stats
打印多个回放统计信息,包括显示流持续时间,编解码器参数,
流中的当前位置,以及音频 视频同步差值。默认情况下处于启用状
态,要显式禁用它则需要指定 nostats 。。

-fast 非标准化规范的多媒体兼容优化。
-genpts 生成 pts 。
-sync type
同步类型 将主时钟设置为 audio type=audio video
type=video )或 external type= ext ),默认是 audio 为主时钟。

-ast audio_stream_specifier 指定音频流索引,比如 ast 3 ,播放流索引为 3 的音频流
-vst video_stream_specifier 指定视频流索引,比如 vst 4 ,播放流索引为 4 的视频流
-sst subtitle_stream_specifier 指定字幕流索引,比如 sst 5 ,播放流索引为 5 的字幕流
-autoexit 视频播放完毕后退出。
-exitonkeydown 键盘按下任何键退出播放
-exitonmousedown 鼠标按下任何键退出播放
-codec:media_specifier codec_name
强制使用设置的多媒体解码器,
media_specifier 可用值为 a (音频 v (视频)和 s 字幕。比如
codec:v h264_qsv 强制视频采用 h264_qsv 解码

-acodec codec_name 强制使用设置的音频解码器进行音频解码
-vcodec codec_name 强制使用设置的视频解码器进行视频解码
-scodec codec_name 强制使用设置的字幕解码器进行字幕解码
-autorotate 根据文件元数据自动旋转视频。值为 0 或 1 ,默认为 1 。
-framedrop
如果视频不同步则丢弃视频帧。当主时钟非视频时钟时
默认开启。若需禁用则使用 noframedrop

-infbuf
不限制输入缓冲区大小。尽可能快地从输入中读取尽可能多的数据。
播放实时流时默认启用,如果未及时读取数据,则可能会丢弃数据。此选项
将不限制缓冲区的大小。若需禁用则使用 noinfbuf

ffprobe

ffprobe主要用来查看多媒体文件的信息
可以查看log,查看每一个音频数据包含信息或者视频数据包信息,查看每一个流有多少帧以及每一个流有多少音视频包,查看视频像素点的格式等。
可使用 ffprobe --help了解更具体的信息。

ffprobe --help

ffprobe参考

ffprobe [options] [input_url]
-L 显示协议
-h/-?/-help/--help topic 帮助可以选择话题
-version 显示版本
-buildconf 展示编译配置选项
-formats 显示支持的编码
-muxers 展示支持的封装器
-demuxers 展示支持的解封装器
-devices 展示支持的设备
-codecs 展示支持的编码
-decoders 显示支持的解码器
-encoders 显示支持的编码器
-bsfs 显示支持的比特流过滤器
-protocols 展示支持的协议
-filters 展示支持的过滤器
-pix_fmts 显示支持的像素格式
-layouts 展示支持的声道格式
-sample_fmts 显示支持的采样格式
-colors 展示支持的颜色名称
-loglevel loglevel 设置日志级别
-v loglevel 设置日志级别
-report 生成报告
-max_alloc bytes 设置单个已分配块的最大大小
-cpuflags flags 指定cpu标志
-hide_banner hide_banner 不显示程序横幅
-sources device 列出源的输出设备
-sinks device 列出输出设备的接收器
-f format 指定格式
-unit 显示显示值的单位
-prefix 对显示的值使用SI前缀
-byte_binary_prefix 对字节单位使用二进制前缀
-sexagesimal 对时间单位使用六十进制格式 HOURS:MM:SS.MICROSECONDS 
-pretty 美化显示输出的值,让人可读
-print_format format 设置打印格式 (available formats are: default, compact, csv, flat, ini, json, xml)
-of format -print_format的编码
-select_streams stream_specifier 选择指定的stream
-sections 打印节结构和节信息,然后退出
-show_data 显示数据包信息
-show_data_hash 显示数据包hash值
-show_error 显示探测中的错误
-show_format 显示格式/容器信息
-show_frames 显示帧信息
-show_format_entry entry 显示格式/容器信息中的特定条目
-show_entries entry_list 显示一组指定的项
-show_log 显示log
-show_packets 显示packet信息
-show_programs  显示程序信息
-show_streams 显示stream的信息
-show_chapters 显示chapters的信息
-count_frames 每个stream中的帧数
-count_packets 每个stream中的包数量
-show_program_version ffprobe的版本
-show_library_versions 库的版本
-show_versions 程序和库的版本号
-show_pixel_formats 展示像素格式描述
-show_private_data 显示私有数据
-private 和显示私有数据一样
-bitexact 强制提取bit输出
-read_intervals read_intervals 设置读取间隔
-default 默认所有选项
-i input_file 读取指定文件
-print_filename print_file 重新显示输入的文件名
-find_stream_info 读取并解码流,用启发式方法填充缺失的信息

eg: -show_format
在这里插入图片描述
eg: ffprobe -show_streams D:\MediaResource\KarolGazdik.mp4 -print_format json

{
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\MediaResource\KarolGazdik.mp4':
  Metadata:
    major_brand     : 3gp5
    minor_version   : 0
    compatible_brands: 3gp5isom
    creation_time   : 2019-04-13T19:27:16.000000Z
  Duration: 00:00:09.28, start: 0.000000, bitrate: 12194 kb/s
    Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 12062 kb/s, 30.19 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2019-04-13T19:27:16.000000Z
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      creation_time   : 2019-04-13T19:27:16.000000Z
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Baseline",
            "codec_type": "video",
            "codec_time_base": "53/3200",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1920,
            "height": 1080,
            "coded_width": 1920,
            "coded_height": 1088,
            "closed_captions": 0,
            "has_b_frames": 0,
            "pix_fmt": "yuv420p",
            "level": 40,
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "30000/1001",
            "avg_frame_rate": "1600/53",
            "time_base": "1/90000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 834750,
            "duration": "9.275000",
            "bit_rate": "12062729",
            "bits_per_raw_sample": "8",
            "nb_frames": "280",
            "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
            },
            "tags": {
                "creation_time": "2019-04-13T19:27:16.000000Z",
                "language": "und"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 447488,
            "duration": "9.322667",
            "bit_rate": "125871",
            "max_bit_rate": "48000",
            "nb_frames": "437",
            "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
            },
            "tags": {
                "creation_time": "2019-04-13T19:27:16.000000Z",
                "language": "und"
            }
        }
    ]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

道阻且长,行则降至

无聊,打赏求刺激而已

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值