2

On Ubuntu 14.04, there is avconv/avplay instead of ffmpeg/ffplay; version is:

$ 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

I would like to set up a pipe, where I pipe the output of avconv to be played by avplay, so I can check if my avconv settings are correct; unfortunately, I cannot get any pipe of this kind whatsoever to work.

I'm working with small.mp4 Sample MP4 Video File from Sample WebM, Ogg, and MP4 Video Files for HTML5 | TechSlides; I have also seen bash - How can I pipe output of ffmpeg to ffplay? - Super User.

Here are my attempts:

$ 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

So, I have to specify output format for avconv, we can see those capable of both encoding and decoding like this:

$ 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

Let's try flv format - if I add just -f flv, then I get "flv does not support that sample rate, choose from (44100, 22050, 11025)."; so I also add -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)

So, a segfault crash - even if the avplay supposedly correctly read the properties of the input stream...

Same segfault happens for avi format (and also if I specify the format for 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   

Same for format mpegts ...

Closest I got to piping was this command from [FFmpeg-user] Pipe to ffplay when recording: syntax :

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

... which however, cannot be really "just converted" to av* commands, because in this version in particular, because:

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

... so the command in this version of Ubuntu would be:

$ 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

... and this is the only one that I found so far that doesn't segfault, and actually shows a video window - but the video screen looks like this:

Screenshot-pipe.png

... that is, the entire video window/screen is black - apart from some green pixels that jitter in the upper left corner...

Also note in this version, occasionally I get "pipe:1: Not yet implemented in Libav, patches welcome", if I try to use pipe:1 instead of just dash - to represent stdout/stdin...

So, is it possible to set up a pipe from avconv to avplay, so avplay plays at least the video (or best, plays both audio and video) sent by avconv, in this version of Ubuntu - and if so, how?

  • 2
    It's looking for a format to encode to so simple command would be avconv -i small.mp4 -f m4v - | avplay - or avconv -i small.mp4 -f matroska - | avplay You could add encoding options if desired (after the -i small.mp4 – doug Jan 25 '18 at 23:54
0

OK, got somewhere with this - not with the built-in avconv/avplay, though:

I found ffmpeg output device xv full screen? : ffmpeg, with this command:

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

So, there is some output device xv that can play to a window; avconv -devices says "Unrecognized option 'devices'" (man says: "The option "-formats" of the av* tools will display the list of enabled output devices (amongst the muxers)."). Note there are FFmpeg Static Builds, but these seemingly do not include the xv device.

So, I ended up using it from PPA - this is how to do it so it runs from extern location:

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

Then you can have a script like this, run-ffmpeg.sh (and make a same one for ffplat -> run-ffplay.sh; remember to chmod +x *.sh them both):

#!/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

(Note using this script somehow screws up the terminal echo, which is the reason for the last stty echo)

Then, finally, the X11 pipe works:

./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 -

... and also can play a video with filters directly in a window from 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

I would have posted a screenshot, but seemingly when having xv window video, its contents do not get captured with gnome-screenshot. However, can also use 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"

... and that seems to get captured with gnome-screenshot:

ffmpeg-sdl.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.