当前位置:网站首页>Haven't tried line art videos this year??
Haven't tried line art videos this year??
2022-08-09 21:36:00 【knighthood2001】
🥰 博客首页:knighthood2001 欢迎点赞评论️ ️ 热爱python,期待与大家一同进步成长!!️ 跟我一起来巩固基础和刷题吧 |
先看后赞,已成习惯(只截取了一部分,Afraid to intercept too much,You open the card)


目录
1The original video is extracted frame by frame.py
2Raw video audio extraction.py
3-1PILBatch convert detail frame line art.py
3-2PILBatch convert edge-enhanced line art.py
5Audio and video synthesis The final full video with sound.py
前言
入门opencv,Laugh and be happy every day
The general idea is similar to the previous article,这里采用了opencv+PIL+moviepy,Finally made a line art with soundMP4.
Here I talk a little aboutPIL的知识:利用PILlibrary for simple image manipulation,The kids next door who beat the king are asking me for sketches,快上车!!
目录如下:A video needs to be prepared

The code is mainly divided into the following parts:
1The original video is extracted frame by frame
2Raw video audio extraction
3-1PILBatch convert detail frame line art 3-2PILBatch convert edge-enhanced line art
4PIL帧-视频合成
5Audio and video synthesis The final full video with sound
注:需要更改的,The author has commented in the codetodo了.
1The original video is extracted frame by frame.py
import os
import cv2
# todo
cap = cv2.VideoCapture('ikun.mp4')
fps = cap.get(cv2.CAP_PROP_FPS)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print('fps:', fps, '\n', 'width:', width, '\n', 'height:', height, '\n', 'frames:', frames)
# todo
path = 'ikun'
if not os.path.exists(path):
os.mkdir(path)
i = 0
while True:
flag, frame = cap.read()
filename = path + '/{}.jpg'.format(str(i))
print(filename)
cv2.imwrite(filename, frame)
i = i + 1
if i > int(frames):
break在上篇文章中,The author directly continues the frames extracted from the original video边缘检测Save as a picture after processing,而在这里,The author directly extracts the frames of the original video and saves them without modification.便于后续操作.
2Raw video audio extraction.py
import moviepy.editor as mp
def extract_audio(videos_file_path):
my_clip = mp.VideoFileClip(videos_file_path)
my_clip.audio.write_audiofile(f'{videos_file_path.split(".")[0]}.mp3')
# todo
extract_audio('ikun.mp4')
3-1PILBatch convert detail frame line art.py
import os
from PIL import Image
from PIL import ImageFilter
# todo 这里的pathFor the previously extracted picture frame by frame,new_pathDirectory to save for newly generated line drawings
path = 'ikun'
new_path = 'new_ikun1'
if not os.path.exists(new_path):
os.mkdir(new_path)
# Output the number of original catalog images
a = os.listdir(path)
b = len(a)
print("The number of original catalog images:", b)
for i in range(b):
'''细节'''
square = Image.open(path + "/{}.jpg".format(i))
square1 = square.filter(ImageFilter.DETAIL)
'''轮廓'''
square2 = square1.filter(ImageFilter.CONTOUR)
square2.save(new_path + "/{}.jpg".format(i))
print(new_path + "/{}.jpg".format(i))
这里笔者采用了PIL中细节+Outline way,Extract line drawings(PILExtract line drawings,An outline is required for this step)
Picture change display


3-2PILBatch convert edge-enhanced line art.py
import os
from PIL import Image
from PIL import ImageFilter
# todo 这里的pathFor the previously extracted picture frame by frame,new_pathDirectory to save for newly generated line drawings
path = 'ikun'
new_path = 'new_ikun2'
if not os.path.exists(new_path):
os.mkdir(new_path)
# Output the number of original catalog images
a = os.listdir(path)
b = len(a)
print("The number of original catalog images:", b)
for i in range(b):
'''边缘增强'''
square = Image.open(path + "/{}.jpg".format(i))
square1 = square.filter(ImageFilter.EDGE_ENHANCE)
'''轮廓'''
square2 = square1.filter(ImageFilter.CONTOUR)
square2.save(new_path + "/{}.jpg".format(i))
print(new_path + "/{}.jpg".format(i))
同样的,I just changed it herePIL的一个函数,Use edge enhancement+Outline way,You can check out my previous blog,You can also try it yourself,Try out a variety of styles.
Picture change display:

(不知道为啥,I feel this looks better)
4PIL帧-视频合成.py
import cv2
import os
size = (854, 480)
# todo pathAnd the saved video name needs to be changed according to
path = 'new_ikun1'
videowrite = cv2.VideoWriter('output_ikun1.mp4', -1, 25, size)
a = os.listdir(path)
n = len(a)
for i in range(n):
img = cv2.imread(path + "/{}.jpg".format(i))
videowrite.write(img)
videowrite.release()
print('end!')
5Audio and video synthesis The final full video with sound.py
import moviepy.editor as mp
# todo The path depends on the situation
# todo Incoming lineart video
video = mp.VideoFileClip('output_ikun1.mp4')
audio = mp.AudioFileClip('ikun.mp3')
video_merge = video.set_audio(audio)
# todo The final generated video with audio
video_merge.write_videofile('final_ikun1.mp4')
# video = mp.VideoFileClip('output_ikun2.mp4')
# audio = mp.AudioFileClip('ikun.mp3')
# video_merge = video.set_audio(audio)
# video_merge.write_videofile('final_ikun2.mp4')注:4和5are only based on3-1The line art content for making a video
总结
It's almost finished,Everyone is not familiar with the content of this article,See my previous article,里面有详细讲解.
It will be picked up next if available改为函数,It is convenient for everyone to change and use!!
注:The above content is only for discussion技术,It is convenient for everyone to be interested in it!!
边栏推荐
猜你喜欢
随机推荐
Open Source Summer | List Details Display Based on Ruoyi Architecture
ebook下载 | 《 企业高管IT战略指南——企业为何要落地DevOps》
2022深圳(软考中级)系统集成项目管理工程师报名
From functional testing to automated testing, do you know their shortcomings?
字节二面,差点倒在了MySQL上面
AttributeError: module ‘click‘ has no attribute ‘get_os_args‘
qq机器人账号不能发送群消息,被风控
重庆智博会|2022智博会到底有哪些看点?拭目以待
C#/VB.NET:从PowerPoint文档中提取文本和图片
国内市场上的 BI 软件到底有啥区别?
Linux上给PHP安装redis扩展
基于设计稿识别的可视化低代码系统实践
MFC教程
grafana docks local ldap
ThreadLocal 夺命 11 连问,万字长文深度解析
[免费专栏] Android安全之静态方式逆向APK应用浅析【手动注入smali+】+【IDA Pro静态分析so文件】+【IDA Pro基础使用讲解】
21天学习挑战赛--第四天打卡(横竖屏切换)
shell脚本基础语句使用(一)
韩国严厉监管元宇宙相关企业
图像处理部分详细目录








![[] free column Android run Android, her - as command of safety](/img/d5/771802eb57f24c1cf88657f5c5a724.png)
