简体   繁体   English

Python - 我如何将图像与 mp3 文件结合起来?

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

I'm making a little script to automate uploading a videos.我正在制作一个小脚本来自动上传视频。

So the data that the script give me, for example:所以脚本给我的数据,例如:

- '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'

I want to combine both files to a single mp4 file.我想将这两个文件合并为一个 mp4 文件。

in a nutshell:简而言之:

audio.mp3 + image.jpg = video.mp4

I can fixed using ffmpeg.我可以使用 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.

相关问题 如何在 python 中将文本转换为语音(mp3 文件)? - How can I convert text to speech (mp3 file) in python? 有没有一种快速的方法可以将 mp3 文件与 python 中的 mp4 文件结合起来? - Is there a fast way to combine an mp3 file with an mp4 file in python? 如何在Python中使用诱变剂将封面图片添加到mp3文件中? - How do I add cover image to a mp3 file using mutagen in Python? 如何使用 python pyttsx3 和 sapi5 将文本文件转换为 mp3 文件? - how can i convert a text file to mp3 file using python pyttsx3 and sapi5? 如何使用python将mp3文件拆分为多个部分 - How can I use python to split a mp3 file to several parts 如何在 python3.6 中将任何随机字节字符串转换为可播放的 mp3 文件? - How can I convert any random byte string to a playable mp3 file in python3.6? 如何使用 python: eyed3 比较 2 个 MP3 文件的封面? - How can I compare the cover art of 2 MP3 file using python: eyed3? 如何使用 google text-to-speech (gTTS) 保存到 MP3 文件 2 不同语言的变量? (蟒蛇) - How with google text-to-speech (gTTS) I can save to the MP3 file 2 Variables with different languages? (Python) 如何在python中仅更改.mp3的一个字母? - How can I change only one letter of .mp3 in python? 如何确定带有 Python 的 mp3 文件的比特率类型? - How can I determine the bitrate type of mp3 files with Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM