我正在尝试同时录制2个视频供稿。我可以获取2个Feed,也可以同时从2个摄像机获取图片。我正在尝试从这两个摄像机获取视频源,但是有可能吗?
我设置了两个媒体记录器(每个摄像机一个)。
fun setupNormalMediaRecorder(activity: MainActivity, params: CameraParams){
params.mediaNormalRecorder.apply {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
setVideoSource(MediaRecorder.VideoSource.SURFACE)
setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_720P))
setOutputFile(activity.getOutputMediaFileUri("Normal").toString())
prepare()
}
}
fun setupWideMediaRecorder(activity: MainActivity, params: CameraParams){
params.mediaWideRecorder.apply {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
setVideoSource(MediaRecorder.VideoSource.SURFACE)
setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_720P))
setOutputFile(activity.getOutputMediaFileUri("Wide").toString())
prepare()
}
}
然后我设置了两个录制会话。
fun startNormalRecordingSession(activity: MainActivity, params: CameraParams){
recordNormalSession(activity, params)
}
fun startWideRecordingSession(activity: MainActivity, params: CameraParams){
recordWideSession(activity, params)
}
fun stopNormalRecordingSession(activity: MainActivity, params: CameraParams){
stopNormalMediaRecorder(activity, params)
}
fun stopWideRecordingSession(activity: MainActivity, params: CameraParams){
stopWideMediaRecorder(activity, params)
}
这是保存两个提要的代码。
fun getOutputMediaFileUri(name: String): Uri {
//requestRuntimePermission()
return Uri.fromFile(getOutputMediaFile(type, name))
}
fun getOutputMediaFile(name: String): File {
val mediaStorageDir = File(getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS), "TwoCameraFeed")
if (!mediaStorageDir.exists()){
if (!mediaStorageDir.mkdirs()){
Log.d("MyCameraApp", "Failed To Create Directory!")
}
}
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
var mediaFile = File(mediaStorageDir.getPath() + separator + "VID_$name" + timeStamp + ".mp4")
return mediaFile
}
然后,当我按下按钮时,我将开始两个记录。这就是我尝试过的方式。
button.setOnClickListener {
if(isRecording){
isRecording = false
stopWideRecordingSession(activity, params)
stopNormalRecordingSession(activity, params)
restartActivity()
}else{
button.text = "Stop"
twoLens.reset()
twoLens.isTwoLensShot = true
MainActivity.cameraParams.get(dualCamLogicalId).let{
if(it?.isOpen == true){
isRecording = true
startWideRecordingSession(activity, params)
startNormalRecordingSession(activity, params)
}
}
}
}
但是,当我运行此代码时,我继续遇到以下错误。
2019-06-28 15:44:22.633 5997-5997/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dualcameratets, PID: 5997
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:534)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Caused by: java.io.FileNotFoundException: file:/storage/emulated/0/Download/TwoCameraImages/VID_Wide20190628_154422.mp4: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:485)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:288)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:151)
at android.hsm.HwMediaPermWrapper.setOutputFile(HwMediaPermWrapper.java:127)
at android.media.MediaRecorder.prepare(MediaRecorder.java:1026)
at com.example.dualcameratets.CameraUtilsKt.setupWideMediaRecorder(CameraUtils.kt:372)
at com.example.dualcameratets.Camera2ControllerKt.recordWideSession(Camera2Controller.kt:70)
at com.example.dualcameratets.MainActivity.startWideRecordingSession(MainActivity.kt:320)
at com.example.dualcameratets.MainActivity$onCreate$1.onClick(MainActivity.kt:81)
at android.view.View.performClick(View.java:6652)
at android.view.View.performClickInternal(View.java:6624)
at android.view.View.access$3100(View.java:787)
at android.view.View$PerformClick.run(View.java:26213)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7470)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:210)
at libcore.io.IoBridge.open(IoBridge.java:471)
它说没有这样的文件或目录,因为创建了文件夹,这有点奇怪,但是它从不记录任何提要。 有什么建议吗?