【平头哥Sipeed LicheeRV 86开发板试用】ffmpeg视频播放体验
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:指定编码器
-c copy:直接复制,不经过重新编码(这样比较快)
-c:v:指定视频编码器
-c:a:指定音频编码器-i:指定输入文件
-an:去除音频流
-vn: 去除视频流
-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, 在网上找到视频下载
播放视频
- ffmpeg -i /mnt/exUDISK/-pix_fmt bgra -f fbdev /dev/fb0 -f alsa hw:0,0
复制代码
发现播放效果不好看好,可不可以使画面居中一下,上下可以留黑边,这里用到pad参数填充,(发现一下算法视频播放就会变卡):
- ffmpeg -i /mnt/UDISK/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 LicheeRV 86 Panel开发板使用FFmpeg进行视频播放的能力,对于播放480x480以下的视频,画面和声音都比较流程,如果使用了FFmpeg的尺寸修改功能,或是从网络直播源播放视频,播放就会不同程度的变卡。
|