-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FFmpegFrameRecorder didn't work with OutputStream in Android #645
Comments
Does the same thing happen with Java SE on another platform, or does it
happen only with Android?
|
I tried do that only on Android platform, on devices: Nexus 5X, Samsung SGS 6, Xiaomi Mi5s. |
@peter9870 Were you able to use OutputStream under Android? |
I want to create the app, which will help in recording video from android camera to cloud(like dropbox) file directly, and i hope that your JavaCV lib with OutputStream param will helps me in it |
I hope so too, but someone has to spend time to figure it out :)
|
Maybe you have any example how to use FFMpegFrameRecorder with OutputStream? Or this crash platform-specific and refers to Android OS? |
@saudet Yes I got it working. @Like-fire You should use I needed to be able to save to SD so I had to use
I'm not sure if this applies to you but I also had to set the pixelformat like so otherwise it wouldn't work correctly. |
Yes, it works! Thank you, but i have quetions. Using this camera i had bad video quality. When i change crv and set value "6" from example camera doesn't respond to fast movements, when i set value "35" camera respond much faster but, too much noise. How i can improve video quality. Thank you very much! |
Have you tried using |
It solved issue with bad picture quality, but absolutely not solve problem with video freezes on fast camera moving. It looks like too few frames per second, but i set it to 30 |
What do you mean by "freeze"? The application doesn't recover?
|
No, just looks like there are about 10 frames per second, but it set to 30 |
So, your device is just too slow to encode as fast as you would like, that's normal. |
On recording CPU monitor show less then 30-40%, and i tried it on phones: Google Pixel XL, Xiaomi Mi5S, LG Nexus 5X, Samsung S7. All of them show similar results. I think the problem has other reasons. |
So, the codec you are using doesn't support multithreading. Try to use a codec that supports multithreading, and use more than one thread for encoding. |
@peter9870 does your recorded videos this way have problem with determine video length in video player apps? like this #95 (comment) |
so works with mastorka, but problem with seeking and length detection, seems when using outputStream ffmpeg mb cannot add some final lines to the video file when we stop recording |
@anonym24 yes I've seen this issue where the video has length 00:00 |
@peter9870 it's always undefined |
yes, I encounter this problem on win7 java10 environment @Test
fun testFFmpegFrameRecorder() {
val inputFilename = "./test-videos/wildlife.wmv"
val outputFilename = "./test-videos/encoded.mp4"
val outputPath = Paths.get(outputFilename)
Files.deleteIfExists(outputPath)
Files.createFile(outputPath)
FileInputStream(File(inputFilename)).use {
FFmpegFrameGrabber(it).use { fg ->
fg.imageMode = FrameGrabber.ImageMode.RAW
fg.start()
val frameSeq = generateSequence { fg.grab().takeIf { frame -> frame != null } }
val frameNum = fg.lengthInFrames
val fr = FFmpegFrameRecorder(
//outputFilename,//
FileOutputStream(outputFilename),
640,//must be multiplication of 32
320,//must be even
fg.audioChannels)//.use { fr ->
fr.format = "mp4"
fr.isInterleaved = true
fr.pixelFormat = AV_PIX_FMT_YUV420P
fr.frameRate = fg.frameRate
fr.videoBitrate = fg.videoBitrate
fr.audioBitrate = fg.audioBitrate
fr.videoCodec = AV_CODEC_ID_H264
fr.start()
frameSeq.forEachIndexed { i: Int, fra: Frame ->
if (i % 100 == 0) {
log.info("$i/$frameNum\t${Jsons.toString(mapOf("timestamp" to fra.timestamp))}")
}
fr.record(fra)
}
fr.stop()
fr.close()
}
}
} it failed at
any hints? thanks in advance |
@cfcodefans Could you attach sample media files to reproduce this issue? |
yeah, actually I think I have got close to the bottom of this problem in class org.bytedeco.javacv.FFmpegFrameRecorder#startUnsafe if (this.outputStream != null) {
this.avio = avformat.avio_alloc_context(new BytePointer(avutil.av_malloc(4096L)), 4096, 1, this.oc, (Read_packet_Pointer_BytePointer_int)null, writeCallback, (Seek_Pointer_long_int)null);
this.oc.pb(this.avio);
this.filename = this.outputStream.toString();
outputStreams.put(this.oc, this.outputStream);
} (Seek_Pointer_long_int)null is parameter which is needed in conversion for some format like mp4 |
We could add a callback for seek and make it work for specialized implementations like ByteArrayOutputStream, yes, that's a good idea! Could you give it a try? |
sure, will try |
Is there any progress on implementing this feature? |
Thanks to @svorlauf, we can now use |
JavaCV 1.5.3 has been released with |
In my Android test application FFmpegFrameRecorder work properly when i pass File in conctructor, but when i pass OutputStream, app crashes and in Logcat i can see only
com.github.crazyorr.ffmpegrecorder A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 29234 (Thread-266)
Code, where i init my frame recorder:
String recordedTime = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File file = CameraHelper.getOutputMediaFile(recordedTime, CameraHelper.MEDIA_TYPE_VIDEO);
FileOutputStream fos = new FileOutputStream(file);
mFrameRecorder = new FFmpegFrameRecorder(fos, videoWidth, videoHeight, 1);
mFrameRecorder.setFormat("mp4");
mFrameRecorder.setSampleRate(sampleAudioRateInHz);
mFrameRecorder.setFrameRate(frameRate);
mFrameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
mFrameRecorder.setVideoOption("crf", "28");
mFrameRecorder.setVideoOption("preset", "superfast");
mFrameRecorder.setVideoOption("tune", "zerolatency");
Gradle:
Before that i use FFmpegFrameRecorder via just passing file in constructor, but in my app i need possibility to write video from camera using OutputStream.
Please help, maybe i understand something wrong
The text was updated successfully, but these errors were encountered: