MCPcopy Index your code
hub / github.com/showlab/Code2Video / merge_videos

Method merge_videos

src/agent.py:667–701  ·  view source on GitHub ↗

Step 5: Merge all section videos

(self, output_filename: str = None)

Source from the content-addressed store, hash-verified

665 return results
666
667 def merge_videos(self, output_filename: str = None) -> str:
668 """Step 5: Merge all section videos"""
669 if not self.section_videos:
670 raise ValueError("No video files available to merge")
671
672 if output_filename is None:
673 safe_name = topic_to_safe_name(self.learning_topic)
674 output_filename = f"{safe_name}.mp4"
675
676 output_path = self.output_dir / output_filename
677
678 print(f"🔗 Start merging section videos...")
679
680 video_list_file = self.output_dir / "video_list.txt"
681 with open(video_list_file, "w", encoding="utf-8") as f:
682 for section_id in sorted(self.section_videos.keys()):
683 video_path = self.section_videos[section_id].replace(f"{self.output_dir}/", "")
684 f.write(f"file '{video_path}'\n")
685
686 # ffmpeg
687 try:
688 result = subprocess.run(
689 ["ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", str(video_list_file), "-c", "copy", str(output_path)],
690 capture_output=True,
691 text=True,
692 )
693
694 if result.returncode == 0:
695 return str(output_path)
696 else:
697 print(f"❌ Failed to merge section videos: {result.stderr}")
698 return None
699 except Exception as e:
700 print(f"❌ Failed to merge section videos: {e}")
701 return None
702
703 def GENERATE_VIDEO(self) -> str:
704 """Generate complete video with MLLM feedback optimization"""

Callers 1

GENERATE_VIDEOMethod · 0.95

Calls 1

topic_to_safe_nameFunction · 0.85

Tested by

no test coverage detected