![](/img/trans.png)
[英]Is there a JavaScript / HTML5 code that can convert any video format to mp4 format, and then upload it to a storage server for viewing on any client?
[英]Is there a way to convert HTML div to a video format (MP4 or any other) in Python/Django?
我正在尝试渲染 HTML 页面并在其中使用特定的<div>
将其转换为视频格式。
解释:
我知道 HTML 是 static 内容,但我有必要将其转换为视频格式(这是一项要求)。 我需要知道是否有一种方法可以渲染页面并将其导出为视频格式。 它可以是直接的 HTML 到 MP4 的转换,也可以将渲染的 div(不记录画布)捕获为图像,然后将该图像转换为视频格式。
技术栈:
Django
Django 模板
HTML
Javascript
任何帮助,将不胜感激。
这是一个粗略的过程:(请注意,我只是从我的代码中复制了“想法”并删除了我的特定内容,因此可能存在拼写错误或小不一致)
import imgkit
from moviepy import editor
# Step 1: render html to PNG
context = { ....}
rendered_html = Render_to_string('path/template.html', context)
# make sure that 'width' matches width in your html ... otherwise will be stretched
options = {'format': 'png', 'width': 670, 'disable-smart-width': ''}
imgkit.from_string(rendered_html,'path/tmp.png',
config=config, options=options)
# Step 2: create video from png and mp3
audio = editor.AudioFileClip('path/audio.mp3')
video = editor.ImageClip('path/tmp.png')
video.fps = 1
video.duration = audio.duration
final_video = video.set_audio(audio)
final_video.write_videofile('path/video.mp4', fps=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.