0

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.

in a nutshell:

audio.mp3 + image.jpg = video.mp4
paij0se
  • 29
  • 4
  • https://stackoverflow.com/questions/38510694/how-to-add-album-art-to-mp3-file-using-python-3 Hope this helps – Arunbh Yashaswi Jan 05 '22 at 19:13
  • 1
    @ArunbhYashaswi that's not they are asking for whatsoever. They want to make a video (in the MP4 format) that consists of an unchanging still image (sourced from the jpg) and the audio from the MP3. – Random Davis Jan 05 '22 at 19:17
  • I found [this post](https://stackoverflow.com/questions/25891342/creating-a-video-from-a-single-image-for-a-specific-duration-in-ffmpeg) which explains how to make a video from a single image via ffmpeg. This can be done in Python via something like `os.system()`. You then just have to add the audio to it - [here](https://superuser.com/questions/590201/add-audio-to-video-using-ffmpeg) is a post explaining how to do this with ffmpeg. It might be possible to do both at once. – Random Davis Jan 05 '22 at 19:19
  • https://stackoverflow.com/questions/64375367/python-convert-mp3-to-mp4-with-static-image Like this one? – Arunbh Yashaswi Jan 05 '22 at 19:20

1 Answers1

0

I can fixed using 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
paij0se
  • 29
  • 4