Changes

Jump to navigation Jump to search
1,483 bytes added ,  15:26, 28 April 2025
Line 100: Line 100:  
win.close()
 
win.close()
 
core.quit()
 
core.quit()
 +
 +
</syntaxhighlight>
 +
 +
Example demonstrating how to disconnect audio from video:
 +
<syntaxhighlight lang="python" line>
 +
import os
 +
import subprocess
 +
 +
input_file = 'tick_rhythm_combined_1min.mp4'
 +
 +
directory = os.path.dirname(input_file)
 +
base_name = os.path.splitext(os.path.basename(input_file))[0]
 +
 +
output_video = os.path.join(directory, f"{base_name}_video_only.mp4")
 +
output_audio = os.path.join(directory, f"{base_name}_audio_only.wav")
 +
 +
subprocess.run(['ffmpeg', '-i', input_file, '-an', output_video])
 +
 +
subprocess.run(['ffmpeg', '-i', input_file, '-vn', '-acodec', 'pcm_s16le', '-ar', '44100', output_audio])
 +
 +
print(f"Video saved to: {output_video}")
 +
print(f"Audio saved to: {output_audio}")
 +
</syntaxhighlight>
 +
 +
Example demonstrating how to combine audio and video:
 +
<syntaxhighlight lang="python" line>
 +
import os
 +
import subprocess
 +
 +
# --- Inputs
 +
video_file = 'tick_rhythm_combined_1min_video_only.mp4'  # Your video-only file
 +
audio_file = 'mic_segment.wav'                            # Your trimmed audio
 +
output_file = 'final_synced_output.mp4'                  # Output file name
 +
 +
# --- FFmpeg command to combine
 +
subprocess.run([
 +
    'ffmpeg',
 +
    '-i', video_file,
 +
    '-i', audio_file,
 +
    '-c:v', 'copy',              # Copy video stream as-is
 +
    '-c:a', 'aac',                # Encode audio with AAC (widely compatible)
 +
    '-shortest',                # Trim to the shortest stream (prevents overhang)
 +
    output_file
 +
])
 +
 +
print(f"Synchronized video saved to: {output_file}")
    
</syntaxhighlight>
 
</syntaxhighlight>

Navigation menu