question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to synchronize audio and video stream from different sources exactly in [ms]?

See original GitHub issue

Expected Behavior

Receive synchronized video clip (accuracy in ms).

Actual Behavior

Unsynchron video clips:

  • first try: audio 1.5 s late
  • 2nd try: audio 2.5 s late

Steps to Reproduce the Problem

from moviepy.editor import VideoFileClip, AudioFileClip

VIDEOFILE = 'video_with_good_quality.mp4'
AUDIOFILE = 'video_with_origin_language.mp4'
OUTPUTFILE = 'video_with_good_quality+origin_language.mp4'
TEST_DURATION = 215.0 # sec
AUDIO_DELAY = -1.5


# from audio attribute of the VideoFileClip object
audio2 = VideoFileClip(AUDIOFILE).audio
# video including original audio
video_a = VideoFileClip(VIDEOFILE)

#create test clips (short)
# FIRST TRY (without delay correction)
audio2_test = audio2.subclip(t_start=audio2.duration-TEST_DURATION, t_end=audio2.duration)
video_a_test = video_a.subclip(t_start=video_a.duration-TEST_DURATION, t_end=video_a.duration)

# combine test clips
video_va_a2 = video_a_test.set_audio(audio2_test)

# show
video_va_a2.ipython_display(maxduration=250, width=640)

#video_a_test.ipython_display(maxduration=250, width=640)  # proofed, but not synchronized: audio -1500 ms to correct

# close all instances
audio2.close()
video_a.close()

With mpv video player I found out that the audio stream is 1500 ms late. This was OK, because it was only a guess to get a synchonized file. Thus, I introduced a correction factor AUDIO_DELAY = -1.5 in [s]. to create the test clips:


# 2nd try (with delay correction)
audio2_test = audio2.subclip(t_start=audio2.duration-TEST_DURATION+AUDIO_DELAY, t_end=audio2.duration+AUDIO_DELAY)
video_a_test = video_a.subclip(t_start=video_a.duration-TEST_DURATION, t_end=video_a.duration)

Specifications

  • Python Version: 3.8
  • Moviepy Version: 1.0.2
  • Platform Name: Linux Mint Mate
  • Platform Version: 19.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
spfeifer222commented, Apr 29, 2020

Yes, but it’s a negative value. It’s Mathematical correct, isn’t it? However, I tried to use a posive value, but failed.

1 file is uploaded, but the second need about 30 min to finish.

0reactions
Josep-DAcommented, Oct 27, 2022

Thanks. This worked out for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Simple Ways to Sync Audio and Video - wikiHow
1. Open VLC Media Player on your computer. VLC is a free multi-platform media player that can correct out-of-sync audio and video on...
Read more >
How to Sync Audio and Video (OBS Studio Tutorial ... - YouTube
OBS Studio allows you to sync your audio and video using a feature called " sync offset". In this OBS Studio tutorial Awall...
Read more >
Sync Audio and Video in OBS for Live Streaming - YouTube
In this video I'll show you how to synchronize your audio and video in OBS. When you use a separate audio and video...
Read more >
How to Sync Audio and Video in OBS Studio - YouTube
This is an easy step by step guide to syncing audio and video captured ... Ready to Record and Stream in OBS (Some...
Read more >
The Best Way to Sync Video Sources in OBS Studio to fix Sync ...
The delay between video cameras in your live stream can become really jarring — almost impossible to watch after just a very short...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found