pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.55k stars 772 forks source link

How Stream From SurfaceView Directly #57

Closed adelhoss closed 7 years ago

adelhoss commented 7 years ago

Hi Thank you for create powerful library for streaming how can streaming to wowza server directly from surfaceview i created project : get video stream from hardware and show on surface view now need stream to server your library very good but : supported camera - file - display

pedroSG94 commented 7 years ago
09-29 04:34:35.119 963-1286/? W/ServiceManager: Permission failure: android.permission.RECORD_AUDIO from uid=10054 pid=2870

                                                [ 09-29 04:34:35.119   963: 1286 E/         ]
                                                Request requires android.permission.RECORD_AUDIO
09-29 04:34:35.119 963-1286/? E/AudioFlinger: openRecord() permission denied: recording not allowed
startRecording() called on an uninitialized AudioRecord

No permissions getted on runtime. Please allow audio permissions to the app

adelhoss commented 7 years ago

no show any dialog for ask Permission ... only Show ask for screen record .... NO ASK FOR AUDIO PERMISSION

adelhoss commented 7 years ago

I Update AndroidManifest For Permission Such as Camera Internet AudioRecord and test now

pedroSG94 commented 7 years ago

You need write code to show the dialog on Android6.0+, If not allow permissions manually in your settings. Make sure you have permissions in your manifest.

adelhoss commented 7 years ago

I set Permission Manually for app http://www.mediafire.com/convkey/d026/49ft3ajl26t2zybzg.jpg set Permission Manually in App Manager http://www.mediafire.com/convkey/030d/ivq72zddhs8cx79zg.jpg 5 Second Start Screen Recorder and show icon in notification but no show any toast about connection to server Finally crash app and restart Emulator on phone Crash app this log https://www.mediafire.com/file/364jo1777twm8mb/log22222afterpermission.txt

pedroSG94 commented 7 years ago

Don't use emulator, use a physical device. And show me that log crash

adelhoss commented 7 years ago

Use phone How send log crash ? log crash Emulator send for you in last post...

adelhoss commented 7 years ago

I clear Cache my Phone And app running and screen recorder ok and tost message Connection Faild

pedroSG94 commented 7 years ago

You only need connect your device to android studio and compile with start. Open android monitor and copy paste

adelhoss commented 7 years ago

After I Clear Cache From Recovery Re Install App and app Start Screen and Toast Message Connection fail let me connected to my network and test ..... send result for you ....

adelhoss commented 7 years ago

I need one two hour for Testing And send result to you .... Please Wait ...

adelhoss commented 7 years ago

Phase One Finally Successfully : Successfully Record Screen on Phone And Send Stream toWowza Server. http://www.mediafire.com/convkey/102d/ubjd3fr4fusz8bozg.jpg

Phase two : Second Option In MY APP Get Directly Stream FROM MJPEG And Send Stream TO RTSP SERVER - No Preview need - only Send Surface VIEW Stream TO RTSP SERVER YOU SAY TO ME : EXTRACT NV21 FRAME FROM SURFACE VIEW AND I USE METHOD BUFFER TO BUFFER PLEASE HELP ME Complete Phase 2 thank you very muchhhh god bless you

pedroSG94 commented 7 years ago

Nice, please, share with me the code to fix the bug in the library and tell me a resume how do you fix the error. To stream the camera to a sever you are opening a url that can be opened with VLC app right? You can forget nv21 method I tell you that because I didn't know how you get data from your camera. You need render inputsurface from videoEncoder with the camera data. Share me your actual code to display and I can help you to do it. Remember do a little explanation :)

adelhoss commented 7 years ago

Ok Thank You veryyyyy Much ......... Please Wait Send All Code Phase 1 . And Send for you my code phase 2 : get video stream from ip camera With url (HTTP PROTOCOL) PLEASE WAIT MY FRIEND SEND ALL DATA YOU NEED FOR YOU.

adelhoss commented 7 years ago

HOW USE RTSP DISPLAY First For Use Stream Need TO STREAM SERVER LIKE : Nginx - WOWZA SERVER - RED5 etc ... First I SETUP STREAM SERVER AND CONFIG FOR LIVE STREAM ..... then i Imported your Library and start to use RtspDisplay Class : RTspDisplay Screen whole Device Screen and then by Use rtspdisplay method start stream send stream to server . Very Important : Define Need Permission in Android Manifest : camera-Audio Record - Internet - External Access to storage . MY PROBLEM SYNTAX ERROR AND NO DEFINE PERMISSION . This link my Project for rstp Display I Use Android Studio 2.2.3 Write This Project Download Link https://www.mediafire.com/file/8sbckbzjsb3evd2/MyApplication.zip Only need change rtsp server url by your server address .

pedroSG94 commented 7 years ago

Ah ok no changes to my activity, last activity worked for you. For your second requeriment you need use my library stream with my library vlc: https://github.com/pedroSG94/vlc-example-streamplayer You never will see a preview but stream will work. My Activity demo:

package com.pedro.rtmpstreamer.displayexample;

import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.pedro.rtmpstreamer.R;
import com.pedro.rtplibrary.rtsp.RtspDisplay;
import com.pedro.rtsp.rtsp.Protocol;
import com.pedro.rtsp.utils.ConnectCheckerRtsp;
import com.pedro.vlc.VlcListener;
import com.pedro.vlc.VlcVideoLibrary;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class DisplayRtspActivity extends AppCompatActivity
    implements ConnectCheckerRtsp, VlcListener {

  private RtspDisplay rtspDisplay;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    rtspDisplay = new RtspDisplay(this, Protocol.TCP, this);

    //If application crash and you see a error like this:
    //E/VLC: [00000073a66cce88/393f] mediacodec decoder: output: 261 unknown, 240x160 stride 240 160, crop 0 0 0 0
    //replace 240 and 160 (resolution) in preparevideo to the resolution that you see in the crash, in this log case 240x160
    if (rtspDisplay.prepareAudio() && rtspDisplay.prepareVideo(240, 160, 30, 1200 *1024, true, 0, 320)) {
      rtspDisplay.startStream("yourserverurl");
      VlcVideoLibrary vlcVideoLibrary =
          new VlcVideoLibrary(DisplayRtspActivity.this, DisplayRtspActivity.this,
              rtspDisplay.getStreamSurface());
      vlcVideoLibrary.play("yourcameraurl");

      //this url was use for test
      //vlcVideoLibrary.play("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
    }
  }

  @Override
  public void onConnectionSuccessRtsp() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Connection success", Toast.LENGTH_SHORT).show();
      }
    });
  }

  @Override
  public void onConnectionFailedRtsp() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Connection failed", Toast.LENGTH_SHORT).show();
        rtspDisplay.stopStream();
      }
    });
  }

  @Override
  public void onDisconnectRtsp() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
      }
    });
  }

  @Override
  public void onAuthErrorRtsp() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Auth error", Toast.LENGTH_SHORT).show();
      }
    });
  }

  @Override
  public void onAuthSuccessRtsp() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Auth success", Toast.LENGTH_SHORT).show();
      }
    });
  }

  @Override
  public void onComplete() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Reproducing video", Toast.LENGTH_SHORT).show();
      }
    });
  }

  @Override
  public void onError() {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(DisplayRtspActivity.this, "Error reproducing video", Toast.LENGTH_SHORT)
            .show();
      }
    });
  }
}
adelhoss commented 7 years ago

Yes Last Activity are ok but Two little Problem : 1-Sign && Forgotted between video and sound in activity result 2-use rtsp utils library but in overload use rtmp

For Phase 2 : no need play ip camera . I need Directly Send Stream Ip Camera To Server . Phase 1 only rtspdisplay . but in phase 2 : I Use Library For Show Mjpeg and Show Mjpeg in my Activity . no need preview only need IpCamera Mjpeg Stream TO WOWZA SERVER . no play need . no privew need . only directly send stream of ip camera to wowza server . no allowed to use of rtsp display in phase 2 . phase 1 with help you ok and finished .

IpCamera I Used in My Project Only Supported Mjpeg (Motion JPEG ) i can get stream from my IpCamera With http://admin:123456@192.168.1.20/?action=stream . with above url can get stream from ipCamera . I need Send This Stream To WOWZA SERVER . Before Send I think very Hard Work : show Camera Preview in Activity For Get Stream From Surface View . Now I Use Mjpeg Library Use of one Surface View To Show IpCamera Stream With Url. 1-Send Directly Stream From IpCamera ?(Directly) 2-Send Stream From Android To Server ?(Indirectly) no difference between Way one and two : Only no allow use of rtspDisplay because used in phase 1 .only send Stream to WOWZA SERVER : For Get Stream Two Ways : Directly Get Stream From IPCAMERA THEN SEND TO WOWZA SERVER OR GET STREAM FROM ANDROID THEN SEND TO WOWZA SERVER .

Android App Only SEND STREAM IN PHASE 2 . no show no privew no play . Only SEND STREAM TO SERVER IN APPLICATION .NO ALLOWED SCREEN RECORD IN PHASE 2 . Goal Of phase 2 is Send Stream to WOWZA SERVER : input Stream From IPCAMERA -----output Stream to SERVER .

pedroSG94 commented 7 years ago

Vlc can get that type of stream. Please test the code

adelhoss commented 7 years ago

I NO ALLOWED USE RTSPDISPLAY . SCREEN RECORDER NO ALLOWED . ok test this code . BUT NO ALLOW RECORDING IN PHASE 2 .

adelhoss commented 7 years ago

please explain your code in second phase : you reuse rtspdisplay (I no allowed re use rtsp display): rtspdisplay record screen . you use vlcplyer library for get stream right ? for send stream reuse rtspdisplay right ? rtspdisplay use mediaprojection that record screen right ? possible Get Stream IpCamera With vlc and send STREAM from vlc To Server ?

adelhoss commented 7 years ago

These is Picture of My Code and My layout Activity and Extrnal Library I Used : i use this code to show Ip Camera(but Preview Not need) if get stream from this view after hide http://www.mediafire.com/convkey/8b41/ckslyem36gvz6tlzg.jpg I use These Library http://www.mediafire.com/view/y6h1htv5w6uxw4w/ph22.JPG this is layout : http://www.mediafire.com/convkey/d107/zp30k2j2fqzc3uzzg.jpg and phase 1 in emulator http://www.mediafire.com/convkey/bf27/7l4m0dbv7url1x8zg.jpg

adelhoss commented 7 years ago

Possible instead of rtspdisplay(because Record Screen) use rtsp library to send Stream to SERVER ???

adelhoss commented 7 years ago

Please RE READ MY POST : https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/issues/57#issuecomment-333283811

pedroSG94 commented 7 years ago

Forget line example please. Get my vlc project and compile (no activity that i writed vlc project linked) then use your url camera ( http://192.168.43.227/media/?action=stream) and click on start. Can you see your camera?

adelhoss commented 7 years ago

Sorry . OK NOW TESTED YOUR CODE . PLEASE WAIT . I am so sorry .

adelhoss commented 7 years ago

I Use Of Your Library Vlc But Toast Show Message : "Error,Make Sure Your EndPoint is correct" this picture result of my test ; http://www.mediafire.com/convkey/426c/ecmhwzd55gvxwchzg.jpg i Used this link : http://admin:@192.168.1.10/media/?action=stream because my camera has basic Authentication and for send user and pass with url before ip seprate username and password with sign ':' and last with @ sign . but your library is error with this url . my camera no passwords . my camera no option for disable Authentication . this is my code : http://www.mediafire.com/convkey/1d4f/anr4hm163jwmr6mzg.jpg

adelhoss commented 7 years ago

this is my problem : https://forum.videolan.org/viewtopic.php?t=132686 Supporter Say use vlckit 3.0

pedroSG94 commented 7 years ago

If you have auth with your camera I can't help you. I don't know how to do it. It need investigation

adelhoss commented 7 years ago

no Problem with auth wit my camera i USE SAME URL IN MJPEGVIEWER LIBRARY . HTTP IS STANDARD PROTOCOL and Basic auth very simple request . i Can Get Stream in My activity . Only Please Help Me Send Stream IP Camera To server .

adelhoss commented 7 years ago

Please Help Me Send Stream With different way on phase 1 . in phase 2 only need send stream to server .

adelhoss commented 7 years ago

i have not any problem with auth of my camera . even vlc player windows version cannot play ip cam stream . Why Use vlc library ? I get Stream in Activity with another library Successfully . You only Help Me send Stream to server .

adelhoss commented 7 years ago

vlc Library Increase Apk Size to 62MB ..... use your library and send stream . now you send camera stream to server . only need change send my stream to server .

pedroSG94 commented 7 years ago

If VLC example don't work. I can't help you more I need develop other way to do it and that require time. I want finish other things first. No time for this develop.

adelhoss commented 7 years ago

You Tested Vlc ? vlc For You Worked ?

adelhoss commented 7 years ago

Only Need Update libvlc in your project

adelhoss commented 7 years ago

these my mjpeg library added send stream function to it . help me get stream with MjpegLibrary and help Send Stream with your library .

pedroSG94 commented 7 years ago

I don't know how work your library... I need read all code to do it and adapt all, I do it on my free time so maybe this need time to do. Anyway I have no plan to do it now. I want develop other things.

adelhoss commented 7 years ago

very very short code less 100 line code and commented . Please Read Library : https://www.mediafire.com/file/c6s6uypb9vsti7v/mjpegviewer.zip only six method get stream . Please spend ten minute on this subject . set out of library to input your library . I Have not Any Way Please Help Me . Only Ten Minute Spend Time Please .

pedroSG94 commented 7 years ago

With that way I only can tell you try get streamsurface like I do in Main2Activity example and draw the bitmap with the method that you use with the surfaceholder unlocking and locking surface canvas.

I think this will crash and if no crash you will get low fps but I don't know other easy way. I have other idea but It could need 1 week working all days to develop and I don't want do it. I can tell you the theory idea but no more.

adelhoss commented 7 years ago

please write sample example for send stream to server with different source other than camera .

pedroSG94 commented 7 years ago

I told you that I need so much time to develop it and for now I will not add that feature. Your issue realted with library was solved (Display mode) so issue closed. Open other issue if you need more help

Squrrli commented 6 years ago

Hi Sorry to reopen this thread, but without documentation I am finding it difficult to understand how to begin working towards getting a stream from a surface.

Just wondering if anything for that has been implemented in the past year?

Cheers, Adam.

pedroSG94 commented 6 years ago

You have multiple example in app folder. This is the most easy example: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/blob/master/app/src/main/java/com/pedro/rtpstreamer/defaultexample/ExampleRtmpActivity.java