Segment video files into smaller clips of specified duration. Parameters: org_path (str): The directory containing the original video files. dst_path (str): The directory where the segmented video files will be saved. vid_list (List[str]): A list of video file names to process.
(org_path: str, dst_path: str, vid_list: List[str], segment_duration: int = 30)
| 105 | print(f"### {idx} videos converted ###") |
| 106 | |
| 107 | def segment_video(org_path: str, dst_path: str, vid_list: List[str], segment_duration: int = 30) -> None: |
| 108 | """ |
| 109 | Segment video files into smaller clips of specified duration. |
| 110 | |
| 111 | Parameters: |
| 112 | org_path (str): The directory containing the original video files. |
| 113 | dst_path (str): The directory where the segmented video files will be saved. |
| 114 | vid_list (List[str]): A list of video file names to process. |
| 115 | segment_duration (int): The duration of each segment in seconds. Default is 30 seconds. |
| 116 | |
| 117 | Returns: |
| 118 | None |
| 119 | """ |
| 120 | for idx, vid in enumerate(vid_list): |
| 121 | if vid.endswith('.mp4'): |
| 122 | input_file = os.path.join(org_path, vid) |
| 123 | original_filename = os.path.basename(input_file) |
| 124 | |
| 125 | command = [ |
| 126 | 'ffmpeg', '-i', input_file, '-c', 'copy', '-map', '0', |
| 127 | '-segment_time', str(segment_duration), '-f', 'segment', |
| 128 | '-reset_timestamps', '1', |
| 129 | os.path.join(dst_path, f'clip%03d_{original_filename}') |
| 130 | ] |
| 131 | |
| 132 | subprocess.run(command, check=True) |
| 133 | |
| 134 | def extract_audio(org_path: str, dst_path: str, vid_list: List[str]) -> None: |
| 135 | """ |