当前位置:网站首页>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!!
边栏推荐
猜你喜欢
![[] free column Android dynamic debugging GDB APP of safety](/img/e3/fd096ec64f682348cca9bbab1ec5bb.png)
[] free column Android dynamic debugging GDB APP of safety

论文分享:「FED BN」使用LOCAL BATCH NORMALIZATION方法解决Non-iid问题

放下手机吧:实验表明花20分钟思考和上网冲浪同样快乐

qq机器人账号不能发送群消息,被风控
![[免费专栏] Android安全之ZIP文件目录遍历漏洞](/img/11/c9116562b0ce57205e73fc442874d3.png)
[免费专栏] Android安全之ZIP文件目录遍历漏洞

Fully automated machine learning modeling!The effect hangs the primary alchemist!

Bi Sheng Compiler Optimization: Lazy Code Motion

三星旗舰优惠千八,苹果优惠过千,国产旗舰只降五百打发叫花子

牛客网 Verilog 在线编程题库解答(VL1~VL10)

开源一夏 | 基于若依架构的列表详情展示
随机推荐
史上最全架构师知识图谱(纯干货)
三面(技术 +HR 面试)网易,分享我的面试经验!(已拿 offer)
IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
[免费专栏] Android安全之Android工程模式
[] free column Android run Android, her - as command of safety
源码编译安装与yum和rpm软件安装详解
From functional testing to automated testing, do you know their shortcomings?
三星旗舰优惠千八,苹果优惠过千,国产旗舰只降五百打发叫花子
英赛克工控安全项目入围《钢铁行业智能制造解决方案推荐目录》
Linux上给PHP安装redis扩展
winpe工具WEPE微PE工具箱
An overview of Office 365 Groups and how to create them
论文分享:「FED BN」使用LOCAL BATCH NORMALIZATION方法解决Non-iid问题
MySQL备份与恢复
pat链表专题训练+搜索专题
AttributeError: module ‘click‘ has no attribute ‘get_os_args‘
shell脚本基础语句使用(一)
牛客网 Verilog 在线编程题库解答(VL1~VL10)
AWS CodePipeLine deploys ECS across accounts
国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...