Opened 11 years ago

Last modified 11 years ago

#2181 new enhancement

AVIO should provide a way to reconnect broken network streams

Reported by: gjdfgh Owned by:
Priority: normal Component: avformat
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

How to reproduce:

Terminal 1:
% while true ; do nc -l -p 10000 ; done

Terminal 2:
% ffplay http://localhost:10000

Now terminate nc on terminal 1 with ctrl+c (the shell will start another nc instance immediately). ffplay will just terminate with "http://localhost:10000: Input/output error", while mplayer (using the same URL) will reconnect.

I suggest libavformat should do one of the following:

  1. provide a "reconnect" API call
  2. transparently try to reconnect internally, until a timeout is reached

Change History (3)

comment:1 by gjdfgh, 11 years ago

My test is a bit flawed because it tests only creating the initial connection. For testing breaking connections during normal playback, try running a local web server serving a file. Play that with ffplay or mplayer. Then kill and restart the web server. (And I'm not actually sure if mplayer really attempts to reconnect if the connection breaks before the http headers have been exchanged.)

comment:2 by Carl Eugen Hoyos, 11 years ago

Please add the failing command line together with complete, uncut console output.

comment:3 by gjdfgh, 11 years ago

$ ffmpeg -i http://localhost:12004/test.mkv out.mkv
ffmpeg version 1.0.3 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jan 24 2013 14:52:18 with gcc 4.7 (Debian 4.7.2-5)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/i386-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libdc1394 --disable-altivec --disable-armv5te --disable  libavutil      51. 73.101 / 51. 73.101
  libavcodec     54. 59.100 / 54. 59.100
  libavformat    54. 29.104 / 54. 29.104
  libavdevice    54.  2.101 / 54.  2.101
  libavfilter     3. 17.100 /  3. 17.100
  libswscale      2.  1.101 /  2.  1.101
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, matroska,webm, from 'http://localhost:12004/test.mkv':
  Metadata:
    ENCODER         : Lavf54.29.104
  Duration: 00:01:49.12, start: 0.000000, bitrate: 7810 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
[libx264 @ 0x808f7a0] using SAR=1/1
[libx264 @ 0x808f7a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
[libx264 @ 0x808f7a0] profile High, level 3.0
[libx264 @ 0x808f7a0] 264 - core 129 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - 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=-2 threads=3 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 'out.mkv':
  Metadata:
    encoder         : Lavf54.29.104
    Stream #0:0: Video: h264, yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 1k tbn, 25 tbc (default)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> libx264)
Press [q] to stop, [?] for help
frame=   56 fps=0.0 q=28.0 size=      33kB time=00:00:00.28 bitrate= 952.7kbits/frame=   74 fps= 71 q=28.0 size=     161kB time=00:00:01.00 bitrate=1315.3kbits/frame=   91 fps= 59 q=28.0 size=     321kB time=00:00:01.68 bitrate=1563.1kbits/frame=  108 fps= 52 q=28.0 size=     481kB time=00:00:02.36 bitrate=1668.1kbits/frame=  124 fps= 47 q=28.0 size=     641kB time=00:00:03.00 bitrate=1749.2kbits/frame=  139 fps= 45 q=28.0 size=     833kB time=00:00:03.60 bitrate=1894.5kbits/frame=  155 fps= 42 q=28.0 size=    1025kB time=00:00:04.24 bitrate=1979.5kbits/frame=  171 fps= 41 q=28.0 size=    1185kB time=00:00:04.88 bitrate=1988.5kbits/frame=  187 fps= 40 q=28.0 size=    1334kB time=00:00:05.52 bitrate=1979.6kbits/frame=  202 fps= 39 q=28.0 size=    1526kB time=00:00:06.12 bitrate=2042.5kbits/Read error
frame=  215 fps= 31 q=18195026.0 Lsize=    2268kB time=00:00:08.52 bitrate=2181.1kbits/s    
video:2266kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.092124%
[libx264 @ 0x808f7a0] frame I:1     Avg QP:20.34  size: 24459
[libx264 @ 0x808f7a0] frame P:66    Avg QP:23.09  size: 16142
[libx264 @ 0x808f7a0] frame B:148   Avg QP:30.85  size:  8312
[libx264 @ 0x808f7a0] consecutive B-frames:  0.5%  0.0% 69.8% 29.8%
[libx264 @ 0x808f7a0] mb I  I16..4: 40.1% 44.1% 15.8%
[libx264 @ 0x808f7a0] mb P  I16..4:  0.6%  0.1%  0.0%  P16..4: 48.6% 13.3%  8.8%  0.0%  0.0%    skip:28.6%
[libx264 @ 0x808f7a0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 22.6%  4.9%  2.4%  direct: 4.4%  skip:65.7%  L0:46.0% L1:43.9% BI:10.1%
[libx264 @ 0x808f7a0] 8x8 transform intra:34.2% inter:20.0%
[libx264 @ 0x808f7a0] coded y,uvDC,uvAC intra: 24.0% 74.4% 27.4% inter: 12.3% 25.0% 19.3%
[libx264 @ 0x808f7a0] i16 v,h,dc,p: 20%  9%  8% 63%
[libx264 @ 0x808f7a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 12% 26% 10% 13%  5% 11%  6%  3%
[libx264 @ 0x808f7a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 14% 12% 10% 11%  9% 10% 10%  9%
[libx264 @ 0x808f7a0] i8c dc,h,v,p: 31% 10% 15% 44%
[libx264 @ 0x808f7a0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x808f7a0] ref P L0: 53.2%  5.3% 29.4% 12.0%
[libx264 @ 0x808f7a0] ref B L0: 67.3% 26.7%  6.0%
[libx264 @ 0x808f7a0] ref B L1: 82.5% 17.5%
[libx264 @ 0x808f7a0] kb/s:2158.20

I killed and restarted the local webserver some time into the encode (roughly at frame 202). The time between killing and fully restarting the server is very short (shell script that restart the server in a loop if it exists). For my test, I tried the program webfsd (it supports seeking).

Obviously ffmpeg exits after receiving the error, instead of retrying. Compare this to mplayer, which can transparently restart.

Note: See TracTickets for help on using tickets.