question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crashed application RTMP || IP camera

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
pedroSG94commented, Mar 20, 2018

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
  }
}
1reaction
pedroSG94commented, Mar 16, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to use RTSP stream from IP Cam as a source (crashes)
I'd like to use an IP cam we have in house but I can't find a clear guide on how to set up...
Read more >
Crashing every time I load | IP Cam Talk
I have Reolink cameras using RTSP and someone posted that switching them to RTMP solves crashing problems. Stepping back through versions ...
Read more >
OpenCV IP camera application crashes [h264 @ 0xxxxx ...
It works perfectly with my webcam. But, it crashes maybe after about ten seconds, while I run it to capture the stream from...
Read more >
[Solved] RTSP Video Stream problem - Blynk Community
Hi, I currently have a cotier ip Camera which I can stream via RTSP in numerous other apps however the same URL won't...
Read more >
RTMP Streaming Connection - ManyCam Help and Support
The RTMP feature allows you to broadcast directly on Facebook, Twitch, USTREAM and YouTube live events. To start a live broadcast you have ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found