Use Python to quickly create clipping draft tracks and automatically generate videos

Use Python to quickly create clipping draft tracks and automatically generate videos

insert image description here

1. Implementation principle

Implementation principle: JianYingProThe project file is jsonstored in the form of , only needs to be created draft_content.json, and draft_mate_info.jsonit will be automatically completed after opening the software.

Function: Quickly generate drafts, which can complete a relatively rough edit and improve efficiency.

2. A simple example

This library can help you quickly and automatically identify audio and video and add them to the corresponding track. After the draft is automatically generated, it can be edited automatically.

  1. Add a media to track order 草稿媒体库-> 内容媒体库->轨道片段
  2. add_media_to_trackIt will identify the media type and add it to the corresponding track.
  3. When there is no video track, creating an audio track will create a video track first.
if __name__ == "__main__":
    # 新建草稿
    draft = Draft("测试草稿") 
    # 将媒体转化为草稿素材
    audio = Material("D:/Music/Krubb Wenkroist - Bleach.mp3")
    # 将媒体添加到轨道中
    draft.add_media_to_track(audio)
    draft.add_media_to_track('D:/Videos/剪印导出/测试1(1).mp4')
    # 保存草稿
    draft.save()

Modify before using main.pythe draft folder path in

drafts_folder = "D:/JianyingPro Drafts"

3. Complete test code

Can support adding drum beats and cropping video

import random
import os
import selenium
from draft import Draft
from draft import Material

# 新建项目
draft = Draft("测试草稿")
# 选择背景音乐并添加鼓点
audio = "D:/Music/Krubb Wenkroist - Bleach.mp3"
draft.add_media_to_track(audio)
# 读取鼓点
beats = draft.content_materials['beats'][0]['user_beats']
# 加载视频
files= []
for pt in os.listdir('D:/myCode/Python/spider/douyin_spider/media/video/小仙儿'):
    file_path = os.path.join('D:/myCode/Python/spider/douyin_spider/media/video/小仙儿',pt)
    files.append(file_path)
# 随机裁切视频为合适时长
end = 0
for beat in beats:
    duration = beat - end
    mate = Material(files[random.randint(0,len(files)-1)])
    start = int(random.uniform(0,(mate.duration-duration)/1000))*1000
    Draft.add_media_to_track(mate,start,duration)
    end = beat
# 保存草稿
draft.save()

4. Complete code download

https://download.csdn.net/download/huangbangqing12/88136001

Guess you like

Origin blog.csdn.net/huangbangqing12/article/details/132025526