Save rtsp stream in android?
Asked Answered
A

1

7

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();
    }
}
Arrive answered 11/8, 2015 at 11:38 Comment(3)
i have tried FFMPEG and android NDK to configure for android but cannot succeed in this.now i just want to save the rtsp streamArrive
@Arrive have you found any solution for your question ? if yes then give answer of your question so i can refer it , i have same problem Thanks in advanced...Whilst
any updates guys? would really appreciate any suggestion/ideas.Padegs
F
3

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.

Foreyard answered 10/6, 2018 at 1:16 Comment(1)
Btw, we used the following to trigger when to stop the recording: final Timer timer = new java.util.Timer(); TimerTask timerTask = new TimerTask() { @Override public void run() { ffTask.sendQuitSignal(); } }; timer.schedule( timerTask, 40000 );Brantley

© 2022 - 2024 — McMap. All rights reserved.