I have parent folder alpha part 3 which contain child folder 43. DP (Part1), 44. DP (Part2), 45. DP (Part3).
I want to merge (concat) all video file present in 43. DP (Part1) and put it into 43. DP (Part1) and give name merged (concat) file to folder name.
And as it is do for all.
alpha part 3
├── 43. DP (Part1)
│ ├── _43.1_Introduction to DP.mp4
│ ├── _43.2_What is DP_ (Definition).mp4
│ ├── _43.3_Ways of DP.mp4
│ ├── _43.4_7 Important Concepts.mp4
│ ├── _43.5_Climbing Stairs (Recursion).mp4
│ ├── _43.6_Climbing Stairs (Memoization DP).mp4
│ ├── _43.7_Climbing Stairs Variation.mp4
│ └── _43.8_Climbing Stairs (Tabulation DP).mp4
├── 44. DP (Part2)
│ ├── _44.1_Types of Knapsack problems.mp4
│ ├── _44.2_0-1 Knapsack (Recursion).mp4
│ ├── _44.3_0-1 Knapsack (Memoization).mp4
│ ├── _44.4_0-1 Knapsack (Tabulation).mp4
│ ├── _44.5_Target Sum Subset (Tabulation).mp4
│ ├── _44.6_Target Sum Subset (Code).mp4
│ └── _44.7_Unbounded Knapsack (Tabulation).mp4
├── 45. DP (Part3)
│ ├── _45.1_Coin Change (Live Class).mp4
│ ├── _45.2_Rod Cutting.mp4
│ ├── _45.3_Longest Common Subsequence (Recursion).mp4
│ ├── _45.4_LCS (Memoization).mp4
│ └── _45.5_LCS (Tabulation).mp4
Right or is any way to go this at once. Write Python code with FFmpeg.
My Python code is as follows; what do I need to adjust?
import os
import subprocess
# Function to merge videos in a folder
def merge_videos_in_folder(folder_path):
print(f"Merging videos in folder: {folder_path}")
# Use FFmpeg to concatenate all video files within the folder
cmd = [
"ffmpeg",
"-f", "concat",
"-safe", "0",
"-i", "<(find '{}' -type f -name '*.mp4' -exec echo 'file {{}}' \;)".format(folder_path),
"-c", "copy",
os.path.join(folder_path, "merged_video.mp4")
]
subprocess.run(cmd, capture_output=True, text=True)
print(f"Videos merged for folder: {folder_path}")
# Specify the directory containing folders with video files
parent_dir = "/path/to/parent_directory"
# Loop through each folder in the input directory
for folder in os.listdir(parent_dir):
folder_path = os.path.join(parent_dir, folder)
if os.path.isdir(folder_path):
# Merge videos in the current folder
merge_videos_in_folder(folder_path)
print("All videos merged successfully!")