【发布时间】:2017-09-24 20:09:54
【问题描述】:
我正在尝试将 html5 视频转换为 mp4 视频,并通过 PhantomJS 的屏幕截图来实现此目的
我也在使用 PIL 裁剪图像,所以最终我的代码大致如下:
while time() < end_time:
screenshot_list.append(phantom.get_screenshot_as_base64())
.
.
for screenshot in screenshot_list:
im = Image.open(BytesIO(base64.b64decode(screenshot)))
im = im.crop((left, top, right, bottom))
现在我正在将所有这些图像保存到光盘并使用已保存文件中的 ffmpeg:
os.system('ffmpeg -r {fps} -f image2 -s {width}x{height} -i {screenshots_dir}%04d.png -vf scale={width}:-2 '
'-vcodec libx264 -crf 25 -vb 20M -pix_fmt yuv420p {output}'.format(fps=fps, width=width,
screenshots_dir=screenshots_dir,
height=height, output=output))
但我希望能够将 PIL.Images 直接通过管道传输到 ffmpeg,而不是使用那些保存的文件,我该怎么做?
【问题讨论】:
-
ffmpeg 部分应该以
ffmpeg -f image2pipe -vcodec png -i - -vf ....开头。如果 PIL 输出正确的 PNG 语法,则不需要指定输入图像大小。 -
我指定是因为有时它不能被 2 整除,这会产生问题,所以我处理它然后指定它
-
比例过滤器参数负责 mod 2 要求。这与摄取图像无关。
-
谢谢,我会解决的
标签: python ffmpeg phantomjs python-imaging-library