#!/bin/bash

# Iterate over each subfolder in the current directory
for dir in */ ; do
    # Remove the trailing slash from directory name
    dirname="${dir%/}"
    # Look for the first mp4 file in the subfolder
    mp4file=$(find "$dir" -maxdepth 1 -type f -iname '*.mp4' | head -n 1)
    if [ -n "$mp4file" ]; then
        # Output file will be named after the folder, with .mp4 extension
        rm -rf "${dirname}/${dirname}.mp4"
        output="${dirname}/${dirname}.mp4"
        # Remove first 60 seconds using ffmpeg
        ffmpeg -y -i "$mp4file" -ss 60 -map_metadata -1 -c copy "$output"
        echo "Processed '$mp4file' -> '$output'"
    else
        echo "No mp4 file found in $dir"
    fi
done