I use google drive.
I can use html for title and image.
But I can’t use audio mp3.
https://drive.google.com/uc?id=1Hx_TJZiPNkp_AMPJn9VTs-tDb-VrHrzI
def download_video(url: str, filename: str):
print("downloading")
r = requests.get(url)
with open(filename, 'wb') as f:
f.write(r.content)
print(f"Downloaded video saved to {filename}")
def check_status_and_download(id: str, api_key: str, path_ : str):
headers = {
'x-api-key': api_key
}
while True:
response = requests.get(f"{endpoint}/{id}", headers=headers)
response_data = response.json()
if 'response' in response_data and 'status' in response_data['response']:
status = response_data['response']['status']
print(status)
if status == 'done':
url = response.json()['response']['url']
download_video(url, path_+"video.mp4")
break
elif status == 'failed':
print(response.json())
print("Render failed with message:", response.json()['response']['message'])
break
else:
print("Unexpected response format:", response_data)
time.sleep(5) # 상태를 너무 자주 확인하지 않도록 쉬어줍니다.
def Video_Editing(path_ : str):
print("Start Video_Editing()")
# 비디오 클립과 자막을 정의하는 JSON 구조 생성
payload = {
"timeline": {
"background": "#000000",
"fonts": [
{
"src": "https://raw.githubusercontent.com/moonspam/NanumSquare/master/NanumSquareB.ttf"
}
],
"tracks": [ # 맨 위에 표시되야하는게 코드상에서 위에 있어야함.
{
"clips": [
{
"asset": {
"type": "html",
"html": "<p>양asdfasdfa김 style 가나다라마ㅏ방아민아ㅓ림나ㅓㅇ리마ㅓㅇasdf니라ㅓ미ㅓㅇㄹ</p>",
"css": "p { font-family: 'NanumSquare', sans-serif; color: #ffffff; font-size: 42px; text-align: center; }",
"width": 400,
"height": 200
},
"start": 0,
"length": 5,
"position": "bottom"
},
# {
# "asset": {
# "type": "audio",
# "src": "https://drive.google.com/uc?id=1Hx_TJZiPNkp_AMPJn9VTs-tDb-VrHrzI",
# "trim": 0,
# "volume": 1,
# "speed": 1,
# "effect": "fadeIn"
# },
# "start": 0,
# "length": 5,
# },
# {
# "asset": {
# "type": "html",
# "html": """<p>2번자막
# 2번자막아래</p>""",
# "css": "p { font-family: 'NanumSquare', sans-serif; color: #ffffff; font-size: 42px; text-align: center; }",
# "width": 400,
# "height": 200
# },
# "start": 5,
# "length": 5,
# "position": "bottom"
# },
# {
# "asset": {
# "type": "audio",
# "src": "https://drive.google.com/uc?id=1IJXFA07bxnY7jWDNz7dIAS_T7744-ARv",
# "trim": 0,
# "volume": 1,
# "speed": 1,
# "effect": "fadeIn"
# },
# "start": 0,
# "length": 5,
# },
],
},
{
"clips": [
# {
# "asset": {
# "type": "image",
# "src": "https://drive.google.com/uc?id=1IZYpjvrdCcQtJYOPPaEqqADxFSRy-Qnc",
# # https://drive.google.com/file/d/1IZYpjvrdCcQtJYOPPaEqqADxFSRy-Qnc/view?usp=sharing
# },
# "start": 0,
# "length": 5,
# "position" : "center",
# },
# {
# "asset": {
# "type": "image",
# "src": "https://drive.google.com/uc?id=1IZYpjvrdCcQtJYOPPaEqqADxFSRy-Qnc",
# },#https://drive.google.com/file/d/1IZdFelqeh3H2B42wpuCZ_gUykBT9HAgU/view?usp=sharing
# "start": 5,
# "length": 5,
# "position" : "center",
# },
{
"asset": {
"type": "audio",
"src": "https://drive.google.com/uc?id=1Hx_TJZiPNkp_AMPJn9VTs-tDb-VrHrzI",
# "trim": 0,
# "volume": 1,
# "speed": 1,
# "effect": "fadeIn"
},
"start": 0,
"length": 5,
},
],
},
]
},
"output": {
"format": "mp4",
"size": {
"width": 1024,
"height": 1792
},#resolution과 aspectratio 생략가능
# "aspectRatio": "1:2",
# "resolution": "hd"#1024x1792 hd
}
}
print(payload,"\n\n")
headers = {
'Content-Type': 'application/json',
'x-api-key': api_key
}
response = requests.post(endpoint, json=payload, headers=headers)
response_data = response.json()
# Render ID 추출
render_id = response_data['response']['id']
# 렌더링 상태 확인 및 다운로드
check_status_and_download(render_id, api_key, path_)