1

I'm putting together a bash script to run movie rendering jobs. ffmpeg expects a multi-line text file as one of the arguments for concatenation filter to join several files into one. Like this:

ffmpeg -f concat -i mylist.txt -c copy output

There's also an option to write it all in a single line like so:

ffmpeg -f concat -i <(printf "file '%s'\n" A.mp4 B.mp4) -c copy Output.mp4

How do I write the latter for into a bash script, substituting the file names from other variables? Tryed splitting the variables, but its not the one that works. $A and $B variables contains paths to input files.

#!/bin/bash
...
TMP_LIST=$(printf "file '%s'\n" ${A} ${B})
APPEND="${FFMPEG} -f concat -i <<< {${TMP_LIST}} -c copy ${OUTPUT}"
# run the concatenation:
$APPEND

2 Answers 2

3

Try the following:

ffmpeg -f concat -i <(printf "file '%s'\n" "$A" "$B") -c copy Output.mp4
Sign up to request clarification or add additional context in comments.

2 Comments

It works! Thank you. Is there a way to put the whole command into a variable to execute then by just calling that variable? — asking for the sake of knowledge.
@SergikS: Use a function, variables are parsed in an way that makes this sort of thing difficult. See BashFAQ #50:I'm trying to put a command in a variable, but the complex cases always fail!
2

This is one way to have a list and store the command in a variable (array) before it gets executed. Unfortunately process substitutions can only be kept alive by passing them as arguments to a function, so we have to use a function here:

#!/bin/bash

LIST_IN_ARRAYS=("$A" "$B")  ## You can add more values.

function append {
    local APPEND=("$FFMPEG" -f concat -i "$1" -c copy "$2")  ## Store the command in an array.
    "${APPEND[@]}"  ## This will run the command.
}

append <(printf "file '%s'\n" "${LIST_IN_ARRAYS[@]}") "$OUTPUT"

Although I would have done it this way to make things simpler:

function append {
    "$FFMPEG" -f concat -i <(printf "file '%s'\n" "${@:2}") -c copy "$1"
}

append "$OUTPUT" "${LIST_IN_ARRAYS[@]}"  ## Or
append "$OUTPUT" "$A" "$B"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.