我正在尝试录制由vitamio videoView播放的直播视频。 现在我使用MediaRecorded,但它只是不工作。
我应该怎么做?我有这三种主要的录音方法。还有另一种录制直播流的方法吗?
holder = mVideoView.getHolder();
holder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
initRecorder();
}
});
private void initRecorder() {
if (recorder == null) recorder = new MediaRecorder();
recorder.setPreviewDisplay(holder.getSurface());
//recorder.setCamera(mCamera);
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
// mrecorder.setOutputFormat(8);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoEncodingBitRate(512 * 1000);
recorder.setVideoFrameRate(25);
recorder.setVideoSize(352, 288);
recorder.setOutputFile(Utils.getTuracoFolder() + "/video.mp4");
try {
recorder.prepare();
} catch (IllegalStateException e) {
// This is thrown if the previous calls are not called with the
// proper order
e.printStackTrace();
TLog.e(TAG, e.getMessage());
} catch (IOException e) {
e.printStackTrace();
TLog.e(TAG, e.getMessage());
}
}
private void toggleRecording() {
if (recorder == null) return;
if (recording) {
try {
recorder.stop();
recorder.reset();
initRecorder();
recording = false;
TLog.d(TAG, "Stopped Recording");
} catch (Exception ex) {
TLog.d(TAG, "Error - " + ex.getMessage());
}
} else {
try {
recorder.start();
} catch (IllegalStateException e) {
TLog.e(TAG, e.getMessage());
}
Log.v(TAG, "Recording Started");
recording = true;
}
}
答案 0 :(得分:1)
我已经用ffmpeg完成了它。这样做是为了使用ffmpeg下载m3u8流。
更新你gradle.built
dependencies {
compile 'com.writingminds:FFmpegAndroid:0.3.2'
}
现在你在活动课上写这个
FFmpeg ffmpeg;
//将在root中创建新文件mani.mp4文件的命令
String cmdd="-i http://rt-a.akamaihd.net/ch_04@325608/720p.m3u8 -c:a copy -c:v copy -bsf:a aac_adtstoasc "+ new File(Environment.getExternalStorageDirectory() + "/mani.mp4").getAbsolutePath();
String[] cmd = cmdd.split(" ");
ffmpeg = FFmpeg.getInstance(getApplicationContext());
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onFailure() {}
@Override
public void onSuccess() {}
@Override
public void onFinish() {}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
Log.e("com",e.toString());
}
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onProgress(String message) {
// will print information about every new frame it find on given link
Log.e("com",message);
}
@Override
public void onFailure(String message) {
}
@Override
public void onSuccess(String message) {
}
@Override
public void onFinish() {}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
停止下载按钮点击
运行此功能ffmpeg.killRunningProcesses();
请记住添加互联网和读/写权限