Created
May 17, 2024 15:47
-
-
Save chrisns/c5e1be38b770c56a24890404addb56b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
do_work() { | |
local dir=$1 | |
local start_time=$2 | |
local duration_to_keep=$3 | |
cd $dir | |
rm -v trimmed_*.mp4 *.txt | |
for file in *.mp4; do | |
output_file="trimmed_$file" | |
ffmpeg -y -i "$file" -ss $start_time -t $duration_to_keep -c copy "$output_file" | |
done | |
# delete small files that are probably invalid | |
find . -type f -name "trimmed_*.mp4" -size -40M -delete | |
# Create lists based on the variable part of the file names | |
for file in trimmed_*.mp4; do | |
# Extract the variable part of the filename | |
var_part=$(echo "$file" | sed -E 's/^trimmed_([^_]+-[0-9]{8}-[0-9]{6}-[0-9]{13}\.mp4)$/\1/' | sed 's/-[0-9]\{8\}-[0-9]\{6\}-[0-9]\{13\}\.mp4$//') | |
# Add the file to the corresponding list | |
echo "file '$file'" >> "$var_part.txt" | |
done | |
# Concatenate files based on the lists | |
for list in *.txt; do | |
var_part=$(basename "$list" .txt) | |
output_file="${var_part}.mp4" | |
ffmpeg -y -f concat -safe 0 -i "$list" -c copy "$output_file" | |
mv "$output_file" "../${1}_${output_file}" | |
done | |
} | |
do_work am 19 14 | |
do_work pm 11 16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment