delay audio stream in ffmpeg python

250 Views Asked by At

objective:

I have separate audio and video streams. Audio stream length varies but video length is same around 60 seconds. For the first 34 seconds the audio should be empty and after 34 seconds i should play the audio according to its length and then the video should end. Generally audio length is around 15-20 seconds. I am trying to do this in ffmpeg python, i have already seen some answers on stackoverflow using itsoffset but they all were on using cmd and i can't get my head around it. Code i am working

import ffmpeg
import textwrap

readAloudText = "The medical center issued a statement saying that patient care was not compromised while their data was unavailable. Still, it's unsettling to hear that a hospital is shut out of parts of its own computer systems and unable to communicate electronically."

wrapper = textwrap.TextWrapper(width=150) 
word_list = wrapper.wrap(text=readAloudText) 
caption_new = ''
for ii in word_list[:-1]:
    caption_new = caption_new + ii + '\n'
caption_new += word_list[-1]

in_video = ffmpeg.input('readaloud.mov')
in_audio = ffmpeg.input('readaloudaudio.wav')

(
    ffmpeg
    .drawtext(in_video, text=caption_new, fontcolor='black', fontsize='24', start_number=0, x=50, y= 600)
    .output(in_audio ,'output.mp4')
    .run()
)

Thanks in advance

1

There are 1 best solutions below

0
On

i added parameter itsoffset when i bring with input check the code

import ffmpeg
import textwrap

readAloudText = "The medical center issued a statement saying that patient care was not compromised while their data was unavailable. Still, it's unsettling to hear that a hospital is shut out of parts of its own computer systems and unable to communicate electronically."

wrapper = textwrap.TextWrapper(width=150) 
word_list = wrapper.wrap(text=readAloudText, itsoffset=38) 
caption_new = ''
for ii in word_list[:-1]:
    caption_new = caption_new + ii + '\n'
caption_new += word_list[-1]

in_video = ffmpeg.input('readaloud.mov')
in_audio = ffmpeg.input('readaloudaudio.wav')

(
    ffmpeg
    .drawtext(in_video, text=caption_new, fontcolor='black', fontsize='24', start_number=0, x=50, y= 600)
    .output(in_audio ,'output.mp4')
    .run()
)