FFMPEG 视频录像机问题
Posted
技术标签:
【中文标题】FFMPEG 视频录像机问题【英文标题】:FFMPEG Video Recorder Issue 【发布时间】:2019-12-30 07:29:35 【问题描述】:我正在使用FFmpegVideoRecorder - Customizable Video Recording Library for android
在我的应用程序中进行视频录制。我按照 GitHub 上的说明安装了该库。当我运行该应用程序时,我收到以下错误。
Error opening camera
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference
at com.google.common.collect.ImmutableSet.copyOf(ImmutableSet.java:247)
at com.amosyuen.videorecorder.camera.CameraController.setFlashModeParams(CameraController.java:383)
at com.amosyuen.videorecorder.camera.CameraController.openCamera(CameraController.java:175)
at com.amosyuen.videorecorder.activity.FFmpegRecorderActivity$OpenCameraTask.doInBackground(FFmpegRecorderActivity.java:718)
at com.amosyuen.videorecorder.activity.FFmpegRecorderActivity$OpenCameraTask.doInBackground(FFmpegRecorderActivity.java:706)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
我使用的代码是这样的
recordbtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String videoSTVString = "/sdcard/myapp_"+ date +".mp4";
prefs.edit().putString("videoSTVString", videoSTVString).commit();
String thumbnailString = "/sdcard/myapp_thumbnail_"+ date +".jpg";
File stvVideoFile = new File(videoSTVString);
File stvThumbnailFile = new File(thumbnailString);
startActivity(stvVideoFile, stvThumbnailFile);
);
public void startActivity(File videoFile, File thumbnailFile)
FFmpegRecorderActivityParams.Builder paramsBuilder =
FFmpegRecorderActivityParams.builder(getApplicationContext())
.setVideoOutputFileUri(videoFile)
.setVideoThumbnailOutputFileUri(thumbnailFile);
paramsBuilder.recorderParamsBuilder()
.setVideoSize(new ImageSize(640, 480))
.setVideoCodec(EncoderParamsI.VideoCodec.H264)
.setVideoBitrate(100000)
.setVideoFrameRate(30)
.setVideoImageFit(ImageFit.FILL)
.setVideoImageScale(ImageScale.DOWNSCALE)
.setShouldCropVideo(true)
.setShouldPadVideo(true)
.setVideoCameraFacing(CameraControllerI.Facing.BACK)
.setAudioCodec(EncoderParamsI.AudioCodec.AAC)
.setAudiosamplingRateHz(44100)
.setAudioBitrate(100000)
.setAudioChannelCount(2)
.setOutputFormat(EncoderParamsI.OutputFormat.MP4);
Intent intent = new Intent(this, FFmpegRecorderActivity.class);
intent.putExtra(FFmpegRecorderActivity.REQUEST_PARAMS_KEY, paramsBuilder.build());
startActivityForResult(intent, 1000);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
if (requestCode == 1000)
switch (resultCode)
case RESULT_OK:
Uri videoUri = data.getData();
break;
case Activity.RESULT_CANCELED:
break;
case FFmpegRecorderActivity.RESULT_ERROR:
break;
谁能帮我解决这个错误?
【问题讨论】:
这个问题解决了吗?我也遇到了类似的问题 【参考方案1】:你正在使用的库,https://github.com/amosyuen/FFmpegVideoRecorder最近处理了这个错误,从Camera获取getSupportedFlashModes时遇到这个错误。您可以在此处查看最近的构建 -
https://github.com/amosyuen/FFmpegVideoRecorder/commit/5844bd9b944cd6efa1e93278d35b95d1092c6016
【讨论】:
是否可以编辑库中的文件?当我尝试时,它显示它是一个只读文件。我使用实现 'com.amosyuen.ffmpegvideorecorder:ffmpeg-video-recorder:2.0.3' 安装它 只需清理项目并重新编译库,可能会解决您的错误。 我清理并重新编译了库,现在我收到以下错误:E/FFmpegRecorderActivity: Error opening camera java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera。以上是关于FFMPEG 视频录像机问题的主要内容,如果未能解决你的问题,请参考以下文章
使用 opencv 和 ffmpeg 制作视频。如何找到正确的颜色格式?
javascript Node.JS功能使用FFMPEG将IP摄像机的mp4 / h.264视频转换为HTML5视频标签