本文整理汇总了Python中moviepy.video.io.VideoFileClip.VideoFileClip.set_audio方法的典型用法代码示例。如果您正苦于以下问题:Python VideoFileClip.set_audio方法的具体用法?Python VideoFileClip.set_audio怎么用?Python VideoFileClip.set_audio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moviepy.video.io.VideoFileClip.VideoFileClip
的用法示例。
在下文中一共展示了VideoFileClip.set_audio方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_and_convert
# 需要导入模块: from moviepy.video.io.VideoFileClip import VideoFileClip [as 别名]
# 或者: from moviepy.video.io.VideoFileClip.VideoFileClip import set_audio [as 别名]
def download_and_convert(url):
print("converting url " + url)
source = pafy.new(url)
best = source.getbest(preftype="mp4")
ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d-%H%M%S')
input_filename = "/tmp/" + ts + "." + best.extension
best.download(filepath=input_filename)
output = VideoFileClip(input_filename)
duration = output.duration
output_filename="/tmp/" + best.title + "." + best.extension
output = output.set_audio(audio).fl_time(lambda t: t * accel, apply_to='mask').set_duration(duration / accel)
output.write_videofile(output_filename)
print("uploading to s3")
s3 = boto.connect_s3()
bucket = s3.get_bucket('bennyhill')
key = Key(bucket)
key.key = best.title + "-" + ts
key.set_contents_from_filename(output_filename)
output_url = key.generate_url(expires_in=3600)
print("complete")
# save the results
try:
result = Result(
url=url,
youtube_url=output_url
)
db.session.add(result)
db.session.commit()
return result.id
except:
errors.append("Unable to add item to database.")
return {"error": errors}