通过在 Ubuntu 14 上将 avconv 传输到 avplay 来播放 mp4 视频文件?

通过在 Ubuntu 14 上将 avconv 传输到 avplay 来播放 mp4 视频文件?

在 Ubuntu 14.04 上,有avconv/avplay而不是ffmpeg/ ffplay;版本是:

$ avconv -version
avconv version 11.3-6:11.3-1~trusty, Copyright (c) 2000-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
avconv 11.3-6:11.3-1~trusty
libavutil     54.  3. 0 / 54.  3. 0
libavcodec    56.  1. 0 / 56.  1. 0
libavformat   56.  1. 0 / 56.  1. 0
libavdevice   55.  0. 0 / 55.  0. 0
libavfilter    5.  0. 0 /  5.  0. 0
libavresample  2.  1. 0 /  2.  1. 0
libswscale     3.  0. 0 /  3.  0. 0

我想建立一个管道,将avconv要播放的输出通过管道传输出去avplay,这样我就可以检查我的avconv设置是否正确;不幸的是,我无法让任何这种管道工作。

我正在与small.mp4 示例 MP4 视频文件HTML5 的示例 WebM、Ogg 和 MP4 视频文件 | TechSlides;我也见过bash - 如何将 ffmpeg 的输出通过管道传输到 ffplay? - 超级用户

以下是我的尝试:

$ avconv -i small.mp4 - | avplay -
avconv version 11.3-6:11.3-1~trusty, Copyright (c) 2000-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
avplay version 11.3-6:11.3-1~trusty, Copyright (c) 2003-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 560x320, 465 kb/s, 30 fps, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0.1(eng): Audio: aac, 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
Unable to find a suitable output format for 'pipe:'
pipe:: Invalid data found when processing input

因此,我必须指定输出格式avconv,我们可以看到那些能够编码和解码的格式,如下所示:

$ avplay -formats | grep ' DE'
avplay version 11.3-6:11.3-1~trusty, Copyright (c) 2003-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
 DE ac3             raw AC-3
 DE adx             CRI ADX
 DE aiff            Audio IFF
 DE alaw            PCM A-law
 DE alsa            ALSA audio output
 DE amr             3GPP AMR
 DE asf             ASF (Advanced / Active Streaming Format)
 DE ass             SSA (SubStation Alpha) subtitle
 DE au              Sun AU
 DE avi             AVI (Audio Video Interleaved)
 DE cavsvideo       raw Chinese AVS (Audio Video Standard) video
 DE daud            D-Cinema audio
 DE dirac           raw Dirac
 DE dnxhd           raw DNxHD (SMPTE VC-3)
 DE dts             raw DTS
 DE dv              DV (Digital Video)
 DE eac3            raw E-AC-3
 DE f32be           PCM 32-bit floating-point big-endian
 DE f32le           PCM 32-bit floating-point little-endian
 DE f64be           PCM 64-bit floating-point big-endian
 DE f64le           PCM 64-bit floating-point little-endian
 DE ffmetadata      FFmpeg metadata in text
 DE filmstrip       Adobe Filmstrip
 DE flac            raw FLAC
 DE flv             FLV (Flash Video)
 DE g722            raw G.722
 DE gxf             GXF (General eXchange Format)
 DE h261            raw H.261
 DE h263            raw H.263
 DE h264            raw H.264 video
 DE hevc            raw HEVC video
 DE ilbc            iLBC storage
 DE image2          image2 sequence
 DE image2pipe      piped image2 sequence
 DE ivf             On2 IVF
 DE latm            LOAS/LATM
 DE m4v             raw MPEG-4 video
 DE mjpeg           raw MJPEG video
 DE mlp             raw MLP
 DE mmf             Yamaha SMAF
 DE mp3             MP3 (MPEG audio layer 3)
 DE mpeg            MPEG-1 Systems / MPEG program stream
 DE mpegts          MPEG-TS (MPEG-2 Transport Stream)
 DE mulaw           PCM mu-law
 DE mxf             MXF (Material eXchange Format)
 DE nut             NUT
 DE ogg             Ogg
 DE oma             Sony OpenMG audio
 DE oss             OSS (Open Sound System) playback
 DE rawvideo        raw video
 DE rm              RealMedia
 DE roq             raw id RoQ
 DE rso             Lego Mindstorms RSO
 DE rtp             RTP output
 DE rtsp            RTSP output
 DE s16be           PCM signed 16-bit big-endian
 DE s16le           PCM signed 16-bit little-endian
 DE s24be           PCM signed 24-bit big-endian
 DE s24le           PCM signed 24-bit little-endian
 DE s32be           PCM signed 32-bit big-endian
 DE s32le           PCM signed 32-bit little-endian
 DE s8              PCM signed 8-bit
 DE sap             SAP output
 DE smjpeg          Loki SDL MJPEG
 DE sox             SoX native
 DE spdif           IEC 61937 (used on S/PDIF - IEC958)
 DE srt             SubRip subtitle
 DE swf             SWF (ShockWave Flash)
 DE truehd          raw TrueHD
 DE u16be           PCM unsigned 16-bit big-endian
 DE u16le           PCM unsigned 16-bit little-endian
 DE u24be           PCM unsigned 24-bit big-endian
 DE u24le           PCM unsigned 24-bit little-endian
 DE u32be           PCM unsigned 32-bit big-endian
 DE u32le           PCM unsigned 32-bit little-endian
 DE u8              PCM unsigned 8-bit
 DE voc             Creative Voice
 DE wav             WAV / WAVE (Waveform Audio)
 DE wv              raw WavPack
 DE yuv4mpegpipe    YUV4MPEG pipe

让我们尝试 flv 格式 - 如果我只添加-f flv,那么我得到“flv 不支持该采样率,请从(44100、22050、11025)中选择。”;所以我还添加-ar 44100

$ avconv -i small.mp4 -f flv -ar 44100 - | avplay -
avconv version 11.3-6:11.3-1~trusty, Copyright (c) 2000-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
avplay version 11.3-6:11.3-1~trusty, Copyright (c) 2003-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 560x320, 465 kb/s, 30 fps, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0.1(eng): Audio: aac, 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
Output #0, flv, to 'pipe:':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : Lavf56.1.0
    Stream #0.0(und): Video: flv, yuv420p, 560x320, q=2-31, 200 kb/s, 1k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0.1(eng): Audio: libmp3lame, 44100 Hz, mono, fltp (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : Lavc56.1.0 libmp3lame
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> flv1 (flv))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press ctrl-c to stop encoding
[flv @ 0xaed026a0] max_analyze_duration 5000000 reached
Input #0, flv, from 'pipe:':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : Lavf56.1.0
  Duration: 00:00:00.00, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: flv, yuv420p, 560x320, 200 kb/s, 30 fps, 1k tbn
    Stream #0.1: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
[flv @ 0x80c7d80] Failed to update header with correct duration.B f=0/0   
[flv @ 0x80c7d80] Failed to update header with correct filesize.
frame=  166 fps=  0 q=31.0 Lsize=     192kB time=5.50 bitrate= 285.5kbits/s    
video:141kB audio:44kB other streams:0kB global headers:0kB muxing overhead: 3.426657%
Segmentation fault (core dumped)

因此,发生了段错误崩溃 - 即使avplay据称正确读取了输入流的属性......

格式也会发生相同的段错误avi(如果我指定了格式也会发生avplay -f avi -):

$ avconv -i small.mp4 -f avi - | avplay -
avconv version 11.3-6:11.3-1~trusty, Copyright (c) 2000-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
avplay version 11.3-6:11.3-1~trusty, Copyright (c) 2003-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.56, start: 0.000000, bitrate: 551 kb/s
    Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 560x320, 465 kb/s, 30 fps, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0.1(eng): Audio: aac, 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
Output #0, avi, to 'pipe:':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20 21:29:11
    ISFT            : Lavf56.1.0
    Stream #0.0(und): Video: mpeg4, yuv420p, 560x320, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : JVT/AVC Coding
    Stream #0.1(eng): Audio: libmp3lame, 48000 Hz, mono, fltp (default)
    Metadata:
      creation_time   : 2010-03-20 21:29:11
      encoder         : Lavc56.1.0 libmp3lame
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press ctrl-c to stop encoding
Input #0, avi, from 'pipe:':
  Metadata:
    encoder         : Lavf56.1.0
  Duration: 9942:03:14.13, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: mpeg4 (Simple Profile), yuv420p, 560x320 [PAR 1:1 DAR 7:4], 30 fps, 30 tbn, 30 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, 1 channels, s16p, 64 kb/s
Segmentation fault (core dumped)0 aq=   17KB vq=  142KB sq=    0B f=0/0   

格式相同mpegts...

我最接近管道的是这个命令[FFmpeg-user] 录制时管道到 ffplay:语法

ffmpeg -f x11grab -r 10 -s 128x128  -i :0.0 -f rawvideo - | ffplay -f rawvideo -s 128x128 -pix_fmt bgr0 -

...但是,它不能真正“转换”为 av* 命令,因为特别是在这个版本中,因为:

Option 'pix_fmt' has been removed, use private format options instead
[rawvideo @ 0xaed026a0] No such pixel format: bgr0.
Option 's' has been removed, use private format options instead

...因此,此版本的 Ubuntu 中的命令将是:

$ avconv -f x11grab -r 10 -s 128x128  -i :0.0 -f rawvideo - | avplay -f rawvideo -pixel_format bgra -video_size 128x128 -
avconv version 11.3-6:11.3-1~trusty, Copyright (c) 2000-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
[x11grab @ 0x8270b80] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 128 height: 128
[x11grab @ 0x8270b80] shared memory extension  found
avplay version 11.3-6:11.3-1~trusty, Copyright (c) 2003-2014 the Libav developers
  built on Apr 13 2015 22:25:59 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
[x11grab @ 0x8270b80] Estimating duration from bitrate, this may be inaccurate
Input #0, x11grab, from ':0.0':
  Duration: N/A, start: 1516909239.674510, bitrate: 5242 kb/s
    Stream #0.0: Video: rawvideo, bgra, 128x128, 5242 kb/s, 10 fps, 1000k tbn, 10 tbc
Output #0, rawvideo, to 'pipe:':
  Metadata:
    encoder         : Lavf56.1.0
    Stream #0.0: Video: rawvideo, bgra, 128x128, q=2-31, 200 kb/s, 10 tbn, 10 tbc
    Metadata:
      encoder         : Lavc56.1.0 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press ctrl-c to stop encoding
[rawvideo @ 0xaed026a0] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: rawvideo, bgra, 128x128, 25 fps, 25 tbn
^Cframe=  119 fps= 11 q=0.0 Lsize=    7616kB time=11.80 bitrate=5287.3kbits/s

...这是迄今为止我发现的唯一一个不会出现段错误并且能显示视频窗口的程序 - 但视频屏幕如下所示:

屏幕截图-管道.png

...也就是说,整个视频窗口/屏幕都是黑色的 - 除了左上角抖动的一些绿色像素......

还请注意,在这个版本中,pipe:1: Not yet implemented in Libav, patches welcome如果我尝试使用pipe:1而不是仅使用破折号-来表示 stdout/stdin,偶尔我会得到“ ”...

那么,是否可以在该版本的 Ubuntu 中设置一个从avconv到 的管道avplay,以便avplay至少播放 发送的视频(或者最好同时播放音频和视频)avconv——如果可以,如何操作?

答案1

好的,虽然取得了一些进展,但不是用内置的avconv/ avplay

我发现ffmpeg 输出设备 xv 全屏?:ffmpeg,使用以下命令:

ffmpeg -re -i "${infile}" -filter_complex "[0:v] scale=w=480:h=-1 [out0]" -map [out0] -f xv mywindowname

因此,有一些输出设备xv可以播放到窗口;avconv -devicesUnrecognized option 'devices'”(man说:“av* 工具的“-formats”选项将显示启用的输出设备列表(在多路复用器中)。”)。注意有FFmpeg 静态构建,但这些似乎并不包括该xv设备。

因此,我最终从 PPA 中使用它——这是如何做到的,以便它从外部位置运行:

sudo apt-get install ppa-purge

sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
apt-get install --simulate ffmpeg

apt-get download ffmpeg libass5 libfdk-aac1 libsdl2-2.0-0 libsoxr0 libva-drm1 libvidstab1.0 libx264-148 libx265-130 libzimg2

# libsoxr0 and libsdl2-2.0-0 are from trusty/universe; so:
rm libsoxr0_0.1.1-1_i386.deb libsdl2-2.0-0_2.0.2+dfsg1-3ubuntu1.2_i386.deb
sudo apt-get install libsoxr0 libsdl2-2.0-0

# unpack debs:
for ix in *.deb; do echo $ix; dpkg -x $ix .; done

sudo ppa-purge ppa:mc3man/trusty-media
sudo apt-get update

然后您可以得到如下脚本, (并为->run-ffmpeg.sh制作相同的脚本;记住它们两个):ffplatrun-ffplay.shchmod +x *.sh

#!/usr/bin/env bash
export LD_LIBRARY_PATH=$PWD/usr/lib/i386-linux-gnu
export PATH="$PATH":$PWD/opt/ffmpeg/bin
ffmpeg "$@"
#reset # deletes all output
stty echo # resets echo, OK

(请注意,使用此脚本会以某种方式搞乱终端回显,这是最后一个的原因stty echo

最后,X11 管道就可以工作了:

./run_ffmpeg.sh -f x11grab -r 10 -s 128x128 -i :0.0 -f rawvideo - | ./run_ffplay.sh -f rawvideo -s 128x128 -pix_fmt bgr0 -
# Option -s is deprecated, use -video_size.
# Option -pix_fmt is deprecated, use -pixel_format.
./run_ffmpeg.sh -f x11grab -r 10 -s 128x128  -i :0.0 -f rawvideo - | ./run_ffplay.sh -f rawvideo -video_size 128x128 -pixel_format bgr0 -

...还可以直接在 ffmpeg 的窗口中播放带有过滤器的视频:

$ ./run_ffmpeg.sh -re -i small.mp4 -filter_complex "[0:v] scale=w=640:h=-1 [out0]" -map [out0] -pix_fmt yuyv422 -f xv "ffmpeg xv Window"
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'small.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    creation_time   : 2010-03-20T21:29:11.000000Z
    encoder         : HandBrake 0.9.4 2009112300
  Duration: 00:00:05.57, start: 0.000000, bitrate: 551 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
      encoder         : JVT/AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 83 kb/s (default)
    Metadata:
      creation_time   : 2010-03-20T21:29:11.000000Z
Stream mapping:
  Stream #0:0 (h264) -> scale
  scale -> Stream #0:0 (rawvideo)
Press [q] to stop, [?] for help
Output #0, xv, to 'ffmpeg xv Window':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isomavc1
    encoder         : Lavf57.71.100
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x366, q=2-31, 112435 kb/s, 30 fps, 30 tbn, 30 tbc (default)
    Metadata:
      encoder         : Lavc57.89.100 rawvideo

我本来想发布一张截图,但似乎当有xv窗口视频时,它的内容不会被捕获gnome-screenshot。不过,也可以使用sdl

./run_ffmpeg.sh -re -i small.mp4 -filter_complex "[0:v] scale=w=640:h=-1 [out0]" -map [out0] -f sdl "ffmpeg SDL Window"

...这似乎被捕获了gnome-screenshot

ffmpeg-sdl 库

相关内容