我目前正在以this project为例开发用于慢动作录制的Android应用。我已经在ZTE BLADE L5 PLUS(Android 5.0)上试用过该应用,并且运行良好,但是由于我需要30 [FPS]以上的分辨率才能获得高质量的慢动作视频,因此我改用了Sony Xperia XZ (Android 8.0)并尝试了此应用。
我现在有2个问题:
1.-跳过了帧: 当我从30(没有尝试过)录制到65 FPS时,该应用程序偶尔会丢失比我使用mMediaRecorder.setVideoFrameRate(int)固定的帧更多的帧,这实际上使视频输出“冻结”了1秒钟以上。为什么会发生这种情况以及如何预防呢?
2。-如果我设置的值> = 65 FPS,应用程序将崩溃: 我实际上不知道我在这里做错了什么。如果有人看到代码中可能导致失败的内容,我将不胜感激。
代码:
private void setupMediaRecorder() throws IOException
{
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setOutputFile(mVideoFileName);
mMediaRecorder.setVideoEncodingBitRate(1000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setOrientationHint(mTotalRotation);
try
{
mMediaRecorder.prepare();
}
catch (IOException e)
{
e.printStackTrace();
}
}
LOG <65FPS:
11-07 11:33:28.788 9285-9309/com.company.www.project I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
11-07 11:33:28.793 9285-9309/com.company.www.project I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
11-07 11:33:28.809 9285-9309/com.company.www.project I/OpenGLRenderer: Initialized EGL, version 1.4
11-07 11:33:28.846 9285-9285/com.company.www.project I/CameraManagerGlobal: Connecting to camera service
11-07 11:33:28.874 9285-9285/com.company.www.project E/libc: Access denied finding property "persist.camera.cfa.packagelist"
11-07 11:33:28.862 9285-9285/com.company.www.project W/.project: type=1400 audit(0.0:1356): avc: denied { read } for name="u:object_r:camera_prop:s0" dev="tmpfs" ino=3332 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:camera_prop:s0 tclass=file permissive=0 ppid=1034 pcomm="main" pgid=1034 pgcomm="main"
11-07 11:33:28.874 9285-9285/com.company.www.project E/libc: Access denied finding property "persist.camera.cfa.packagelist"
11-07 11:33:28.879 9285-9290/com.company.www.project I/zygote64: Do partial code cache collection, code=27KB, data=23KB
After code cache collection, code=27KB, data=23KB
Increasing code cache capacity to 128KB
11-07 11:33:28.936 9285-9309/com.company.www.project I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
11-07 11:33:31.638 9285-9290/com.company.www.project I/zygote64: Do partial code cache collection, code=50KB, data=44KB
After code cache collection, code=50KB, data=44KB
Increasing code cache capacity to 256KB
11-07 11:33:31.639 9285-9290/com.company.www.project I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
11-07 11:33:39.400 9285-9290/com.company.www.project I/zygote64: Do full code cache collection, code=124KB, data=90KB
11-07 11:33:39.401 9285-9290/com.company.www.project I/zygote64: After code cache collection, code=89KB, data=59KB
11-07 11:34:00.273 9285-9285/com.company.www.project I/Choreographer: Skipped 55 frames! The application may be doing too much work on its main thread.
11-07 11:34:00.729 9285-9290/com.company.www.project I/zygote64: Do partial code cache collection, code=124KB, data=82KB
After code cache collection, code=124KB, data=82KB
Increasing code cache capacity to 512KB
11-07 11:34:21.830 9285-9285/com.company.www.project I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread.
日志> = 65FPS:
11-07 12:14:59.806 10366-10366/com.company.www.project E/MediaRecorder: prepare failed: -2147483648
11-07 12:14:59.806 10366-10366/com.company.www.project W/System.err: java.io.IOException: prepare failed.
11-07 12:14:59.807 10366-10366/com.company.www.project W/System.err: at android.media.MediaRecorder._prepare(Native Method)
at android.media.MediaRecorder.prepare(MediaRecorder.java:954)
at com.company.www.project.MainActivity.setupMediaRecorder(MainActivity.java:444)
at com.company.www.project.MainActivity.startRecord(MainActivity.java:456)
at com.company.www.project.MainActivity.checkWriteStoragePermission(MainActivity.java:412)
at com.company.www.project.MainActivity.access$800(MainActivity.java:42)
at com.company.www.project.MainActivity$3.onClick(MainActivity.java:191)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24710)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6572)
11-07 12:14:59.808 10366-10366/com.company.www.project W/System.err: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
11-07 12:14:59.808 10366-10366/com.company.www.project E/MediaRecorder: SurfaceMediaSource could not be initialized!
11-07 12:14:59.810 10366-10366/com.company.www.project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.company.www.project, PID: 10366
java.lang.IllegalStateException: failed to get surface
at android.media.MediaRecorder.getSurface(Native Method)
at com.company.www.project.MainActivity.startRecord(MainActivity.java:467)
at com.company.www.project.MainActivity.checkWriteStoragePermission(MainActivity.java:412)
at com.company.www.project.MainActivity.access$800(MainActivity.java:42)
at com.company.www.project.MainActivity$3.onClick(MainActivity.java:191)
at android.view.View.performClick(View.java:6256)
at android.view.View$PerformClick.run(View.java:24710)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:251)
at android.app.ActivityThread.main(ActivityThread.java:6572)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
感谢您的时间=)
答案 0 :(得分:0)
好的,我已经找到了部分答案,我将与遇到的下一个问题共享:) 所以我现在要做的是以QUALITY_HIGH配置文件作为我的mMediaRecorder的基础,只是更改了bitRate和FrameRate尝试将其记录为120 FPS,如下所示:
private void setupMediaRecorder() throws IOException
{
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mMediaRecorder.setOutputFormat(profile.fileFormat);
mMediaRecorder.setVideoEncoder(profile.videoCodec);
mMediaRecorder.setVideoEncodingBitRate(8000000);
mMediaRecorder.setVideoFrameRate(120);
mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mMediaRecorder.setOutputFile(mVideoFileName);
mMediaRecorder.setOrientationHint(mTotalRotation);
try
{
mMediaRecorder.prepare();
}
catch (IOException e)
{
e.printStackTrace();
}
}
现在我正在录制30FPS的视频,但我实际上并不了解->如果在MediaRecorder上设置120FPS怎么办?
关于如何获得MediaRecorder以120FPS实际记录的任何想法吗?
谢谢!
答案 1 :(得分:0)
您需要以下配置以 30、60、90 和 120 fps 进行录制。
来源:
$ git clone https://source.codeaurora.org/quic/la/camera-samples -b iot-concam-apk.lnx.1.1
private var streamConfigOpMode: Int = 0x00
private val HIGH_SPEED_SESSION: Int = 1
previewRequest.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range(previewFps, previewFps))
if (previewFps == 120) streamConfigOpMode = streamConfigOpMode or HIGH_SPEED_SESSION
Log.d(TAG, "Operation Mode: $streamConfigOpMode")
val config = SessionConfiguration(
streamConfigOpMode, outConfigurations, HandlerExecutor(cameraHandler),
object : CameraCaptureSession.StateCallback() {
override fun onConfigured(s: CameraCaptureSession) {
if (previewFps == 120) {
Log.i(TAG, "onConfigured HFR session")
sessionHFR = s as CameraConstrainedHighSpeedCaptureSession
// if there is no active surface, do not set setRepeatingBurst.
if (streamSurfaceList.isNotEmpty()) {
var requestList = sessionHFR.createHighSpeedRequestList(previewRequest.build())
sessionHFR.setRepeatingBurst(requestList, null, cameraHandler)
}
} else {
Log.i(TAG, "onConfigured session")
session = s
// if there is no active surface, do not set setRepeatingRequest.
if (streamSurfaceList.isNotEmpty()) {
if ((streamSurfaceList.size == 2) && (previewFps == 60 || previewFps == 90)) {
optimizePreviewFPS(previewFps)
} else {
session.setRepeatingRequest(previewRequest.build(), null, cameraHandler)
}
}
}
isCameraReady = true
Log.i(TAG, "isCameraReady true")
}
override fun onConfigureFailed(s: CameraCaptureSession) =
s.device.close()
})
config.sessionParameters = previewRequest.build()
camera.createCaptureSession(config)
Log.i(TAG, "createSession exit")
private fun optimizePreviewFPS(previewFps: Int) {
when (previewFps) {
60 -> {
var burstList = mutableListOf<CaptureRequest>()
burstList.add(previewRequest.build())
// First Surface is always display.
previewRequest.removeTarget(streamSurfaceList[0])
burstList.add(previewRequest.build())
session.setRepeatingBurst(burstList, null, cameraHandler)
previewRequest.addTarget(streamSurfaceList[0])
}
90 -> {
var burstList = mutableListOf<CaptureRequest>()
burstList.add(previewRequest.build())
// First Surface is always display.
previewRequest.removeTarget(streamSurfaceList[0])
burstList.add(previewRequest.build())
burstList.add(previewRequest.build())
session.setRepeatingBurst(burstList, null, cameraHandler)
previewRequest.addTarget(streamSurfaceList[0])
}
}
}