gpt4 book ai didi

java - 在android中保存rtsp流?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:47 25 4
gpt4 key购买 nike

我正在开发 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();
}
}

最佳答案

我也遇到了同样的问题。但我已经决定使用以下库。

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 秒的视频保存在给定路径上。

关于java - 在android中保存rtsp流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31940733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com