0

For the sake of concatenating video files, I've assembled bits of code found online into a ffmpeg bash script on Automator. It works. However, I'd like for the output file to be named after the folder the videos are in.

I've found solutions online, but none of them follow a shell script workflow. My workflow is just (with an added demanded "Get Specified Finder Items" when tested within Automator):

current_path=$(dirname "$1")
cd "$current_path"

for f in "$@"
do
    /usr/local/Cellar/ffmpeg/4.1_1/bin/ffmpeg -i concat:"$(pipeize() { local OLDIFS="$IFS";IFS='|';echo "$*";IFS="$OLDIFS";}; pipeize *.VOB)" -c copy -map "0:v?" -map "0:a?" -map "0:s?" "THIS_SHOULD_BE_THE_DIRECTORY_NAME.VOB"
done
0

I'm assuming $1 is e.g. "/path/to/filename.VOB" so $current_path would be: /path/to

So, for $filename use filename="$(basename "$current_path")" placed after: current_path="$(dirname "$1")" and then ext=".VOB" afterwards. You can then change .VOB to other extensions as needed.

Thus, change "THIS_SHOULD_BE_THE_DIRECTORY_NAME.VOB" to "${filename}${ext}" as shown below:

#!/bin/bash

current_path="$(dirname "$1")"
filename="$(basename "$current_path")"
ext=".VOB"
cd "$current_path"

for f in "$@"
do
    /usr/local/Cellar/ffmpeg/4.1_1/bin/ffmpeg -i concat:"$(pipeize() { local OLDIFS="$IFS";IFS='|';echo "$*";IFS="$OLDIFS";}; pipeize *.VOB)" -c copy -map "0:v?" -map "0:a?" -map "0:s?" "${filename}${ext}"
done
  • Thanks a lot. This works, although I believe you missed a " on filename="$(basename "$current_path")".VOB", as the script only runs on my end if I add one. Do you know how I could modify the code so that it works with any extension? I tried a bunch of workflows and edits to the code, but they all fail in different ways. I'm interested on using the same action for folders which may contain .VOB, or .m2ts, or .mkv. – firewater May 11 at 5:17
  • @firewater, I've updated the answer to address your comment, making a separate variable for the filename and extension. I do believe what I've added is quoted properly, as I've double checked it at ShellCheck. That said, your code throws some flags, so I'd suggest you use ShellCheck to see what's up. – user3439894 May 11 at 5:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .