Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MediaExtractor RTSP

Tags:

android

I'm attempting to develop an application which downloads a live video stream via RTSP (Real Time Streaming Protocol) from a security camera.

I have successfully connected to the camera and can view the video in a VideoView. However, I want low level access to the data stream so have been looking into the MediaExtractor API.

When I set the data source to an RTSP URI I receive an IOException - Failed to open file. This is confusing as this same URI works correctly in VideoView and other media players such as VLC. I am assuming VideoView must be using the same MediaExtractor options 'under the hood'. Does MediaExtractor support RTSP? I was expecting my RTSP URI to be opened by the MediaExtractor. I couldn't see anywhere in the documentation where this is unsupported. If I'm missing something can you please point me in the right direction. I see there are other libraries such as FFmpeg, VLC and Live555 which are available but I was attempting to using the Android SDK if possible.

Code (Kotlin):

val extractor = MediaExtractor()
extractor.setDataSource("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov")

Error:

2018-12-11 15:43:23.259 21127-21127/com.crichq.myactionreplayhub E/FileSource: Failed to open file 'rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov'. (No such file or directory)
2018-12-11 15:43:23.260 21127-21127/com.crichq.myactionreplayhub D/AndroidRuntime: Shutting down VM
2018-12-11 15:43:23.262 21127-21127/com.crichq.myactionreplayhub E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.crichq.myactionreplayhub, PID: 21127
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crichq.myactionreplayhub/com.crichq.myactionreplayhub.MediaExtractorActivity}: java.io.IOException: Failed to instantiate extractor.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: java.io.IOException: Failed to instantiate extractor.
        at android.media.MediaExtractor.nativeSetDataSource(Native Method)
        at android.media.MediaExtractor.setDataSource(MediaExtractor.java:202)
        at com.crichq.myactionreplayhub.MediaExtractorActivity.onCreate(MediaExtractorActivity.kt:16)
        at android.app.Activity.performCreate(Activity.java:7174)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6944) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

Andorid Version:

compileSdkVersion 28 (Android 9.0)

Android Test Device:

Samsung Galaxy S7 Edge (running Android 8.0.0)

like image 769
Morepork Avatar asked Dec 11 '18 03:12

Morepork


1 Answers

MediaExtractor supports HTTP or local file only

https://developer.android.com/reference/android/media/MediaExtractor.html#setDataSource(java.lang.String)

public void setDataSource (String path) Sets the data source (file-path or http URL) to use.

path String: the path of the file, or the http URL of the stream

like image 89
msh Avatar answered Oct 18 '22 11:10

msh