Bia*_*apy 6 bash ogg audio-converter flac avconv
我正在编写一个命令行工具,将具有各种格式的输入音乐库(flac/ogg/mp3/...)转换为给定格式的输出音乐库(flac/ogg/mp3).我将它基于avconv(或ffmpeg,如果avconv不可用),因为它是我发现的最完整的命令行转换器.我的脚本可从此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
Run Code Online (Sandbox Code Playgroud)
我的问题是,当使用Ubuntu 13.10 Saucy Salamander上提供的avconv版本将flac转换为ogg时,尽管有此选项(将输入flac文件中的全局元数据复制到输出ogg文件的所有音频流),但不保留元数据:
--map_metadata:s:a 0:g
Run Code Online (Sandbox Code Playgroud)
您是否有人知道正确的--map_metadata选项,用于在转换时将元数据从flac输入文件复制到ogg输出文件?
ps:附加问题:如何防止avconv生成的CBR mp3文件有VBR标头?
pps:我知道甜菜等工具,但我还没有看到专门的命令行工具来完成这项任务.
在这里找到了修复:
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