Roger
Roger

Reputation: 8576

Spaces in variable

I am facing some problems with spaces in variables:

ALBUM=' -metadata album="Peregrinações Alheias"'

This command:

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k "$ALBUM" -y $OUT

Returns:

Unable to find a suitable output format for ' -metadata album="Peregrinações Alheias"'

And if I take out the "" from the variable:

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $ALBUM -y $OUT

Returns:

Unable to find a suitable output format for 'Alheias"'

And I am sure I am missing something in the bash sintax...


UPDATE:

So it looks that the matter is not with spaces but with the "-metadata" argument...

The problem is that I have many metadata and I'd like to put them in just one variable. Like this:

META=' -metadata album="Peregrinações" -metadata title="Passeio ao PETAR" -metadata author="Rogério Madureira" -metadata date="2012" -metadata description="Áudio de um passeio ao PETAR" -metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '

And then:

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT

Upvotes: 2

Views: 337

Answers (5)

Peter.O
Peter.O

Reputation: 6856

Using eval can do what you want... Depending on what you have in $R_IMG, $SOUND and $OUT, they may need double-quote escaping, eg. \"$SOUND\" ....

Your $META (which I assume is another name for youur originally named $ALBUM) doesn't need to be laid out like this, but it surely helps (me) ... Just spaces, as in your original works just as well.

META='
-metadata album="Peregrinações"
-metadata title="Passeio ao PETAR"
-metadata author="Rogério Madureira"
-metadata date="2012"
-metadata description="Áudio de um passeio ao PETAR"
-metadata comment="Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS"
'; META="$(echo "$META" |sed 's|"|\\\\"|g' |tr '\n' ' ')" 

eval "ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT"

If you prefer to not use the sed conversion line, you simply need to change each " in $META to \\" as in this next example:

META=' -metadata album=\\"Peregrinações\\" -metadata title=\\"Passeio ao PETAR\\" -metadata author=\\"Rogério Madureira\\" -metadata date=\\"2012\\" -metadata description=\\"Áudio de um passeio ao PETAR\\" -metadata comment=\\"Áudio capturado com TACAM DR-07MKII e Foto capturada com Canon PowerShot S5IS" '
eval "ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k $META -y $OUT"

I've tested it successfully with the following ffmpeg encoding parameters:

eval "ffmpeg -i ~/input.flv -sameq -acodec libmp3lame -ab 128k $META -y ~/output.mp3"

Upvotes: 1

A.H.
A.H.

Reputation: 66223

If you always want to set ALBUM, then Adam's answer is OK. But if you want to optionally set ALBUM then use this:

ALBUM="Peregrinações Alheias"
TITLE="Passeio ao PETAR"
OPTIONAL=
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND \
    -acodec libmp3lame -ab 128k \
     ${ALBUM:+-metadata album="$ALBUM"} \
     ${TITLE:+-metadata title="$TITLE"} \
     ${OPTIONAL:+-metadata optional="$OPTIONAL"} \
    -y $OUT

When not setting ALBUM the complete ${var:+subst} block is omitted. Other vars are just the same of course-

Of course this scales up to several -metadata options if there is a fixed set of data you want to set.

Upvotes: 1

kev
kev

Reputation: 161604

ALBUM='album=Peregrinações Alheias'

ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND -acodec libmp3lame -ab 128k -metadata "$ALBUM" -y $OUT

Upvotes: 1

Adam Liss
Adam Liss

Reputation: 48280

Bash interprets words in quotes as a single argument. Try

ALBUM='album="Peregrinações Alheias"'
ffmpeg -i $R_IMG -r 1 -b 1800 -i $SOUND \
  -acodec libmp3lame -ab 128k -metadata "$ALBUM" -y $OUT

Upvotes: 2

Related Questions