Javacv: FFmpegFrameGrabber.start() stuck when provided url with no video

Created on 22 May 2019  路  2Comments  路  Source: bytedeco/javacv

I was trying to pull some video from an address of myself, while there is not always a video being pushed in that address.
When there's no video stream in that address (or, as I tried, just provide a non-existing url for FFmpegFrameGrabber), FFmpegFrameGrabber.start() stuck. Was it trying to connect to the url permanently? Or maybe the connection was already established at the first time, but it's tring to find some video in vain?
I tried adding FFmpegFrameGrabber.setOption("stimeout", "10000000"); after creating the FFmpegFrameGrabber object, but it won't work and FFmpegFrameGrabber.start() stuck as before.
Here's my code:

import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacv.*;
import org.bytedeco.ffmpeg.global.avutil;
import org.opencv.core.Mat;
import org.bytedeco.opencv.opencv_java;
import org.opencv.highgui.HighGui;
import javax.swing.*;
import java.util.Date;
import static org.opencv.imgcodecs.Imgcodecs.imwrite;

public class Main {
    static {Loader.load(opencv_java.class);}
    public static void main(String[] args) throws FrameGrabber.Exception {
        String path = "rtmp://play.aszn.org.cn/live/zcf";
        //String path = "rtmp://play.aszn.org.cn/JustNoVideoHere";
        FFmpegFrameGrabber mFrameGrabber = new FFmpegFrameGrabber(path);
        mFrameGrabber.setOption("stimeout", "10000000");
        mFrameGrabber.start();
        Frame mFrame;
        Mat mOpencvMat;
        while(true){
            mFrame = mFrameGrabber.grab();
            mOpencvMat = convert(mFrame);
            if(mOpencvMat != null){
                HighGui.imshow("Video", mOpencvMat);
                HighGui.waitKey(10);
            }
        }

    }

    private static Mat convert(Frame frame){
        OpenCVFrameConverter.ToOrgOpenCvCoreMat converter = new OpenCVFrameConverter.ToOrgOpenCvCoreMat();
        return converter.convert(frame);
    }
}

Help wanted! T_T

question

Most helpful comment

The correct option for RTMP is probably "rw_timeout":
https://ffmpeg.org/ffmpeg-protocols.html#Protocols

A thousand thanks to you! Problem is solved at once. Without your help I will be searching the internet whole day for Solution. Just brilliant of you.^_^

All 2 comments

The correct option for RTMP is probably "rw_timeout":
https://ffmpeg.org/ffmpeg-protocols.html#Protocols

The correct option for RTMP is probably "rw_timeout":
https://ffmpeg.org/ffmpeg-protocols.html#Protocols

A thousand thanks to you! Problem is solved at once. Without your help I will be searching the internet whole day for Solution. Just brilliant of you.^_^

Was this page helpful?
0 / 5 - 0 ratings

Related issues

y4nnick picture y4nnick  路  3Comments

chenhl05 picture chenhl05  路  4Comments

The-Crocop picture The-Crocop  路  5Comments

SenudaJayalath picture SenudaJayalath  路  3Comments

RaGreen picture RaGreen  路  4Comments