IT News

유튜브 숏츠 만들기 2

posttstory 2023. 3. 23.
728x90

유튜브 숏츠 만들기 2번째

숏츠 만들기를 시도 하고 있는데 원하는 대로 잘 되어지지가 않고 있어서 속상하네요

 

자꾸 시도 하다보니 API도 있어야 한다고 하고 좀 깊이 있는 곳까지 연습을 해야 하나봅니다.

쉽지 많은 않은 거 같아요

컴퓨터나 스마트폰으로 쉽게 만드는 방법이 있는데 구지 어렵게 만들려고 하는게 아닌지 모르겠어

import cv2
import numpy as np
import os
import pafy

# Define the URL of the YouTube short video

# Load the video using pafy
video = pafy.new(short_url).getbest(preftype="mp4")

# Define the folder name to save the puppy video
folder_name = "puppy_videos"
if not os.path.exists(folder_name):
    os.makedirs(folder_name)

# Define the video name and path to save the puppy video
video_name = "puppy_video.mp4"
video_path = os.path.join(folder_name, video_name)

# Check if the file name already exists, and if so, add a number to create a new name
if os.path.isfile(video_path):
    count = 1
    while True:
        new_video_name = f"puppy_video_{count}.mp4"
        new_video_path = os.path.join(folder_name, new_video_name)
        if not os.path.isfile(new_video_path):
            video_name = new_video_name
            video_path = new_video_path
            break
        count += 1

# Read the video frame by frame and apply a puppy filter to each frame
cap = cv2.VideoCapture(video.url)
puppy_filter = cv2.imread("puppy_filter.png")
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
out = cv2.VideoWriter(video_path, fourcc, 30.0, (640, 360))
while True:
    ret, frame = cap.read()
    if not ret:
        break
    frame = cv2.resize(frame, (640, 360))
    puppy_frame = np.where(puppy_filter > 50, frame, puppy_filter)
    out.write(puppy_frame)
    cv2.imshow("Puppy Video", puppy_frame)
    if cv2.waitKey(1) == 27:
        break

# Release the video capture, writer, and close the window
cap.release()
out.release()
cv2.destroyAllWindows()

print(f"Puppy video saved to {video_path}")

이렇게 해보니 

아쉽게도 또 다른 난관이 부딪쳐서 열심히 시도 중인대요

자꾸만 막히니 힘이 빠지네요

728x90

댓글

💲 추천 글