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

Audio out of sync #321

Closed
The-Crocop opened this issue Jan 29, 2016 · 16 comments
Closed

Audio out of sync #321

The-Crocop opened this issue Jan 29, 2016 · 16 comments
Labels

Comments

@The-Crocop
Copy link

Hi Im having the problem that when I try to transcode a live stream into another live stream audio and video are out of sync. Any ideas why that is and how it can be fixed?

Its happening for many different input streams.

My version is 1.1

code is default im using FFMpegFrameGrabber and FFmpegFrameRecorder

@saudet
Copy link
Member

saudet commented Jan 29, 2016

Make sure to call FFmpegFrameRecorder.setTimestamp(FFMpegFrameGrabber.getTimestamp()), before calling FFmpegFrameRecorder.record(Frame)

@The-Crocop
Copy link
Author

Im doing this:

   recorder.start();
   Frame capturedFrame= null;
                while( keepRunning && (capturedFrame = grabber.grabFrame(audio,video, true, false)) != null ){

                    recorder.setTimestamp(grabber.getTimestamp())
                     recorder.record(capturedFrame);

and getting errors like:

 av_interleaved_write_frame() error -22 while writing interleaved video frame.

and

 pts (600) < dts (767) in stream 0

@saudet
Copy link
Member

saudet commented Jan 30, 2016

That probably means you're trying to use a different frame rate. If you need to convert the frame rate, try to use FFmpegFrameFilter for that.

@The-Crocop
Copy link
Author

How do I use FFmpegFrameFilter for that case?

@saudet
Copy link
Member

saudet commented Jan 31, 2016

Try to use it as shown in issue #164 (comment) but with the fps filter.

@The-Crocop
Copy link
Author

is this correct or should I leave out the timestamp part?

fpsFilter = new FFmpegFrameFilter("fps=fps=25",width,height)
                recorder.start()
            fpsFilter.start()
                Frame capturedFrame= null;

            while( keepRunning && (capturedFrame = grabber.grabFrame(audio,video, true, false)) != null ){

                    fpsFilter.push(capturedFrame)
                    capturedFrame = fpsFilter.pull()
                recorder.setTimestamp(grabber.getTimestamp())
                recorder.record(capturedFrame);
            }

@saudet
Copy link
Member

saudet commented Feb 1, 2016

You're missing a loop in there, and we'll need to pass the timestamps to FFmpegFrameFilter as well, somehow... I didn't think about that...

@The-Crocop
Copy link
Author

   fpsFilter = new FFmpegFrameFilter("fps=fps=25",width,height)

                recorder.start()
                fpsFilter.start()
                Frame capturedFrame= null;

                    while( keepRunning && (capturedFrame = grabber.grabFrame(audio,video, true, false)) != null ){

                fpsFilter.push(capturedFrame) //--> before this we should be calling fpsFilter.setTimestamp(grabber.getTimestamp)?

                Frame frame = null

                while ((frame = fpsFilter.pull())!= null){
                    recorder.setTimestamp(grabber.getTimestamp())// <- so here we would need fpsFilter.getTimestamp?

                    recorder.record(frame);
                }

So currently there is no way to synchronize audio and video or is there another option?

[Parsed_fps_0 @ 000000003a657560] Discarding initial frame(s) with no timestamp

@saudet
Copy link
Member

saudet commented Feb 2, 2016

You could simply drop the frame when recorder.getTimestamp() > grabber.getTimestamp().

@The-Crocop
Copy link
Author

Ok so I keep fpsFilter, and instead of:
recorder.setTimestamp(grabber.getTimestamp())
I do if(recorder.getTimestamp() <= grabber.getTimestamp())recorder.setTimestamp(grabber.getTimestamp())
?

or do you mean I should remove fps Filter completely?

@saudet
Copy link
Member

saudet commented Feb 3, 2016 via email

@The-Crocop
Copy link
Author

Ok thanks alot will try that

@The-Crocop
Copy link
Author

 while( keepRunning && (capturedFrame = grabber.grabFrame(audio,video, true, false)) != null ){
                    if(!(recorder.getTimestamp() > grabber.getTimestamp())){
                        recorder.setTimestamp(grabber.getTimestamp())
                        recorder.record(capturedFrame)
                    }else log.info("drop Frame!")
            }

I did that now all video Frames are being dropped :/ but sound is getting through

@saudet
Copy link
Member

saudet commented Feb 4, 2016

Well, do you see anything in FFmpeg's log that might indicate problems with the timestamps?

@The-Crocop
Copy link
Author

No Messages at all. If I leave out the setTimestamp(grabTimestamp) it works for same framerate

@saudet
Copy link
Member

saudet commented Feb 6, 2016

So it looks like a problem with variable frame rates. Try to use different formats and codecs.

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