Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用bash在ffmpeg中添加带空格的mp3元数据_Bash_Ffmpeg_Youtube Dl - Fatal编程技术网

使用bash在ffmpeg中添加带空格的mp3元数据

使用bash在ffmpeg中添加带空格的mp3元数据,bash,ffmpeg,youtube-dl,Bash,Ffmpeg,Youtube Dl,我在下载youtube视频时使用了这个bash脚本,然后使用youtube dl和ffmpeg将其转换为mp3 #!/bin/bash ytlink="" outputFileName="" title="" artist="" album="" while getopts l:o:t:r:b: flag; do case "${flag}" in l) ytlink="${OPTARG}";; o) outputFileName="${OPTARG}";; t)

我在下载youtube视频时使用了这个bash脚本,然后使用youtube dl和ffmpeg将其转换为mp3

#!/bin/bash

ytlink=""
outputFileName=""
title=""
artist=""
album=""

while getopts l:o:t:r:b: flag; do
  case "${flag}" in
    l) ytlink="${OPTARG}";;
    o) outputFileName="${OPTARG}";;
    t) title="${OPTARG}";;
    r) artist="${OPTARG}";;
    b) album="${OPTARG}";;
  esac
done

youtube-dl "$ytlink" --add-metadata --extract-audio --audio-format mp3 --output "temp.%(ext)s"

tempFilename="temp.mp3"
outputFileName="$outputFileName.mp3"

args+=("-i" "$tempFilename" "-metadata" "title='$title'" "-metadata" "artist='$artist'" "-metadata" "album='$album'" "-metadata" "comment=Source:$ytlink")
ffmpeg -loglevel debug ${args[@]} -acodec copy "$outputFileName"
rm "$tempFilename"
如果我有一个单词title/artist/album,这个脚本就可以了。但是,如果我有一个空格,ffmpeg将空格前的每个单词解释为另一个参数。以下是我在命令行中使用此命令的方式:

/yttomp3.sh-l”https://www.youtube.com/watch?v=KwQnSHAilOQ“-o“Lee-秋季节”-t“秋季节”-r“Lee”-b(免费)低保真型节拍-秋季节”

ffmpeg的调试输出:

Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input url with argument 'temp.mp3'.
Reading option '-metadata' ... matched as option 'metadata' (add metadata) with argument 'title='Autumn'.
Reading option 'Day'' ... matched as output url.
Reading option '-metadata' ... matched as option 'metadata' (add metadata) with argument 'artist='Lee''.
Reading option '-metadata' ... matched as option 'metadata' (add metadata) with argument 'album='(Free)'.
Reading option 'Lo-fi' ... matched as output url.
Reading option 'Type' ... matched as output url.
Reading option 'Beat' ... matched as output url.
Reading option '-' ... matched as output url.
Reading option 'Autumn' ... matched as output url.
Reading option 'Day'' ... matched as output url.
Reading option '-metadata' ... matched as option 'metadata' (add metadata) with argument 'comment=Source:https://www.youtube.com/watch?v=KwQnSHAilOQ'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'copy'.
Reading option 'Lee - Autumn Day.mp3' ... matched as output url.
Finished splitting the commandline.

我试着在脚本中用引号括起参数,但仍然不起作用。我该如何处理这件事?谢谢。

你正在竭尽全力构建一个数组,并仔细引用你所有的字符串。。。然后不引用数组

您想在“${args[@]}”周围加双引号

请查看: