[FFmpeg-user] help using SIGPIPE in ffmpeg

Dave Rice dave at dericed.com
Fri Nov 3 22:53:27 EET 2023


Hi ffmpeg-users,

I was using a behavior in ffmpeg where SIGPIPE would terminate ffmpeg (while permitting it to cleanly end its muxing). This can be demonstrated in ffmpeg 5.1.3 with this command of piping ffmpeg into ffplay. When I close the ffplay window, the ffmpeg receives a SIGPIPE and stop.

ffmpeg -f lavfi -i testsrc -f matroska test_ffmpeg5.mov -f nut - | ffplay -
ffmpeg version 5.1.3ffplay version 5.1.3 Copyright (c) 2003-2022 the FFmpeg developers Copyright (c) 2000-2022 the FFmpeg developers

  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --prefix='/usr/local/Cellar/ffmpeg at 5/5.1.3' --datadir='/usr/local/Cellar/ffmpeg at 5/5.1.3/share/ffmpeg' --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  configuration: --prefix='/usr/local/Cellar/ffmpeg at 5/5.1.3' --datadir='/usr/local/Cellar/ffmpeg at 5/5.1.3/share/ffmpeg' --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox
  libavutil      57. 28.100 / 57. 28.100
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #1:0 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7f9070417300] using SAR=1/1
[libx264 @ 0x7f9070417300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x7f9070417300] profile High 4:4:4 Predictive, level 1.3, 4:4:4, 8-bit
[libx264 @ 0x7f9070417300] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 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=7 lookahead_threads=1 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=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'test_ffmpeg5.mov':
  Metadata:
    encoder         : Lavf59.27.100
  Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 1k tbn
    Metadata:
      encoder         : Lavc59.37.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Output #1, nut, to 'pipe:':
  Metadata:
    encoder         : Lavf59.27.100
  Stream #1:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p(tv, progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 51200 tbn
    Metadata:
      encoder         : Lavc59.37.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
Input #0, nut, from 'pipe:':4.7 size=       1kB time=00:00:00.00 bitrate=230000.0kbits/s speed=0.455x    
  Metadata:
    encoder         : Lavf59.27.100
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 51200 tbn
    Metadata:
      encoder         : Lavc59.37.100 mpeg4
   1.22 M-V:  0.001 fd=   0 aq=    0KB vq=   39KB sq=    0B f=0/0   trate=   1.4kbits/s speed=3.81x    
av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:: Broken pipe
frame=  121 fps= 60 q=-1.0 Lq=1.6 size=      24kB time=00:00:04.80 bitrate=  41.2kbits/s speed=2.38x    
video:219kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Error closing file pipe:: Broken pipe
[libx264 @ 0x7f9070417300] frame I:1     Avg QP:19.18  size:  2974
[libx264 @ 0x7f9070417300] frame P:33    Avg QP:14.59  size:   461
[libx264 @ 0x7f9070417300] frame B:87    Avg QP:14.07  size:    51
[libx264 @ 0x7f9070417300] consecutive B-frames:  1.7%  0.0% 22.3% 76.0%
[libx264 @ 0x7f9070417300] mb I  I16..4: 30.0% 43.0% 27.0%
[libx264 @ 0x7f9070417300] mb P  I16..4:  1.7%  1.3%  0.8%  P16..4:  7.3%  3.8%  2.7%  0.0%  0.0%    skip:82.4%
[libx264 @ 0x7f9070417300] mb B  I16..4:  0.2%  0.2%  0.0%  B16..8:  4.0%  0.1%  0.0%  direct: 0.1%  skip:95.5%  L0:53.0% L1:42.1% BI: 4.9%
[libx264 @ 0x7f9070417300] 8x8 transform intra:39.2% inter:36.5%
[libx264 @ 0x7f9070417300] coded y,u,v intra: 10.8% 11.2% 10.0% inter: 0.7% 0.8% 0.7%
[libx264 @ 0x7f9070417300] i16 v,h,dc,p: 55% 32%  1% 13%
[libx264 @ 0x7f9070417300] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 72%  4% 24%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x7f9070417300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 46% 14%  1%  1%  1%  0%  1%  0%
[libx264 @ 0x7f9070417300] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7f9070417300] ref P L0: 68.2%  7.7% 21.1%  3.0%
[libx264 @ 0x7f9070417300] ref B L0: 59.4% 36.4%  4.2%
[libx264 @ 0x7f9070417300] ref B L1: 97.3%  2.7%
[libx264 @ 0x7f9070417300] kb/s:37.43



With ffmpeg 6, the behavior is different. When I close the ffplay window, the ffmpeg does not stop. I’ve tried adding -xerror but that doesn’t help get the 5.1.3 behavior. With ffmpeg 6 is there a way to have ffmpeg stop nicely when receiving SIGPIPE (like ffmpeg 5.1.3 could do)?



ffmpeg -f lavfi -i testsrc -f matroska test_ffmpeg6.mov -f nut - | ffplay -
ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: wrapped_avframe, rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 25 tbn
Stream mapping:
  Stream #0:0 -> #0:0 (wrapped_avframe (native) -> h264 (libx264))
  Stream #0:0 -> #1:0 (wrapped_avframe (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
ffplay version 6.0 Copyright (c) 2003-2023 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/6.0_1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[libx264 @ 0x7fdbbaa0a340] using SAR=1/1
[libx264 @ 0x7fdbbaa0a340] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x7fdbbaa0a340] profile High 4:4:4 Predictive, level 1.3, 4:4:4, 8-bit
[libx264 @ 0x7fdbbaa0a340] 264 - core 164 r3108 31e19f9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 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=7 lookahead_threads=1 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=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'test_ffmpeg6.mov':
  Metadata:
    encoder         : Lavf60.3.100
  Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 1k tbn
    Metadata:
      encoder         : Lavc60.3.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Output #1, nut, to 'pipe:':
  Metadata:
    encoder         : Lavf60.3.100
  Stream #1:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p(tv, progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 51200 tbn
    Metadata:
      encoder         : Lavc60.3.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
Input #0, nut, from 'fd:':q=4.7 size=       0kB time=00:00:00.00 bitrate=N/A speed=N/A    
  Metadata:
    encoder         : Lavf60.3.100
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 51200 tbn
    Metadata:
      encoder         : Lavc60.3.100 mpeg4
   1.30 M-V:  0.001 fd=   0 aq=    0KB vq=   40KB sq=    0B f=0/0   trate=   1.1kbits/s speed=3.13x    
av_interleaved_write_frame(): Broken pipe
[out#1/nut @ 0x7fdbbaa0b000] Error muxing a packet
[out#1/nut @ 0x7fdbbaa0b000] Error writing trailer: Broken pipe16 bitrate=  20.5kbits/s speed=13.5x    
frame= 2715 fps=339 q=-1.0 Lq=2.0 size=     492kB time=00:01:48.48 bitrate=  37.2kbits/s speed=13.5x    
video:671kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7fdbbaa0a340] frame I:11    Avg QP:16.89  size:  3393
[libx264 @ 0x7fdbbaa0a340] frame P:733   Avg QP:14.00  size:   472
[libx264 @ 0x7fdbbaa0a340] frame B:1971  Avg QP:14.24  size:    52
[libx264 @ 0x7fdbbaa0a340] consecutive B-frames:  1.0%  0.0% 19.6% 79.4%
[libx264 @ 0x7fdbbaa0a340] mb I  I16..4: 31.1% 38.6% 30.3%
[libx264 @ 0x7fdbbaa0a340] mb P  I16..4:  1.8%  1.6%  0.8%  P16..4:  7.2%  3.8%  2.6%  0.0%  0.0%    skip:82.2%
[libx264 @ 0x7fdbbaa0a340] mb B  I16..4:  0.2%  0.1%  0.0%  B16..8:  4.3%  0.1%  0.0%  direct: 0.1%  skip:95.2%  L0:52.9% L1:42.7% BI: 4.4%
[libx264 @ 0x7fdbbaa0a340] 8x8 transform intra:38.7% inter:36.4%
[libx264 @ 0x7fdbbaa0a340] coded y,u,v intra: 10.1% 10.7% 8.7% inter: 0.7% 0.8% 0.7%
[libx264 @ 0x7fdbbaa0a340] i16 v,h,dc,p: 49% 32%  2% 17%
[libx264 @ 0x7fdbbaa0a340] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 64%  5% 31%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x7fdbbaa0a340] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 54% 11%  1%  1%  1%  0%  1%  0%
[libx264 @ 0x7fdbbaa0a340] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fdbbaa0a340] ref P L0: 68.5%  7.2% 21.0%  3.3%
[libx264 @ 0x7fdbbaa0a340] ref B L0: 58.4% 38.6%  3.1%
[libx264 @ 0x7fdbbaa0a340] ref B L1: 97.5%  2.5%
[libx264 @ 0x7fdbbaa0a340] kb/s:35.73
Exiting normally, received signal 2.

Kind Regards,
Dave Rice



More information about the ffmpeg-user mailing list