How to synchronize audio and video stream from different sources exactly in [ms]?
See original GitHub issueExpected 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:
- Created 3 years ago
- Reactions:1
- Comments:11
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Thanks. This worked out for me.