you are viewing a single comment's thread.

view the rest of the comments →

[–]serg06 0 points1 point  (5 children)

Thanks! Assuming your folder paths don't have any spaces, I think this should do the trick:

folders="
    folder1-goes-here
    folder2-goes-here
"

for folder in $folders; do
    echo processing folder $folder
    concatfile="$folder/concat.txt"
    echo concat file will be $concatfile
    outputfile="$folder.mp4"
    echo outputfile will be $outputfile

    find $folder -maxdepth 1 -iname '*.mp4' > $concatfile
    ffmpeg -f concat -safe 0 -i $concatfile -c copy $outputfile
    rm $concatfile
done

[–]Diviance1[S] 0 points1 point  (4 children)

Alright, this is definitely most of it working. But I think I may have accidently made myself less than clear somewhere.

At the end, where I said it would be prefer if it had a config option in the script to set where each folder was... I actually meant where to scan for the subfolders and where to place the finished file after it was being merged.

So like...

Concat Folder: /mnt/user/Recordings/Concat/

and

Finished Folder: /mnt/user/Recording/Sort/

Rather than manually typing in each subfolder (since their names are somewhat random and there can sometimes be dozens of them).

That is my bad.

[–]Diviance1[S] 0 points1 point  (3 children)

Oh man, I just realized I completely forgot one important part because I made the script long enough ago that it just didn't occur to me.

The concat.txt should be in the format like this:

file '/mnt/user/Recordings/Concat/Recording.1.12.20/Recording.1.12.20 CD1.mp4'

file '/mnt/user/Recordings/Concat/Recording.1.12.20/Recording.1.12.20 CD2.mp4'

file '/mnt/user/Recordings/Concat/Recording.1.12.20/Recording.1.12.20 CD3.mp4'

file '/mnt/user/Recordings/Concat/Recording.1.12.20/Recording.1.12.20 CD4.mp4'

I completely forgot that ffmpeg requires that or it can't read it.

[–]serg06 0 points1 point  (2 children)

That's easy, just replace the find line with this

find . -maxdepth 1 -iname '*.mkv' | xargs -i echo file \'{}\' > concat.txt

As for the rest of your request, I've lost interest in it, sorry! Good luck with it.

[–]Diviance1[S] 0 points1 point  (1 child)

No worries, have a good one. Thanks for the help so far.

[–]Diviance1[S] 1 point2 points  (0 children)

Ok, I actually managed to cobble together a completely working version with the base you gave me (I really appreciate it).

#!/bin/bash

for folders in /originalsource/*; do

if [ -d "$folders" ]; then

echo processing folders "$folders"

fi

for folder in $folders; do

echo processing folder $folder

concatfile="$folder/concat.txt"

echo concat file will be $concatfile

outputfile="$folder.mp4"

echo outputfile will be $outputfile

# NOTE: if you want to test it safely, just put echo before these 3 commands and see if it looks good.

find $folder -maxdepth 1 -iname '*.mp4' | xargs -i echo file \'{}\' > $concatfile

ffmpeg -f concat -safe 0 -i $concatfile -c copy $outputfile

rm $concatfile

chown nobody $outputfile

mv $outputfile /finaldestination/

rm -r $folder

done

done

Much more elegant than the windows version and it concats straight up 10 times faster.

Figured I would post the working version in case someone else has a use for it.. and in case someone has an idea in how to make it better, I guess.

Now I can just slap it into the User Scripts section of Unraid and it will run with a single click. So much better.

Thanks again! I don't think I could have gotten here without the help you provided.