Created
May 22, 2024 04:23
-
-
Save Forpetesake2/f3b411fba7b6265f5da2fe8ed04b73c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
def run_ffprobe(file_path, stream_type): | |
"""Run ffprobe and return the parsed JSON output for a specific stream type.""" | |
command = [ | |
'ffprobe', '-v', 'error', '-select_streams', stream_type, | |
'-show_entries', 'packet=pts_time,dts_time', '-of', 'json', file_path | |
] | |
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | |
return json.loads(result.stdout) | |
def check_timestamps(video_file): | |
"""Check timestamps of video and audio streams for inconsistencies.""" | |
video_data = run_ffprobe(video_file, 'v:0') | |
audio_data = run_ffprobe(video_file, 'a:0') | |
video_pts = [float(pkt['pts_time']) for pkt in video_data['packets']] | |
audio_pts = [float(pkt['pts_time']) for pkt in audio_data['packets']] | |
print("Video PTS times (first 10):", video_pts[:10]) | |
print("Audio PTS times (first 10):", audio_pts[:10]) | |
# Check for discrepancies in the start times | |
if video_pts and audio_pts: | |
video_start = video_pts[0] | |
audio_start = audio_pts[0] | |
print(f"Video start time: {video_start}") | |
print(f"Audio start time: {audio_start}") | |
if abs(video_start - audio_start) > 0.1: # Threshold for considering it a sync issue | |
print("Warning: Significant start time difference between video and audio streams.") | |
else: | |
print("No significant start time difference detected.") | |
# Check for ongoing discrepancies | |
discrepancies = [] | |
for v_pts, a_pts in zip(video_pts, audio_pts): | |
if abs(v_pts - a_pts) > 0.1: # Threshold for considering it a sync issue | |
discrepancies.append((v_pts, a_pts)) | |
if discrepancies: | |
print(f"Found {len(discrepancies)} timestamp discrepancies between video and audio streams.") | |
else: | |
print("No significant timestamp discrepancies found.") | |
if __name__ == "__main__": | |
video_file_path = 'input_video.mov' # Change this to your video file path | |
check_timestamps(video_file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment