bytedeco / bytedeco/sample-projects
FFmpegFrameRecorder doesn't generate video file in android versions 10 or higher
- Dominant language
- Java
- Stars
- 228
- Forks
- 173
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I have been trying the example the example [JavaCV-android-example](https://github.com/bytedeco/sample-projects/tree/master/JavaCV-android-example) but found that it doesn't work for Android version 10 or higher, the video file (.mp4) is not created when the recording is complete.
I'm kind of new to android development but I think the problem is occurring because FFmpegFrameRecorder needs to be passed an instance of FILE that is the .mp4 video file, however, in new versions of Android (10 or higher) the creation of files no longer works that way and the MediaStore API should be used.
```
private void initRecorder() {
ffmpeg_link = new File(getBaseContext().getExternalFilesDir(null), "stream.mp4");
Log.w(LOG_TAG, "init recorder");
if(RECORD_LENGTH > 0) {
imagesIndex = 0;
images = new Frame[RECORD_LENGTH * frameRate];
timestamps = new long[images.length];
for(int i = 0; i < images.length; i++) {
images[i] = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
timestamps[i] = -1;
}
} else if(yuvImage == null) {
yuvImage = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
Log.i(LOG_TAG, "create yuvImage");
}
Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link.getAbsolutePath());
recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);
recorder.setFormat("mp4");
recorder.setSampleRate(sampleAudioRateInHz);
// Set in the surface changed method
recorder.setFrameRate(frameRate);
Log.i(LOG_TAG, "recorder initialize success");
audioRecordRunnable = new AudioRecordRunnable();
audioThread = new Thread(audioRecordRunnable);
runAudioThread = true;
Log.i(LOG_TAG, "recorder initialize success");
}
```
So far I haven't been able to figure out how to fix this problem. Does someone know how to solve this problem?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.