簡體   English   中英

Python - 我如何將圖像與 mp3 文件結合起來?

[英]Python - How i can combine a image with an mp3 file?

我正在制作一個小腳本來自動上傳視頻。

所以腳本給我的數據,例如:

- 'I kicked all my friends off my HBO account because they were horrid to me last night and now they can’t watch the Game of Thrones premiere..jpg'
- 'I kicked all my friends off my HBO account because they were horrid to me last night and now they can’t watch the Game of Thrones premiere..mp3'

我想將這兩個文件合並為一個 mp4 文件。

簡而言之:

audio.mp3 + image.jpg = video.mp4

我可以使用 ffmpeg 進行修復。

import subprocess


def video(image_file: str, mp3_file: str, video_file: str) -> None:
    # audio.mp3 + image.jpg = video.mp4
    if image_file == "":
        print("no image")
    else:
        subprocess.call([
            "ffmpeg", "-loop", "1", "-i", image_file, "-i", mp3_file, "-c:v",
            "libx264", "-tune", "stillimage", "-c:a", "aac", "-b:a", "192k",
            "-shortest", video_file
        ])
        return None

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM