本文整理匯總了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}