将 BMP + WAV 转换为视频 (XviD) 的脚本实用程序?
Posted
技术标签:
【中文标题】将 BMP + WAV 转换为视频 (XviD) 的脚本实用程序?【英文标题】:Scriptable utility to convert BMPs + WAV to video (XviD)? 【发布时间】:2009-12-15 20:18:41 【问题描述】:我正在寻找一种可编写脚本的实用程序来将一堆 BMP 和 WAV 文件转换为视频。 XviD 需要是输出格式。如果可能的话,我希望它可以在 Linux (Ubuntu) 上运行。命令行实用程序会很棒,因为我有 36 个视频要以这种方式创建。 bash
(或[在此处插入最喜欢的脚本语言])脚本将非常适合。 (我还需要玩不同的视频尺寸,但我可以使用其他程序来调整大小。)
我使用过 VirtualDub(适用于 Windows XP),但它似乎不能满足这些需求。不过,我可能是错的。任何指向示例的指针都会很棒。
我也在玩ffmpeg
。它似乎完全符合要求,但我似乎无法将 BMP 整合到视频中。这是我正在尝试的:
for directory in $BMP_DIRECTORY_PATH/*
do
ffmpeg \
-f image2 \
-i "$directory/Sequence %d%d%d%d%d%d.bmp" \
-r 29.97 \
-vcodec mpeg4 \
-vtag xvid \
\
-i "$file/audio.wav" \
-acodec libmp3lame \
\
$(basename $directory.avi)
done
这就是它的回复:
[...]
FFmpeg version 0.5-svn17737+3:0.svn20090303-1ubuntu6, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --extra-version=svn17737+3:0.svn20090303-1ubuntu6 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --disable-stripping --disable-vhook --enable-libdc1394 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Apr 10 2009 23:18:41, gcc: 4.3.3
[image2 @ 0x97e5ac0]Could not find codec parameters (Video: bmp)
/home/ben/Pending/1080p_export/6/Sequence %d%d%d%d%d%d.bmp: could not find codec parameters
我已经看到关于此的 mailing list post,但建议的内容似乎在这里不起作用。
更新
这是包含多个步骤的更新脚本:
#!/usr/bin/env bash
# bmp+wav2xvid+mp3
#
# Although it has a cryptic name, it's pretty descriptive. This script consumes BMPs (Windows bitmaps) and WAVs (Microsoft AD-PCM Waveforms) to make an XviD (MPEG-4 video) movie.
#
# By convention, you pass it a directory with one or more directories that contain:
#
# * Frames named "frame_001.bmp", "frame_002.bmp", etc.
# * Audio named "audio.wav"
#
# Author: Benjamin Oakes
# FIXME: The audio doesn't get muxed correctly. The A/V sync is off a little. At the beginning it looks pretty okay, but by the end the mouths definitely don't match up with the words that are said.
#############################################################
# NOTE: SEE `ffmpeg -formats` for a list of available formats
#############################################################
# BMP_DIRECTORY_PATH="/home/ben/Outbox/ffmpeg.fixture/"
BMP_DIRECTORY_PATH="/media/Archival Data/Video Projects Backup/Video Projects/1080p_export_dual_gray/"
# Output settings
VTAG="xvid"
VCODEC="mpeg4"
ACODEC="libmp3lame"
DIMENSIONS="1000x562"
FPS="35"
CONTAINER="avi"
if [ -d "$BMP_DIRECTORY_PATH" ]; then
echo "BMP directory exists"
# for directory in "$BMP_DIRECTORY_PATH"/*
# do
directory="/media/Archival Data/Video Projects Backup/Video Projects/1080p_export_dual_gray/1"
ffmpeg \
-f image2 \
-i "$directory/frame_%03d.bmp" \
-vcodec mpeg1video \
-sameq \
\
-r $FPS \
"../tmp/$(basename "$directory.mpg")"
ffmpeg \
-i "../tmp/$(basename "$directory.mpg")" \
-vcodec $VCODEC \
-vtag $VTAG \
-s $DIMENSIONS \
-sameq \
\
-i "$directory/audio.wav" \
-acodec $ACODEC \
-ar 8000 \
\
-f $CONTAINER \
-r $FPS \
"../tmp/$(basename "$directory")-$VTAG-$VCODEC-$ACODEC-$DIMENSIONS-$FPS.$CONTAINER"
# done
else
echo "ERROR: BMP directory does not exist"
fi
更新 2
请查看我的回答,了解我最终开始工作的原因。
【问题讨论】:
【参考方案1】:我认为你试图一次做太多事情。尝试将任务分解为三个独立的动作:
从 bmp 图像创建视频 音频中的多路复用器 编码为目标格式为此,我建议使用 mpeg1 作为中间视频格式。
【讨论】:
这很有帮助——我发布了上面的更新脚本。不过,我在混合音频时遇到了问题。 (A/V 同步已关闭。) 关于导致 A/V 同步问题的任何想法?我正在考虑对此提出一个新问题。 他们减了多少?不到 1 秒,但仍然疼痛?添加的剪辑越多,问题就越严重吗?你做了多少剪辑?是的,可能最适合提出新问题。但我会先分析各个组件的长度,然后再连接和重新混合。您应该能够修剪/填充音频以使其完全匹配。可能还有其他技术。是的...另一个问题... 如果您正在动态调整音频速率,那么您可能会遇到问题。尝试保留本机音频速率。 (视频也一样。)调整任一速率闻起来可能会导致同步错误...一定要四舍五入...【参考方案2】:这是我整理出来的,仅供参考。
# bmp+wav2xvid+mp3
#
# Although it has a cryptic name, it's pretty descriptive. This script consumes BMPs and WAVs to make an XviD (MPEG-4 video) movie.
#
# By convention, you pass it a directory with one or more directories that contain:
#
# * Frames named "frame_001.bmp", "frame_002.bmp", etc.
# * Audio named "audio.wav"
#
# Author: Benjamin Oakes
# Output settings
VTAG="xvid"
VCODEC="mpeg4"
ACODEC="libmp3lame"
ABITRATE="128k"
QSCALE="1"
DIMENSIONS="1000x562"
FPS="24000/1001"
CONTAINER="avi"
if [ -d "$BMP_DIRECTORY_PATH" ]; then
echo "BMP directory exists"
for directory in "$BMP_DIRECTORY_PATH"
do
ffmpeg \
-f image2 \
-r 24000/1001 \
-i "$directory/frame_%03d.bmp" \
\
\
-i "$directory/audio.wav" \
\
\
-vcodec $VCODEC \
-vtag $VTAG \
-qscale $QSCALE \
-s $DIMENSIONS \
-r $FPS \
\
-acodec $ACODEC \
-ab $ABITRATE \
\
"../tmp/$(basename "$directory").avi"
done
else
echo "ERROR: BMP directory does not exist"
fi
【讨论】:
以上是关于将 BMP + WAV 转换为视频 (XviD) 的脚本实用程序?的主要内容,如果未能解决你的问题,请参考以下文章