Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save rtsp stream in android?

i am working on Rtsp streaming app .Rtsp stream is working fine but now i want to save this in android SD card.i have done lot of google search but cannot find correct solutions. There are few methods i came across but didn't succeed. Using FFMPEG and android NDK to store the stream on device? I am new to Android and RTSP streaming, help will be very appreciated.

import android.app.Dialog;
import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

public class FrontFragment extends Fragment {
    VideoView videoView;
    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        final View rootView = inflater.inflate(
                R.layout.fragment_front_cam, container, false);
        videoView = (VideoView) rootView.findViewById(R.id.video_view);
        MediaController mc = new MediaController(getActivity());
        videoView.setMediaController(mc);
//
        //Set the path of Video or URI
        videoView.setVideoURI(Uri.parse("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov"));
        //Set the focus
        videoView.requestFocus();
        videoView.start();

        Button btn = (Button) rootView.findViewById(R.id.buttonDialog);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Dialog fb = new Dialog(getActivity());
                fb.setContentView(R.layout.dialogue_camera);
                fb.setTitle("Camera Options");
                fb.show();
                Button config = (Button) fb.findViewById(R.id.buttonConfigure);
                config.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        // Toast.makeText(getActivity(),"Configure",Toast.LENGTH_SHORT).show();
                        Intent i = new Intent(getActivity(), ConfigureCam1.class);
                        startActivity(i);
                        fb.dismiss();
                    }
                });
                Button rec = (Button) fb.findViewById(R.id.buttonRecord);
                rec.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(getActivity(), "Record", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
        return rootView;
    }

    public void recordMethod() {
        Toast.makeText(getActivity(), "Front Fragment called", Toast.LENGTH_SHORT).show();
    }
}
like image 718
SAK Avatar asked Aug 11 '15 11:08

SAK


People also ask

Can I use RTSP in browser?

As a rule, browsers do not support RTSP, so the video stream is converted for a browser using an intermediate server.

Is RTSP stream secure?

Like WebRTC, RTSP streams use the Real-Time Transport Protocol (RTP) in conjunction with Real-time Control Protocol (RTCP) for media stream delivery. RTSP can also use SRTP to encrypt the stream so that it remains secure.


1 Answers

I also suffered with the same problem. But I have resolved using the following library.

https://github.com/bravobit/FFmpeg-Android

String[] cmd = {"-y", "-i", "rtsp://username:[email protected]:554", "-acodec", "copy", "-vcodec", "copy","-t","00:00:20", targetFile.toString() };

FFmpeg.getInstance(this).execute(cmd,new ExecuteBinaryResponseHandler(){

            @Override
            public void onStart() {
                super.onStart();
                Log.i(TAG,"Start");
            }

            @Override
            public void onFailure(String message) {
                super.onFailure(message);
                Log.i(TAG,message);

            }

            @Override
            public void onSuccess(String message) {
                super.onSuccess(message);
                Log.i(TAG,"OnSuccess...");

             }

            @Override
            public void onProgress(String message) {
                super.onProgress(message);
                Log.i(TAG,"onProgress");
            }

            @Override
            public void onFinish() {
                super.onFinish();
                Log.i(TAG,"onFinish");


            }
        });

The above code save the 20 seconds video on given path.

like image 63
Kona Suresh Avatar answered Oct 05 '22 08:10

Kona Suresh