0

Is it possible to pause the audio and video during the overlay time period? Once the audio is paused, is it possible to add a new audio track during that interval alone? remaining time original audio needs to be playing.

For example,

I am using ffmpeg to overlay multiple images in a video using the below mentioned command,

ffmpeg -i 2.mp4 -i gloves.png -i socks.png -filter_complex "[1:v]scale=320:240 [ovrl]; [0:v][ovrl]overlay=y=H-h:enable='between(t,3,8)'[v1];[2:v]scale=320:240 [ovrl1];[v1][ovrl1]overlay=y=H-h:enable='between(t,15,20)'[v2]" -map "[v2]" -map 0:a -c:a copy outputVideo.mp4

Now i need to pause the video and audio between 3-8 seconds, and play a new audio during the 3 to 8 seconds alone and continue with the old audio for the remaining time.

Kindly help me with this.

1 Answer 1

0

In order to pause audio and video, you can either loop the streams or offset the PTS.

Looping streams

loop=loop={len_frames}:size=1:start={pos_frames},setpts=N/FRAME_RATE/TB

Here, {len_frames} is the length of the loop in frames, and {pos_frames} is the position of the pause in frames. You can calculate these numbers by obtaining the framerate of the video and multiplying it with the chosen length and timestamp in seconds.

The same goes for the audio part, for which you have to use aloop and asetpts, respectively, and the sample rate in Hz. Furthermore, you have to mute the audio by setting the volume=0.

The looped video and audio streams will be longer than the originals, and you can then show the overlay on them.

As such commands are rather complex to put together, I wrote a Python program that inserts a “buffering” indicator while video and audio are paused. You can check how the loop commands are generated here.

Offset for PTS

See Gyan's answer here, which essentially does:

setpts='PTS+gte(T\,{start_time})*({shift}/TB)'

combined with -vsync vfr, where {start_time} is the time at which the frames are offset and {shift} is the shift applied.

Shifting audio

As for playing the audio during a particular time interval, you can use the -itsoffset input option to offset its start.

Or you offset the PTS of the audio stream with a fixed amount using the asetpts filter.

3
  • No need to loop the video (or audio). Offsetting timestamps is enough. See first part of stackoverflow.com/a/56525809
    – Gyan
    Jul 25, 2019 at 9:46
  • @Gyan I was thinking about that as well, but conceptually, a loop always made more sense to me. I'll include a link to your post. How would it work with an overlay though, if the PTS are irregular?
    – slhck
    Jul 25, 2019 at 10:01
  • As long as the overlay is static or occurs before timestamps are offset, it will work just as well.
    – Gyan
    Jul 25, 2019 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .