fyhertz / libstreaming

A solution for streaming H.264, H.263, AMR, AAC using RTP on Android
Apache License 2.0
3.49k stars 1.08k forks source link

RTP: missed N packets #90

Open 4ntoine opened 9 years ago

4ntoine commented 9 years ago

I've tried to stream large resolution video (like 2048 x 2048 and more) and RTP packets are lost and decoding sometimes fails:

MBA-Anton:platform-tools asmirnov$ ffplay rtsp://192.168.168.159:8087
ffplay version 2.2.3 Copyright (c) 2003-2014 the FFmpeg developers
  built on Jan 15 2015 17:26:03 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.2.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-ffplay
  libavutil      52. 66.100 / 52. 66.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  2.100 /  4.  2.100
  libavresample   1.  2.  0 /  1.  2.  0
  libswscale      2.  5.102 /  2.  5.102
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
[h264 @ 0x7f939082a400] RTP: missed 3 packets 0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] RTP: missed 1 packets 0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] RTP: missed 2 packets 0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] P sub_mb_type 9 out of range at 67 66
[h264 @ 0x7f939082a400] error while decoding MB 67 66
[h264 @ 0x7f939082a400] Cannot use next picture in error concealment
[h264 @ 0x7f939082a400] concealing 7918 DC, 7918 AC, 7918 MV errors in P frame
[h264 @ 0x7f939082a400] RTP: missed 5 packets 0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] RTP: missed 7 packets
[h264 @ 0x7f939082a400] RTP: missed 3 packets 0KB sq=    0B f=0/0   
    Last message repeated 1 times
[h264 @ 0x7f939082a400] corrupted macroblock 61 23 (total_coeff=-1)
[h264 @ 0x7f939082a400] error while decoding MB 61 23
[h264 @ 0x7f939082a400] Cannot use next picture in error concealment
[h264 @ 0x7f939082a400] concealing 13428 DC, 13428 AC, 13428 MV errors in P frame
[h264 @ 0x7f939082a400] RTP: missed 40 packets0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] RTP: missed 1 packets
[h264 @ 0x7f939082a400] negative number of zero coeffs at 104 57
[h264 @ 0x7f939082a400] error while decoding MB 104 57
[h264 @ 0x7f939082a400] Cannot use next picture in error concealment
[h264 @ 0x7f939082a400] concealing 9033 DC, 9033 AC, 9033 MV errors in P frame
[h264 @ 0x7f939082a400] RTP: missed 4 packets 0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] RTP: missed 9 packets 0KB sq=    0B f=0/0   
[h264 @ 0x7f939082a400] RTP: missed 10 packets
[h264 @ 0x7f939082a400] RTP: missed 1 packets 0KB sq=    0B f=0/0   
Input #0, rtsp, from 'rtsp://192.168.168.159:8087':q=    0B f=0/0   
  Metadata:
    title           : Unnamed
    comment         : N/A
  Duration: N/A, start: 0.003467, bitrate: N/A
    Stream #0:0: Video: h264 (Baseline), yuv420p, 2048x2048, 90k tbr, 90k tbn, 180k tbc
[h264 @ 0x7f9390816e00] P sub_mb_type 9 out of range at 67 66=0/0   
[h264 @ 0x7f9390816e00] error while decoding MB 67 66
[h264 @ 0x7f9390816e00] Cannot use next picture in error concealment
[h264 @ 0x7f9390816e00] concealing 7918 DC, 7918 AC, 7918 MV errors in P frame
[h264 @ 0x7f9390923800] corrupted macroblock 61 23 (total_coeff=-1)
[h264 @ 0x7f9390923800] error while decoding MB 61 23
[h264 @ 0x7f9390923800] Cannot use next picture in error concealment
[h264 @ 0x7f9390923800] concealing 13428 DC, 13428 AC, 13428 MV errors in P frame
[h264 @ 0x7f9390831a00] out of range intra chroma pred mode at 121 37
[h264 @ 0x7f9390831a00] error while decoding MB 121 37
[h264 @ 0x7f9390831a00] Cannot use next picture in error concealment
[h264 @ 0x7f9390831a00] concealing 11576 DC, 11576 AC, 11576 MV errors in P frame
[h264 @ 0x7f9390923800] negative number of zero coeffs at 104 57
[h264 @ 0x7f9390923800] error while decoding MB 104 57
[h264 @ 0x7f9390923800] Cannot use next picture in error concealment
[h264 @ 0x7f9390923800] concealing 9033 DC, 9033 AC, 9033 MV errors in P frame
[h264 @ 0x7f9390816e00] Cannot use next picture in error concealment
[h264 @ 0x7f9390816e00] concealing 533 DC, 533 AC, 533 MV errors in P frame

I've googled a bit and found the following: http://ffmpeg.org/pipermail/libav-user/2013-October/005686.html https://trac.ffmpeg.org/ticket/285#comment:12

So it seems to be UDP issue.. Any confirmations/fixes/thoughts?

4ntoine commented 9 years ago

fixed by increasing MulticastSocket send buffer (RtpSocket.java):

mSocket.setSendBufferSize(2 * 1024 * 1024); // 2 Mb is max for my impl
tesmai4 commented 9 years ago

Hi, I am facing the same issue in my C++ program. I am decoding RTSP stream using FFMPEG and getting the same console output. Any idea how can I increase buffer in my implementation. I am not managing socket in my program. I open RTSP stream using FFMPEG API calls.

hcl008 commented 8 years ago

For C++, if you are using FFMPEG: add AVDictionary* options = NULL; av_dict_set(&options, "rtsp_transport", "tcp", 0); before avformat_open_input

Here is the code fragment:

pFormatCtx = avformat_alloc_context();

AVDictionary* options = NULL; av_dict_set(&options, "rtsp_transport", "tcp", 0);

if (avformat_open_input(&pFormatCtx, filepath, NULL, &options) != 0){ printf("Couldn't open input stream.\n"); return -1; }