Capturing a mjpg stream with android

Hi, I’ve got a small camera from which I stream mjpeg video. I’d like to capture this for further processing in my android app. I have a runnable class MJpegCapture which has this “run” function:

    public void run(){
        s = new Size();
        frame = new Mat();
        toRun = true;
        VideoCapture capture = new VideoCapture();
        capture.open(mJPEGUrl);
        capture.read(frame);
        s.height = frame.rows();
        s.width = frame.cols();
        while (capture.read(frame) && toRun == true) {
            listener.onFrameReceived(frame);
            frame.release();
            System.gc();
        }
        capture.release();
    }

When using this in a java project on a desktop, it seems to work, but on android I get this error:

2021-05-28 09:06:17.366 6915-6915/com.example.myapp E/NativeCodec: failed to stat file: http://172.16.0.193:8000?dummy=param.mjpg (No such file or directory)

What I did to resolve this issue:
1.) I made sure that the url is actually accessible by accessing ti with the browser of the device I use for testing. Video streaming on the url works.
2.) I made sure that Internet Permissions have been granted in the manifest.

    <uses-permission android:name="android.permission.INTERNET" />

3.) I made sure cleartext traffic is allowed

        android:usesCleartextTraffic="true"

4.) I added “?dummy=param.mjpg” to the end of the url as some users of the internet seem to believe it is necessary.

I’m not sure how to proceed. Does anyone have a hint or an alternative approach?

sorry to say so, but there is no backend (like ffmpeg or gstreamer) to read video urls on android by default, you can only read local avi files with MJPG codec

so, changing permissions or tweaking the url won’t help.

if you really need this, you will have to build ffmpeg libs on android, and rebuild the opencv sdk, so it is using that

(you can ofc. open a socket, and implement your own MJPEG protocol, receiving JPG images, but that won’t scale for other protocols, like rtsp)

Thanks for the quick reply, though it was not the answer I wanted, it was the one I needed.
I will probably be adapting the code from simplemjpegview as I really don’t need anything other than mjpeg. Also my boss is chasing me to get this part done.

Could you add a link to the documentation where it says so?

heh, good one :wink:
i don’t think, there’s anything in the docs.
(maybe you can find a github issue)
also: Add Android Media NDK video I/O file capture back-end by komakai · Pull Request #14005 · opencv/opencv · GitHub