bytedeco/javacv

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

Open

#915 创建于 2018年2月19日

在 GitHub 查看
 (5 评论) (0 反应) (1 负责人)Java (1,583 fork)batch import
help wantedquestion

仓库指标

Star
 (6,985 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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!

贡献者指南