1

I manage to play a live stream from a url such as this

rtsp://192.168.0.18:554/user=admin&password=&channel=1&stream=0.sdp?

But I want to download this stream into a temporary file and then play it locally so that I can make it seems like the buffering time is short (around 2-4 seconds delay maybe)

Is it possible to do this with rtsp? or do I have to use http?Because this url only works on rtsp protocol

If so,a bit of example would help me alot

Example of my codes

cA.mPlayer1 = new MediaPlayer();
  try {
    cA.mPlayer1.setDataSource("rtsp://192.168.0.18:554/user=admin&password=&channel=1&stream=0.sdp?");
    cA.mPlayer1.prepareAsync();
    cA.mPlayer1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      @Override
      public void onPrepared(MediaPlayer mediaPlayer) {
        cA.mPlayer1.start();
        Toast.makeText(getBaseContext(), "Connecting...", Toast.LENGTH_LONG).show();
      }
    });
  } catch (IOException e) {
    e.printStackTrace();
  }
  cA.mCallback1 = new SurfaceHolder.Callback() {
    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {

      cA.mPlayer1.setDisplay(surfaceHolder);

    }
    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
    }
    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
    }
  };

final SurfaceView surfaceView1 =
        (SurfaceView) findViewById(R.id.surfaceView1);
// Configure the Surface View.
surfaceView1.setKeepScreenOn(true);
// Configure the Surface Holder and register the callback.
SurfaceHolder holder1 = surfaceView1.getHolder();
holder1.addCallback(cA.mCallback1);
holder1.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Fay Zan
  • 165
  • 2
  • 17

1 Answers1

0

you can not use MediaPlayer to save a Raw stream in file . you can use one of these :

1- Capture or decode the RAW frames from live stream and pass them to ffmpeg and save them to sdcard in .h264 format.

2- Then again pick .h264 raw file and decode the file using ffmpeg, and save the file with extention .mp4 into sd card.

3- delete the .h264 file programmatically, and save only .mp4, or which format you want. Try .mp4 playback.

https://stackoverflow.com/a/24586256/6502368

Community
  • 1
  • 1
mehd azizi
  • 594
  • 1
  • 5
  • 16