putting it all togeather
This commit is contained in:
+27
-15
@@ -7,6 +7,8 @@ def combine_twitch_vod_and_chat(vod_path: str, layout: str = "side-by-side", for
|
||||
Renders Twitch chat JSON to video and combines it with the source VOD.
|
||||
Provides real-time terminal feedback for all processing steps.
|
||||
"""
|
||||
threads = "8"
|
||||
|
||||
video_path = vod_path
|
||||
chat_path = video_path.replace(".mp4", "_chat.json")
|
||||
temp_chat = video_path.replace(".mp4", "_temp_chat.mp4")
|
||||
@@ -14,18 +16,25 @@ def combine_twitch_vod_and_chat(vod_path: str, layout: str = "side-by-side", for
|
||||
mask_path = video_path.replace(".mp4", "_temp_chat_mask.mp4")
|
||||
|
||||
# Step 1: Pre-flight checks
|
||||
if os.path.exists(video_chat) and force is False:
|
||||
print(f"❌ Error: Chat video allready exists: {video_chat}")
|
||||
return False
|
||||
|
||||
if not os.path.exists(video_path):
|
||||
print(f"❌ Error: Source video not found: {video_path}")
|
||||
return False
|
||||
|
||||
|
||||
if not os.path.exists(chat_path):
|
||||
print(f"❌ Error: Chat file not found: {chat_path}")
|
||||
return False
|
||||
|
||||
if os.path.exists(video_chat):
|
||||
if not force:
|
||||
print(f"❌ Error: Chat video already exists: {video_chat}")
|
||||
return False
|
||||
else:
|
||||
os.remove(video_chat)
|
||||
|
||||
if os.path.exists(temp_chat):
|
||||
os.remove(temp_chat)
|
||||
os.remove(mask_path)
|
||||
|
||||
# Step 2: Render Chat to Video
|
||||
print("====================================================")
|
||||
print("🚀 STEP 1: Rendering Chat JSON to Video Layer")
|
||||
@@ -37,18 +46,20 @@ def combine_twitch_vod_and_chat(vod_path: str, layout: str = "side-by-side", for
|
||||
f"-w 400 -h 1080 "
|
||||
f"--collision Overwrite "
|
||||
f"--temp-path download/temp "
|
||||
f"--font-size 20 "
|
||||
f"--generate-mask "
|
||||
f"--font-size 20 "
|
||||
f"--background-color #00000000 "
|
||||
f"-o {temp_chat} "
|
||||
f"-o {temp_chat}"
|
||||
)
|
||||
|
||||
if layout == "overlay":
|
||||
chat_cmd = (f"{chat_cmd} --generate-mask ")
|
||||
|
||||
if not os.path.exists(temp_chat):
|
||||
chat_success = linux.run_command(chat_cmd, look_for=["[STATUS]"])
|
||||
if chat_success:
|
||||
print("✅ Success: TwitchDownloaderCLI render chat video.")
|
||||
else:
|
||||
print(f"❌ Error: TwitchDownloaderCLI failed to render chat video. {chat_success['error']} : {chat_success['stderr']}")
|
||||
print("❌ Error: TwitchDownloaderCLI failed to render chat video.")
|
||||
os.remove(temp_chat)
|
||||
os.remove(mask_path)
|
||||
return False
|
||||
@@ -63,15 +74,16 @@ def combine_twitch_vod_and_chat(vod_path: str, layout: str = "side-by-side", for
|
||||
if layout == "side-by-side":
|
||||
ffmpeg_cmd = (
|
||||
f"ffmpeg -y -i {video_path} -i {temp_chat} "
|
||||
f"-filter_complex '[0:v][1:v]hstack=inputs=2[v]' "
|
||||
f"-map '[v]' -map 0:a? -c:a copy -preset superfast {video_chat}"
|
||||
f"-filter_complex '[1:v]scale=-1:H[scaled_chat];[0:v][scaled_chat]hstack=inputs=2[v]' "
|
||||
f"-map '[v]' -map 0:a? -c:v libx264 -crf 18 -preset slow -c:a copy "
|
||||
f"-threads {threads} {video_chat}"
|
||||
)
|
||||
elif layout == "overlay":
|
||||
ffmpeg_cmd = (
|
||||
f"ffmpeg -y -i {video_path} -i {temp_chat} -i {mask_path} "
|
||||
f"-filter_complex '[1:v][2:v]alphamerge[masked_chat];"
|
||||
f"[0:v][masked_chat]overlay=x=10:y=10[v]' "
|
||||
f"-map '[v]' -map 0:a? -c:a copy -preset superfast {video_chat}"
|
||||
f"-filter_complex '[1:v][2:v]alphamerge[masked_chat];[0:v][masked_chat]overlay=x=0:y=10[v]' "
|
||||
f"-map '[v]' -map 0:a? -c:v libx264 -crf 18 -preset slow -c:a copy "
|
||||
f"-threads {threads} {video_chat}"
|
||||
)
|
||||
else:
|
||||
raise ValueError("Invalid layout choice. Choose 'side-by-side' or 'overlay'.")
|
||||
@@ -97,4 +109,4 @@ def combine_twitch_vod_and_chat(vod_path: str, layout: str = "side-by-side", for
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
combine_twitch_vod_and_chat("download/videos/2813112936/2813112936.mp4", "overlay")
|
||||
combine_twitch_vod_and_chat("download/videos/2813112936/2813112936.mp4", "overlay", True)
|
||||
Reference in New Issue
Block a user