Li Yunlong two-dimensional stylized!

Li Yunlong two-dimensional stylized! You can also generate such a leader with one click of star and fork!

Rolling, selling cute, begging star, begging for fork!

The specific detailed operations are also listed step by step on AIstudio, please star and fork!

1. First find the video material you want to operate, extract the audio of the video separately for use

The resources I found myself are placed in the codes/videos/liyunlongfolder, which is Li Yunlong's famous scene:
Why don't you dare to fight with the brigade commander ! Brigadier, I knelt down for you
Brigadier, I knelt down for you

2. Not much to say, enter the code practice:

  • Install the basic environment
!pip install -r codes/PaddleGAN-develop/requirements.txt
  • Import the basic environment
import paddle 
import os 
import sys 
sys.path.insert(0,'codes/PaddleGAN-develop')
from ppgan.apps import AnimeGANPredictor

3.GAN it!

Friendly reminder : GPU environment is best used here, cpu reasoning is really a bit slow

Use paddlepaddle pre-trained animeGANv2 model to perform style transfer on the video:
from ppgan.apps import AnimeGANPredictor
import cv2

predictor = AnimeGANPredictor('',None,)
video_src = 'codes/videos/liyunlong/格式工厂混流 亮剑-03+亮剑-03+亮剑-04 00_00_23-.mp4'
video_ = cv2.VideoCapture(video_src)
video_name_ = os.path.basename(video_src)
total_frames = video_.get(cv2.CAP_PROP_FRAME_COUNT)
fps_ = video_.get(cv2.CAP_PROP_FPS)
print("video {}, fps:{}, total frames:{}...".format(video_name_, fps_, total_frames))
frame_count_ = 0
save_per_frames = 1
dst_dir = 'codes/videos/liyunlong/'
    
out_video = cv2.VideoWriter('{}/hayao_{}'.format(dst_dir, video_name_),
                                cv2.VideoWriter_fourcc(*'DIVX'), int(fps_),
                                (int(video_.get(3)), int(video_.get(4))))
print('now begin...')
while True:
    ret_, frame_ = video_.read()
    if not ret_:  # or len(fps_list_) == 0:
        print('end of video...')
        break
        
    result_frame = predictor.anime_image_only(frame_)
    if frame_count_ % save_per_frames == 0:
        out_video.write(result_frame)
    frame_count_ = frame_count_ + 1
    if frame_count_ % 100 == 0:
        print("{}/{} processed...".format(frame_count_, int(total_frames)), flush=False)
Merge the generated video and the previously separated audio:
!ffmpeg -i codes/videos/liyunlong/hayao_格式工厂混流 亮剑-03+亮剑-03+亮剑-04 00_00_23-.mp4 -i codes/videos/liyunlong/音频1.aac -c:v copy -c:a aac -strict experimental codes/videos/liyunlong/李云龙二次元化.mp4

That's it~~~
Rolling and selling cute star and fork!

Guess you like

Origin blog.csdn.net/oukohou/article/details/114936767