Skip to content
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 creates video with duration less than last frame timestamp #337

Closed
Denis1986 opened this issue Feb 22, 2016 · 6 comments
Labels

Comments

@Denis1986
Copy link

I use FFmpegFrameRecorder (javaCV 1.1) to create video fragments with max duration of 30 seconds from screenshots, which I get from MediaProjection on Android. In each video fragment first frame has timestamp 0.
I have the following recorder settings:

FFmpegFrameRecorder mRecorder;
//...
mRecorder.setFormat("mp4");
mRecorder.setFrameRate(30);
mRecorder.setVideoCodec(AvCodecConstants.CODEC_ID_H264);
mRecorder.setGopSize(10);

MediaProjection gives me next screenshot only when there are changes on the screen, so frames are recorded irregularly. When it is time to close current video fragment, usually the last recorded frame has timestamp smaller than 30 seconds. I found only one way to get video fragment of exactly 30 seconds – I record last real frame several times. As I understand, if first frame has timestamp 0, video duration must be equal to last frame timestamp + last frame duration. For example, if last real frame has timestamp 27.5 sec, I record this frame with timestamps 28.5 sec, 29.5 sec, 29.966 sec. This approach works perfectly with mpeg4 codec, but with H264 codec result video duration is much smaller than last frame timestamp. For example, for one of video fragments video duration (determined by exiftool and mp4parser) is 28.7 sec and last frame has timestamp 29.966 sec and pkt_duration_time = 0.033333 sec (determined by ffprobe).
So I can’t create video of specified duration using FFmpegFrameRecorder with H264 codec. Is it a bug in FFmpegFrameRecorder (when using H264 codec) or am I missing something? May be, there is a way to set duration for last frame instead of recording the last real frame with different timestamps?

@saudet
Copy link
Member

saudet commented Feb 27, 2016

Maybe there is a bug, but the mp4 format isn't known to be easy to work with anyway. I'd suggest trying the Matroska (mkv) format, if that's an option.

@saudet
Copy link
Member

saudet commented May 19, 2016

Is this still happening with JavaCV 1.2?

@Denis1986
Copy link
Author

Denis1986 commented Jun 16, 2016

Sorry for the delay. Now we use MediaCodec instead of ffmpeg in our project.
I have tried to use JavaCV 1.2 in the old version of our project today:

compile 'org.bytedeco:javacv:1.2'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.0.2-1.2', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.0.2-1.2', classifier: 'android-x86'

But I get the following error:
"Error:A problem occurred configuring project ':app' .

A problem occurred configuring project ':library' .
Could not find javacpp-presets-Windows 7-amd64.jar (org.bytedeco:javacpp-presets:1.2).
Searched in the following locations:
https://jcenter.bintray.com/org/bytedeco/javacpp-presets/1.2/javacpp-presets-1.2-Windows 7-amd64.jar"
I have Intel processor, so it it strange for me, that gradle searches for amd64 version.

@saudet
Copy link
Member

saudet commented Jun 16, 2016

Thanks for checking! That's a known issue with Gradle: #395 (comment)

Let me know if that's enough to get it working, thanks!

@saudet
Copy link
Member

saudet commented Dec 9, 2016

Any updates on this? JavaCV 1.3 has just been released. Maybe this got fixed in new versions of FFmpeg...

@saudet
Copy link
Member

saudet commented Jan 18, 2018

I'm guessing you simply forgot to call stop(). Calling release() won't flush the buffers.

@saudet saudet closed this as completed Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants