IT News

유튜브 숏츠 만들기

post tistory 2023. 3. 23.
반응형

유튜브 숏츠 만들어 보려고 만든 테스트용

잘 안되고 있어서 계속 수정 중입니다. ㅠㅠ

 

코드를 잘 나가다가 에러 나오면 이상하리 만치 해매게 되네요.

코딩을 잘알못이라서 헤매면서 만들고는 있는데 막힐때 보면 정말 왜 하나 싶기도 하고

흠흠흠.

어려운 코딩을 쉽게 쉽게 풀어보려고 하는데 한계에 부딪칠때마다 포기 하고 픈 생각이 불쑥불쑥 튀어나오네요..

암튼 다시 도전...!!

 

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}")
반응형

'IT News' 카테고리의 다른 글

유튜브 숏츠 만들기 2  (0) 2023.03.23
opencv 설치하기, 파이썬, python opencv  (0) 2023.03.23
openpose editor 설치 및 사용방  (0) 2023.03.22
pip pycurl설치  (0) 2023.03.21
자동이미지 파이썬  (0) 2023.02.05

댓글

💲 추천 글