From 7cf22df07dcb25542e8a8ef5cec1ccbdfc0032d0 Mon Sep 17 00:00:00 2001 From: Haffel Date: Tue, 9 Sep 2025 11:59:43 +0200 Subject: [PATCH] search mp4's up to one layer deep --- filename-as-metadata-title.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/filename-as-metadata-title.md b/filename-as-metadata-title.md index dca3587..6d4ecec 100644 --- a/filename-as-metadata-title.md +++ b/filename-as-metadata-title.md @@ -16,3 +16,36 @@ done echo "Metadata title set for all MP4 files in directory" ``` + + +--- + + +```bash +#!/bin/bash + +# Loop through directories one level deep +for DIR in */ ; do + # Ensure it's a directory + if [ -d "$DIR" ]; then + # Loop through mp4 files in this subdirectory + for FILE_PATH in "$DIR"*.mp4; do + # Check if the file exists + if [ ! -f "$FILE_PATH" ]; then + continue + fi + + # Extract basename without the path and extension + BASE_NAME=$(basename "$FILE_PATH" .mp4) + + # Define a temp file path + TEMP_FILE="${FILE_PATH%.*}_temp.mp4" + + # Set the metadata title using ffmpeg and then replace the original file + ffmpeg -i "$FILE_PATH" -c copy -metadata title="$BASE_NAME" "$TEMP_FILE" && mv -f "$TEMP_FILE" "$FILE_PATH" + done + fi +done + +echo "Metadata title set for all MP4 files in subdirectories." +``` \ No newline at end of file