0

Hi i want to make a video using images. Lets say i have an audio of 60 seconds and 6 images and i want my video to show images with equal durations i.e 10 second per image but i couldn't figure it out how to do it here is my code

import ffmpeg
input_audio = ffmpeg.input('./SARS/SARS.mp3')
input_still = ffmpeg.input('./SARS/*.jpg',t=20, pattern_type='glob', framerate=24)
(
    ffmpeg
    .concat(input_still, input_audio, v=1, a=1)
    .filter('scale', size='hd1080', force_original_aspect_ratio='increase')
    .output('./SARS/output.mp4')
    .run(overwrite_output=True)
)

any help is appriciated

Amandeep
  • 25
  • 6
  • `framerate` dictates how fast images are shown, so set it to be the reciprocal of the per-image duration: i.e., `framerate=0.1` in your case. Also, drop `t=20` as it'll limit the stream to only 2 images. – kesh Mar 13 '22 at 14:56
  • Also, I don't think `.concat` is what you need to use. You need to create separate audio and video streams and join them in forming the output object. I don't use `ffmpeg-python` package, but I can show you how to either as an ffmpeg cli command or using my `ffmpegio` package if you are interested. – kesh Mar 13 '22 at 15:03
  • Yes please tell me thanks, and what should i use t=? And what it means, i searched for it on google but couldn't find anything – Amandeep Mar 13 '22 at 16:23

1 Answers1

1

I'm sure you can achieve this with ffmpeg-python but you can try one of the following:

Plain CLI

ffmpeg \
  -y \
  -i './SARS/SARS.mp3' \
  -pattern_type glob -framerate 0.1 -i './SARS/*.jpg' \
  -vf scale=size=hd1080:force_original_aspect_ratio=increase \
  './SARS/output.mp4'

You can run this in Python using subprocess.run(['ffmpeg','-y',...])

ffmpegio Package

For a one-time pure transcoding need, ffmpegio is actually an overkill and directly calling ffmpeg via subprocess is more than sufficient and faster, but if you do this kind of operations often you can give it a try.

pip install ffmpegio-core
from ffmpegio.ffmpegprocess import run

run({'inputs': [
      ('./SARS/SARS.mp3', None)
      ('./SARS/*.jpg', {'pattern_type':'glob','framerate': 0.1})],
     'outputs': [
      ('./SARS/output.mp4', {'vf':'scale=size=hd1080:force_original_aspect_ratio=increase'})], 
    overwrite=True)

Essentially, it's like subprocess counterpart but takes a dict of parameters.

kesh
  • 4,515
  • 2
  • 12
  • 20