bytedeco/javacv

Question: Best Way Synchronize Video and Audio When Playing Videos using FFMPEG

Open

#915 opened on Feb 19, 2018

View on GitHub
 (5 comments) (0 reactions) (1 assignee)Java (1,583 forks)batch import
help wantedquestion

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Problem: When reading in some videos, audio and images are returned by FFmpegFrameGrabber is in X second chunks. For example, in one mp4 I'll get a sequence of images in a row when calling grab() that's one seconds worth. After the images I'll then get 1 second's worth of audio. This is problematic because I want to play the video in real-time with audio and video properly synchronized. I've yet to think of a good solution.

Possible Solutions:

  1. The Ideal Solution Ideally I would get one image then be feed all the audio for that image in an interleaved fashion. Is that possible by changing some setting I'm not aware of?

  2. Cache Images and Audio I can cache images and audio and synchronize it when playing it back to the user. I'm estimating this to require more than 1 gig of memory and cause a noticeable pause after seeking to a new frame. So this is undesirable.

  3. Abuse Seeking Could grab an image then read the video until I found the audio I need then seek to the next image frame. This is likely to be very slow.

  4. Launch two instance of FFmpegFrameGrabber. One would read audio and the other images. This might be the best solution. Less memory and cpu intensity than other solutions. I'm not sure if some codecs use hardware acceleration. That could be problematic if all the hardware resources are used by one instance.

Thanks for the help and this great library!

Contributor guide