in a bash script i'm using ffmpeg to create a spectrogram movie and pipe
the output to a decoder (mpv in this case, but it doesn't matter)
as expected, if the user exits mpv before ffmpeg completes, it returns a
broke pipe error and i would like to avoid that if possible
the problem is that the terminal may refuse to accept any user input
when this happens (this occurs ~20% of the time)
is there a way to have ffmpeg exit gracefully when the pipe is broken?
$ ffmpeg -i 'a.flac' -filter_complex
"[0:a]showspectrum=mode=separate:color=intensity:scale=cbrt:s=1280x518[top];
[0:a]showwaves=s=1280x202:mode=point:colors=white[bottom];
[top][bottom]vstack" -map 0:a -codec:v libx264 -preset fast -crf 18
-codec:a copy -f matroska - | mpv --no-config -- -
ffmpeg version n4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11.1.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static
--disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm
--enable-lto --enable-fontconfig --enable-gmp --enable-gnutls
--enable-gpl --enable-ladspa --enable-libaom --enable-libass
--enable-libbluray --enable-libdav1d --enable-libdrm
--enable-libfreetype --enable-libfribidi --enable-libgsm
--enable-libiec61883 --enable-libjack --enable-libmfx
--enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb
--enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus
--enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr
--enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1
--enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf
--enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264
--enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid
--enable-libzimg --enable-nvdec --enable-nvenc --enable-shared
--enable-version3
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat58. 76.100 / 58. 76.100
libavdevice58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc55. 9.100 / 55. 9.100
Input #0, flac, from 'a.flac':
Metadata:
GENRE : Soft
TITLE : 17th Street
ARTIST : 2 Good To Go
COMMENT : Muzik Faktry v20211226 12/26/2021
REPLAYGAIN_REFERENCE_LOUDNESS: 89.0 dB
REPLAYGAIN_TRACK_GAIN: -6.36 dB
REPLAYGAIN_TRACK_PEAK: 1.
REPLAYGAIN_ALBUM_GAIN: -6.36 dB
REPLAYGAIN_ALBUM_PEAK: 1.
Duration: 00:03:38.00, start: 0.00, bitrate: 953 kb/s
Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Side data:
replaygain: track gain - -6.36, track peak - 0.23, album
gain - -6.36, album peak - 0.23,
Stream mapping:
Stream #0:0 (flac) -> showspectrum
Stream #0:0 (flac) -> showwaves
vstack -> Stream #0:0 (libx264)
Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 @ 0x5627f9f5aa00] using SAR=1/1
[libx264 @ 0x5627f9f5aa00] MB rate (15876) > level limit (16711680)
[libx264 @ 0x5627f9f5aa00] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5627f9f5aa00] profile High 4:4:4 Predictive, level 6.2,
4:4:4, 8-bit
[libx264 @ 0x5627f9f5aa00] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4
AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html -
options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6
psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1
8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=12
lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0
bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1
b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250
keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf
mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
aq=1:1.00
Output #0, matroska, to 'pipe:':
Metadata:
GENRE : Soft
TITLE : 17th Street
ARTIST : 2 Good To Go
COMMENT : Muzik Faktry v20211226 12/26/2021
REPLAYGAIN_REFERENCE_LOUDNESS: 89.0 dB
REPLAYGAIN_TRACK_GAIN: -6.36 dB
REPLAYGAIN_TRACK_PEAK: 1.
REPLAYGAIN_ALBUM_GAIN: -6.36 dB
REPLAYGAIN_ALBUM_PEAK: 1.
encoder : Lavf58.76.100
Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(progressive),
1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1k tbn (default)
Metadata:
encoder : Lavc58.134.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: flac ([172][241][0][0] / 0xF1AC), 44100 Hz,
stereo, s16
Side data:
replaygain: track gain - -6.36, track peak - 0.23, album
gain - -6.36, album peak - 0.23,
[file] Reading from stdin...
frame=1 fps=0.0 q=0.0 size= 1kB time=00:00:00.74 bitrate=
1