我目前正在编写一个命令行工具,用于将具有各种格式(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
你们中有人知道在转换时将元数据从 flac 输入文件复制到 ogg 输出文件的正确 --map_metadata 选项吗?
ps:附加问题:如何防止avconv生成的CBR mp3文件有VBR头?
pps:我知道诸如甜菜之类的工具,但我还没有看到专门的命令行工具来完成这项任务。