我正在研究Rtsp流媒体应用.Rtsp流工作正常,但现在我想在Android SD卡中保存这个。我做了很多谷歌搜索但找不到正确的解决方案。 我遇到的方法很少但没有成功。 使用FFMPEG和android NDK将流存储在设备上? 我是Android和RTSP流媒体的新手,非常感谢帮助。
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();
}
}
答案 0 :(得分:2)
我也遇到了同样的问题。但我已经解决了使用以下库。
<强> https://github.com/bravobit/FFmpeg-Android 强>
String[] cmd = {"-y", "-i", "rtsp://username:password@192.168.0.101: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");
}
});
以上代码在给定路径上保存20秒视频。