简体   繁体   中英

delay audio stream in ffmpeg python

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

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()
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM