FFmpegFrameGrabber doesn't work for rtp

1,039 views
Skip to first unread message

Bin

unread,
Sep 9, 2015, 8:16:54 PM9/9/15
to javacv

I'm trying to display the rtp video from a webcam. I can display the rtp with ffplay(even with quite large delay), however I can't use   FFmpegFrameGrabber to get it work.
if I use setFormat("rtp"), I get this error "[rtp @ 0x7f3040658640] Received too short packet"
if I use setFormat("h264"), I get the following

[h264 @ 0x7f0da86b5f80] missing picture in access unit with size 183
[h264 @ 0x7f0da86b5f80] no frame!
[h264 @ 0x7f0da86ac880] decoding for stream 0 failed
[h264 @ 0x7f0da86ac880] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: avformat_find_stream_info() error -541478725: Could not find stream information.
    at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:436)
    at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:377)

Can anyone help? Thanks


This is my code:
------------------------------------------------------------------------------------------------------------------------------------
FFmpegFrameGrabber stream= new FFmpegFrameGrabber("vchat.sdp");//sdp file for rtp
    
        stream.setFormat("h264");
        //stream.setFormat("rtp");
            stream.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
            //stream.setVideoCodec(avcodec.AV_CODEC_ID_AAC);

            stream.setVideoBitrate(2000000);
           stream.setVideoCodec(avcodec.AV_CODEC_ID_H264);
           //stream.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
          
            // FPS (frames per second)
            stream.setFrameRate(30);
            stream.setImageHeight(480);
            stream.setImageWidth(640);
           
            stream.start();
            Frame image;
           
            while(true)
            {
                  image = stream.grab();
                            
                  if(image!=null)
                    {
                           frame.showImage(image);
                    }
            }
           

Samuel Audet

unread,
Sep 10, 2015, 10:03:54 AM9/10/15
to jav...@googlegroups.com
On 09/10/2015 12:48 AM, Bin wrote:
> I'm trying to display the rtp video from a webcam. I can display the rtp with ffplay(even with quite large delay), however I can't use FFmpegFrameGrabber to get it work.

Could you also post the output of ffplay? It should give us some clues
about how we should be reading the file. Thanks!

Samuel

Eric

unread,
Sep 11, 2015, 2:45:34 AM9/11/15
to javacv
Hi Samuel,

Attached are the screenshot (for setFormat(''h264''))

for the setFormat("rpt") one, the error is the following(endless too short packet)

Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library /home/wu/Downloads/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0 which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
[rtp @ 0x7fa4a0637d20] Unsupported RTP version packet received
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet
[rtp @ 0x7fa4a0637d20] Received too short packet



On Thursday, September 10, 2015 at 7:03:54 AM UTC-7, Samuel Audet wrote:

Screenshot from 2015-09-10 23:36:26.png

Eric

unread,
Sep 11, 2015, 2:47:32 AM9/11/15
to javacv

missed one shot
Screenshot from 2015-09-10 23:01:43.png

Eric

unread,
Sep 11, 2015, 2:53:57 AM9/11/15
to javacv
here is ffplay one

Thanks!

Eric
ffplay.png

Samuel Audet

unread,
Sep 12, 2015, 2:49:28 AM9/12/15
to jav...@googlegroups.com
I've just tried it here with some RTP stream and FFmpegFrameGrabber
works fine. You did try to NOT call setFormat() or call
setFormat("sdp"), right?

Eric

unread,
Sep 12, 2015, 3:12:52 AM9/12/15
to javacv
I tried three options: no setFormat(), setFormat("rtp") and setFormat("h264"), all of them didn't work,  but never tried setformat("sdp")
if possible, could you share you receiver side code?

Samuel Audet

unread,
Sep 12, 2015, 3:44:07 AM9/12/15
to jav...@googlegroups.com
On 09/12/2015 04:12 PM, Eric wrote:
> I tried three options: no setFormat(), setFormat("rtp") and
> setFormat("h264"), all of them didn't work, but never tried
> setformat("sdp")
> if possible, could you share you receiver side code?

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("test.sdp");
grabber.start()
...

That's all.

Samuel

Eric

unread,
Sep 12, 2015, 6:28:12 PM9/12/15
to javacv
You are right. I guess you must also use a very simple send side setting.  After I clean the send and receive side settings. it works! Thanks a lot!
I guess it is my settings that cause this problem and I tried to match the receive settings with send setting, which even makes things worse
It seems the default encoder is mpeg4 (not H264). Does this rely on some openCV codec( not ffmpeg codec)? it asks me for some openCV library.

Samuel Audet

unread,
Sep 12, 2015, 9:29:47 PM9/12/15
to jav...@googlegroups.com
On 09/13/2015 07:28 AM, Eric wrote:
> You are right. I guess you must also use a very simple send side
> setting. After I clean the send and receive side settings. it works!
> Thanks a lot!

Great :) If you have any insights about why it works better with ffplay,
let me know so we can fix this. Thanks!

> I guess it is my settings that cause this problem and I tried to match
> the receive settings with send setting, which even makes things worse

Are you talking about FFmpegFrameGrabber? Or FFmpegFrameRecorder? The
MPEG4 codec comes bundled with FFmpeg, while H264 does not, so it just
makes more sense for FFmpegFrameRecorder to use it as default. It's not
a big issue to change it though. Let me know if you have concrete
suggestions. Thanks!

> It seems the default encoder is mpeg4 (not H264). Does this rely on some
> openCV codec( not ffmpeg codec)? it asks me for some openCV library.

Neither FFmpegFrameGrabber nor FFmpegFrameRecorder rely on OpenCV
anymore since version 0.11:
http://bytedeco.org/news/2015/04/04/javacv-frame-converters/

Samuel

Cody Ehlers

unread,
Nov 4, 2015, 8:00:30 PM11/4/15
to javacv
Hi Samuel, I'm facing a very similar issue but I'm out of ideas on how to fix it. I have an Android app that uses mjpeg and h264 (rtsp). Everything works great except for one scenario, h264 streaming from a server on an external network. So, to be clear, mjpg and h264 both work if I'm on the same local network as the server, and mjpg works if I'm accessing a server on a different network. Only h264 on the external network doesn't work. The error I get is:
org.bytedeco.javacv.FrameGrabber$Exception: avformat_find_stream_info() error -110: Could not find stream information.
W/System.err﹕ at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:400)
W/System.err﹕ at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:341)  

There isn't much info about this out there except for this discussion so hopefully you can help me resolve and for future readers as well, thanks!

Cody Ehlers

unread,
Nov 5, 2015, 10:20:10 AM11/5/15
to javacv
Ok I've figured it out. Grabber was defaulting to UDP and since UDP is lan only it wouldn't cross the routers. Setting grabber.setOption("rtsp_transport", "tcp") did the trick.

Samuel Audet

unread,
Nov 7, 2015, 9:09:33 PM11/7/15
to jav...@googlegroups.com
On 11/06/2015 12:20 AM, Cody Ehlers wrote:
> Ok I've figured it out. Grabber was defaulting to UDP and since UDP is
> lan only it wouldn't cross the routers. Setting
> grabber.setOption("rtsp_transport", "tcp") did the trick.

Good to know! Thanks.

BTW, we can call FFmpegLogCallback.set() to get more debug info in the log.

Samuel

Reply all
Reply to author
Forward
0 new messages