我正在编写一个命令行工具,将具有各种格式的输入音乐库(flac / ogg / mp3 / ...)转换为给定格式的输出音乐库(flac / ogg / mp3)。我将它基于avconv(如果avconv不可用则为ffmpeg),因为它是我发现的最完整的命令行转换器。我的脚本可从此URL(GitHub)获取:
https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools
我正在尝试将元数据从输入库文件传递到输出/转换的库文件。
我想出了这段代码:
local MAP_METADATA=' 0:g'
# Specific needs for some input formats/
case "${INPUT_FILE_MIMETYPE}" in
'application/ogg' )
# Get input metadata from first audio stream and direct it to global.
MAP_METADATA=' 0:s:0'
;;
* )
# Do nothing.
# MAP_METADATA=' 0:g'
;;
esac
# Specific needs for some output formats/
local OUTPUT_OPTIONS=""
case "${OUTPUT_FORMAT}" in
'flac' )
# No encoding options needed.
ENCODING_OPTIONS=""
;;
'ogg' )
# Set vorbis as default codec for ogg.
OUTPUT_OPTIONS="-codec:a libvorbis -f ${OUTPUT_FORMAT}"
# Map input metadata to all audio streams in ogg container.
MAP_METADATA=":s:a ${MAP_METADATA}"
;;
* )
# Do nothing.
# MAP_METADATA="${MAP_METADATA}"
OUTPUT_OPTIONS="-f ${OUTPUT_FORMAT}"
;;
esac
# Dangerous solution for mp3 cbr format:
# Write output on pipe and then directed to file.
# For cbr format for mp3 files. Harmless for other formats.
# See: http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=7&t=377
#
# What about log output ? how to prevent it from being included in
# the resulting output file ?
if ! command ${AVCONV} -i "${INPUT_FILE}" \
-vn -sn \
-map_metadata${MAP_METADATA} \
-loglevel "${LOG_LEVEL}" \
${AVCONV_OPTIONS} \
${OUTPUT_OPTIONS} \
${ENCODING_OPTIONS} \
"${OUTPUT_TEMP_FILE}"; then
test "${QUIET}" != 'True' && echo "Failed."
test -e "${OUTPUT_TEMP_FILE}" && command rm "${OUTPUT_TEMP_FILE}"
return 1
else
test "${QUIET}" != 'True' && echo "Done."
# Test if fix for MP3 VBR is needed.
# See: http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=7&t=377
if [ "${OUTPUT_FORMAT}" = 'mp3' -a "${ENCODING_MODE}" != 'CBR' ]; then
# Output file is MP3 and VBR. Apply header fix.
if [ "${VERBOSE}" = 'True' ]; then
command vbrfix "${OUTPUT_TEMP_FILE}" "${OUTPUT_FILE}"
else
command vbrfix "${OUTPUT_TEMP_FILE}" "${OUTPUT_FILE}"
fi
else
# Nothing to do but rename the file.
command mv "${OUTPUT_TEMP_FILE}" "${OUTPUT_FILE}"
fi
# Delete temporary file if it is still present.
test -e "${OUTPUT_TEMP_FILE}" && command rm "${OUTPUT_TEMP_FILE}"
# Fetch cover art from input file.
transfert_images "${INPUT_FILE}" "${OUTPUT_FILE}"
fi
我的问题是,当使用Ubuntu 13.10 Saucy Salamander上提供的avconv版本将flac转换为ogg时,尽管有此选项(将输入flac文件中的全局元数据复制到输出ogg文件的所有音频流),但不保留元数据:
--map_metadata:s:a 0:g
您是否有人知道正确的--map_metadata选项,用于在转换时将元数据从flac输入文件复制到ogg输出文件?
ps:附加问题:如何防止avconv生成的CBR mp3文件有VBR标题?
pps:我知道甜菜等工具,但我还没有看到专门的命令行工具来完成这项任务。答案 0 :(得分:4)
在此处找到修复程序:
https://bugs.kde.org/show_bug.cgi?id=306895
好的--map_metadata选项是:
--map_metadata 0:s:0
--map_metadata:s:a 0:s:0
请注意,输出Ogg并输入ogg时, - map_metadata选项是相同的。
至于CBR mp3文件,此处提供的修复:http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=7&t=37(输出到管道)有效。 avconv输出日志信息到& 2。 & 1对数据是免费的。 编辑:此修复程序仅适用于CBR mp3,它会破坏需要直接输出到文件的VBR mp3。
我已将更改集成到mussync-tools 1.2.0:
https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools