首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

MoviePy - 中文文档4-MoviePy实战案例-重新构建15世纪舞蹈视频

  • 23-09-22 20:22
  • 2391
  • 10643
blog.csdn.net

回到目录

重新构建15世纪舞蹈视频

  1. # -*- coding: utf-8 -*-
  2. """
  3. Result: https://www.youtube.com/watch?v=Qu7HJrsEYFg
  4. This is how we can imagine knights dancing at the 15th century, based on a very
  5. serious historical study here: https://www.youtube.com/watch?v=zvCvOC2VwDc
  6. Here is what we do:
  7. 0- Get the video of a dancing knight, and a (Creative Commons) audio music file.
  8. 1- load the audio file and automatically find the tempo
  9. 2- load the video and automatically find a segment that loops well
  10. 3- extract this segment, slow it down so that it matches the audio tempo,
  11. and make it loop forever.
  12. 4- Symmetrize this segment so that we will get two knights instead of one
  13. 5- Add a title screen and some credits, write to a file.
  14. This example has been originally edited in an IPython Notebook, which makes it
  15. easy to preview and fine-tune each part of the editing.
  16. """
  17. from moviepy.editor import *
  18. from moviepy.video.tools.cuts import find_video_period
  19. from moviepy.audio.tools.cuts import find_audio_period
  20. # Next lines are for downloading the required videos from Youtube.
  21. # To do this you must have youtube-dl installed, otherwise you will need to
  22. # download the videos by hand and rename them, as follows:
  23. # https://www.youtube.com/watch?v=zvCvOC2VwDc => knights.mp4
  24. # https://www.youtube.com/watch?v=lkY3Ek9VPtg => frontier.mp4
  25. import os
  26. if not os.path.exists("knights.mp4"):
  27. os.system("youtube-dl zvCvOC2VwDc -o knights.mp4")
  28. os.system("youtube-dl lkY3Ek9VPtg -o frontier.mp4")
  29. #==========
  30. # LOAD, EDIT, ANALYZE THE AUDIO
  31. audio = (AudioFileClip("frontier.mp4")
  32. .subclip((4,7), (4,18))
  33. .audio_fadein(1)
  34. .audio_fadeout(1))
  35. audio_period = find_audio_period(audio)
  36. print ('Analyzed the audio, found a period of %.02f seconds'%audio_period)
  37. # LOAD, EDIT, ANALYZE THE VIDEO
  38. clip = (VideoFileClip("./knights.mp4", audio=False)
  39. .subclip((1,24.15),(1,26))
  40. .crop(x1=332, x2=910, y2=686))
  41. video_period = find_video_period(clip, tmin=.3)
  42. print ('Analyzed the video, found a period of %.02f seconds'%video_period)
  43. edited_right = (clip.subclip(0,video_period)
  44. .speedx(final_duration=2*audio_period)
  45. .fx(vfx.loop, duration=audio.duration)
  46. .subclip(.25))
  47. edited_left = edited_right.fx(vfx.mirror_x)
  48. dancing_knights = (clips_array([[edited_left, edited_right]])
  49. .fadein(1).fadeout(1).set_audio(audio).subclip(.3))
  50. # MAKE THE TITLE SCREEN
  51. txt_title = (TextClip("15th century dancing (hypothetical)", fontsize=70,
  52. font="Century-Schoolbook-Roman", color="white")
  53. .margin(top=15, opacity=0)
  54. .set_position(("center","top")))
  55. title = (CompositeVideoClip([dancing_knights.to_ImageClip(), txt_title])
  56. .fadein(.5)
  57. .set_duration(3.5))
  58. # MAKE THE CREDITS SCREEN
  59. txt_credits = """
  60. CREDITS
  61. Video excerpt: Le combat en armure au XVe siècle
  62. By J. Donzé, D. Jaquet, T. Schmuziger,
  63. Université de Genève, Musée National de Moyen Age
  64. Music: "Frontier", by DOCTOR VOX
  65. Under licence Creative Commons
  66. https://www.youtube.com/user/DOCTORVOXofficial
  67. Video editing © Zulko 2014
  68. Licence Creative Commons (CC BY 4.0)
  69. Edited with MoviePy: http://zulko.github.io/moviepy/
  70. """
  71. credits = (TextClip(txt_credits, color='white',
  72. font="Century-Schoolbook-Roman", fontsize=35, kerning=-2,
  73. interline=-1, bg_color='black', size=title.size)
  74. .set_duration(2.5)
  75. .fadein(.5)
  76. .fadeout(.5))
  77. # ASSEMBLE EVERYTHING, WRITE TO FILE
  78. final = concatenate_videoclips([title, dancing_knights, credits])
  79. final.write_videofile("dancing_knights.mp4", fps=clip.fps,
  80. audio_bitrate="1000k", bitrate="4000k")

一起交流,一起进步,群内提问答疑

QQ群:MoviePy中文 :819718037

回到目录

文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树首页概览333612 人正在系统学习中
注:本文转载自blog.csdn.net的ucsheep的文章"https://blog.csdn.net/ucsheep/article/details/82786267"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top