• 正文
    • FFmpeg简介
    • FFmpeg命令行使用格式
  • 相关推荐
申请入驻 产业图谱

【平头哥Sipeed LicheeRV 86开发板试用】ffmpeg视频播放体验

01/24 15:02
1044
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

Tina系统镜像里已经编译了FFmpeg软件包,可以使用FFmpeg进行视频播放。如果自行编译话,用默认配置编译tina系统镜像也是有ffmpeg的。

下面我们简单了解一下ffmpeg

FFmpeg简介

FFmpeg(Fast Forward Mpeg)是一个强大的音视频,处理、推流、播放的开源软件。FFmpeg在Linux平台下开发,但它同样也可以在其它操作系统环境中编译运行,包括Windows、Mac OS X等。现在绝大多数音视频处理软件,播放器,摄像头推流,都是基于ffmpeg开发的。

FFmpeg命令行使用格式

FFmpeg 的命令行参数可以分成五个部:

$ ffmpeg {1} {2} -i {3} {4} {5}

  • 全局参数
  • 输入文件参数
  • 输入文件
  • 输出文件参数
  • 输出文件

先help 一下:

root@MaixLinux:/mnt/UDISK# ffmpeg -h
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8.1.0 (C-SKY RISCV Tools V1.8.4 B20200702)
configuration: --enable-cross-compile --cross-prefix=riscv64-unknown-linux-gnu- --arch=riscv --cpu=c910 --target-os=linux --prefix=/usr --pkg-config=pkg-config --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --enable-outdev=fbdev --enable-outdev=alsa --enable-outdev=v4l2 --disable-outdev=sdl2 --disable-x86asm --enable-small --enable-gpl --enable-libx264
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.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
-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 errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.
-bits_per_raw_sample number set the number of bits per raw sample
-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)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number set the number of bits per raw sample
-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

可以得知一些基本信息:

ffmpeg版本:

version 4.3.1

built with gcc版本:8.1.0 (C-SKY RISCV Tools V1.8.4 B20200702)
configuration平台库等信息:

平台 : 

--enable-cross-compile
--cross-prefix=riscv64-unknown-linux-gnu- --arch=riscv --cpu=c910
--target-os=linux --prefix=/usr --pkg-config=pkg-

config库:

--enable-shared --enable-static --enable-pthreads --enable-zlib
--disable-doc --disable-debug --disable-lzma --disable-vaapi
--disable-vdpau -

视频输出设备:

-enable-outdev=fbdev

音频输出设备:

--enable-outdev=alsa

支持解码格式:

--enable-outdev=v4l2 --disable-outdev=sdl2 --disable-x86asm --enable-small --enable-gpl --enable-libx264

FFmpeg命令行参数:

-c:指定编码器

-i :  输入音视源

-c copy:直接复制,不经过重新编码(这样比较快)

-c:v:指定视频编码器

-c:a:指定音频编码器

-i:指定输入文件

-an:去除音频流

-vn:去除视频流-vf :  视频滤镜

-pix_fmt : 视频格式

-preset:指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast, superfast, veryfast,

faster, fast, medium, slow, slower, veryslow。-y:

不经过确认,输出时直接覆盖同名文件。
..................

ffmpeg的东西太多了, 详细说明的,得写好几百篇稿, 也说不完

用到哪, 说到哪

播放一个视频试试吧

视频播放测试

播放例程所用的BadApple测试视频

播放一个视频试试吧

传视频到开发板

scp badapple_480360_xvid.mp4 root@192.168.0.20:/mnt/UDISK

注未扩容的,用不到上面空间, 可以用wget, 在网上找到视频下载

扩容方法,上几节有讲

【平头哥Sipeed LicheeRV 86开发板试用】SD卡中Linux系统根root分区扩容

【平头哥Sipeed LicheeRV 86开发板试用】扩展外部sd卡存储找到失去空间

播放视频

ffmpeg -i badapple_480360_xvid.mp4 -pix_fmt bgra -f fbdev /dev/fb0 -f alsa hw:0,0

发现播放效果不好看好,可不可以使画面居中一下,上下可以留黑边,这里用到pad参数填充,(发现一下算法视频播放就会变卡):

ffmpeg -i badapple_480360_xvid.mp4 -pix_fmt bgra -vf pad='w=480:h=480:x=(ow-iw)/2:y=(oh-ih)/2' -f fbdev /dev/fb0 -f alsa hw:0,0

再一个小(大)一点的视频试试

ffmpeg -i mov_bbb.mp4 -pix_fmt bgra -f fbdev /dev/fb0 -f alsa hw:0,0

用上面方法居中一下

ffmpeg -i mov_bbb.mp4 -pix_fmt bgra -vf 'pad=480:480:0:(oh-ih)/2' -f fbdev /dev/fb0 -f alsa hw:0,0

效果还是不好, 可以让它按屏宽度拉伸一下,并居中呢

用参数scale=480:-1,   宽度480, 高度按比例缩放,试试下面命令:

ffmpeg -i mov_bbb.mp4 -pix_fmt bgra -vf 'scale=480:-1, pad=480:480:0:(oh-ih)/2' -f fbdev /dev/fb0 -f alsa hw:0,0

这样理想了。

播放自制的视频

比较大的在上面播放比较卡,可以用ffmpeg, l转码,缩小一些

宽度固定转文件

ffmpeg -i /mnt/UDISK/jueju.mp4  -preset ultrafast -pix_fmt bgra -vf 'scale = 480:-1' -f mp4 /mnt/UDISK/jju.mp4复制代码用转码文件播放出来,就不会卡,居中会卡

播放电视直播

找一个电视直播的视频源,板子连网之后可以查看电视直播:

ffmpeg -i http://183.207.249.6/PLTV/3/224/3221225534/index.m3u8 -pix_fmt bgra -vf 'scale = 480:-1, pad = 480:480:(ow-iw)/2:(oh-ih)/2' -f fbdev /dev/fb0 -f alsa hw:0,0

播放画面如下,虽然能播,但是画面非常的卡。

总结

上述我们体验了Sipeed LicheeRV86 Panel开发板使用FFmpeg进行视频播放和视频处理(转码)的能力,对于播放480x480以下的视频,画面和声音都比较流程,转码非常慢,如果使用了FFmpeg的缩放或填充算法,播放就会不同程度的变卡。D1的解码及流处理能力相对X86, ARMV7以上内核还是差不少的。

平头哥

平头哥

平头哥半导体有限公司于2018年9月宣布成立,是阿里巴巴集团的全资半导体芯片业务主体。平头哥拥有端云一体全栈产品系列,涵盖数据中心人工智能芯片、处理器IP授权等,实现芯片端到端设计链路全覆盖。

平头哥半导体有限公司于2018年9月宣布成立,是阿里巴巴集团的全资半导体芯片业务主体。平头哥拥有端云一体全栈产品系列,涵盖数据中心人工智能芯片、处理器IP授权等,实现芯片端到端设计链路全覆盖。收起

查看更多
点赞
收藏
评论
分享
加入交流群
举报

相关推荐

登录即可解锁
  • 海量技术文章
  • 设计资源下载
  • 产业链客户资源
  • 写文章/发需求
立即登录