Zedd
Zedd

Reputation: 204

How to solve the problem of low performance of complex video generation using ffmpeg?

I use ffmpeg to generate a complex video.

This video consists of the following materials:

  1. Original video

  2. Video dub

  3. Background music

  4. Subtitle

My code logic is as follows

  1. Combine 'Original video' and 'Video dub' into 'Video A'

  2. Subtitle 'Video A' as 'Video B'

  3. Add 'Background music' for 'Video B' as 'Video C'

The 'Video C' is the video I want.

My Code

// Step1:
ffmpeg -i VideoDub.mp3 -i OriginalVideo.mp4 VideoA.mp4
// Step2:
ffmpeg -i VideoA.mp4 -vf subtitles=Subtitle.srt -y VideoB.mp4
// Step3:
ffmpeg -i VideoB.mp4 -i BackgroundMusic.mp3 -filter_complex "[1:a]aloop=loop=-1:size=2e+09[out];[out][0:a]amix" -ss 0 -t 100 -y VideoC.mp4

Design defect

My Question

How to solve the above problem?

Upvotes: 0

Views: 230

Answers (1)

Gyan
Gyan

Reputation: 92928

Use a filter_complex to perform all filtering in one command.

ffmpeg -i OriginalVideo.mp4 -i VideoDub.mp3 -stream_loop -1 -i BackgroundMusic.mp3 -filter_complex "[0:v]subtitles=Subtitle.srt;[2][1]amix" -ss 0 -t 100 VideoC.mp4 -y

Upvotes: 2

Related Questions