RootEncoder: Crashed application RTMP || IP camera

Hi all.

I’m writing an application, I used your libraries to transfer video to the server by RTMP.

Has connected all as it is necessary in a gradle and the manifest.

There are MainActivities and SurfaceView, I wanted to start broadcasting video from SurfaceView directly to the server, as in your examples. But there was an error and the application closes as soon as it opens.

He swears on two lines:

        // create builder
        RtmpCamera1 rtmpCamera1 = new RtmpCamera1 (videostreamPreviewSf, (ConnectCheckerRtmp) this);
        // start stream
        rtmpCamera1.startStream ("rtmp: //adress...");

crash

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 33 (16 by maintainers)

Most upvoted comments

This could be useful for you. It is a little code to use that should work(Of course, I cant test it so maybe not 😦). Read commentary because you need create 2 new methods in VideoDecoder class to work:

public class TestH264Stream
    implements LoopFileInterface, VideoDecoderInterface, GetH264Data, ConnectCheckerRtmp {

  private VideoDecoder videoDecoder;
  private VideoEncoder videoEncoder;
  private SrsFlvMuxer srsFlvMuxer;
  private int width, height;

  public TestH264Stream() {
    videoDecoder = new VideoDecoder(this, this);
    videoEncoder = new VideoEncoder(this);
    srsFlvMuxer = new SrsFlvMuxer(this);
  }

  public void prepare(int width, int height) {
    this.width = width;
    this.height = height;
    videoEncoder.prepareVideoEncoder(width, height, 30, 1200 * 1024, 0, false, 2,
        FormatVideoEncoder.SURFACE);
    /*Change this to other method. Use your own configuration. 
    You don't need use MediaExtractor because you should know stream resolution, etc. 
    The idea is create your own MediaFormat to avoid nullpointer in prepareVideo method*/
    videoDecoder.initExtractor();
    videoDecoder.prepareVideo(videoEncoder.getInputSurface());
  }

  public void start(String url) {
    videoEncoder.start();
    videoDecoder.start();
    srsFlvMuxer.setVideoResolution(width, height);
    srsFlvMuxer.start(url);
  }

  public void stop() {
    videoDecoder.stop();
    videoDecoder.stop();
    srsFlvMuxer.stop();
  }

  //Send to decoder h264 buffers to stream. After decode frames VideoEncoder surface will be feed with decoders data 
  // and this data will be encoded.
  public void sendH264Buffer(ByteBuffer byteBuffer) {
    /*This method no exists now. This should be like the current method decodeVideo in VideoDecoder 
    but frame is send from this method no from a file like MediaExtractor do */
    videoDecoder.sendH264Data(byteBuffer);  
  }

  @Override
  public void onReset(boolean isVideo) {
    //no file end so this is ignored
  }

  @Override
  public void onVideoDecoderFinished() {
    //no file end so this is ignored
  }

  //callback to get frame info. This should be called a time with the first encoded frame.
  @Override
  public void onSPSandPPS(ByteBuffer sps, ByteBuffer pps) {
    srsFlvMuxer.setSpsPPs(sps, pps);
  }

  //callback called when a frame is encoded.
  @Override
  public void getH264Data(ByteBuffer h264Buffer, MediaCodec.BufferInfo info) {
    srsFlvMuxer.sendVideo(h264Buffer, info);
  }

  @Override
  public void onVideoFormat(MediaFormat mediaFormat) {
    //useful is you want record. See some Base to know about it.
  }

  @Override
  public void onConnectionSuccessRtmp() {
    //do something
  }

  @Override
  public void onConnectionFailedRtmp(String reason) {
    //do something
  }

  @Override
  public void onDisconnectRtmp() {
    //do something
  }

  @Override
  public void onAuthErrorRtmp() {
    //do something
  }

  @Override
  public void onAuthSuccessRtmp() {
    //do something
  }
}

This look audio permission missed. Remember get permissions on runtime if you use API23+

AndroidViewFilter work with all views that draw something in onDraw (it means that library get canvas from the view and draw this canvas) method except a GlSurfaceView.

If your camera is device camera (You still have device camera in use so you can’t open with the library) nothing to do by default. You need modify the library. If camera is like a IP camera and you want re stream it to other server you can try use AndroidViewFilter like I said but if not work you can modify the project to stream using opengl to copy surface frames to surface from VideoEncoder class (like I do using OpenglView that copy camera frames in surfaceview surface and in VideoEncoder surface) or send h264 and aac bytebuffer directly to rtmp or rtsp modules.

Other way (maybe not useful for you) is stream your device screen like in DisplayRtmpActivity class

You can do a “hacky way”. You can do stream with openglview and use AndroidViewFilter to send other view of course this will use camera but your view will overlay it so you can set same size to openglview than your surfaceview and overlay all camera content. You can see OpenglRtmpActivity to know how to use openglview and androidviewfilter. If you need more info you can see this issue still closed: https://github.com/pedroSG94/rtmp-rtsp-stream-client-java/issues/125

The error is here:

(ConnectCheckerRtmp) this

You need implement ConnectCheckerRtmp in your class.