Search code examples
ffmpegpyffmpeg

Converting multiple ffmpeg command into one line (burn subtitle & watermark)


i'm first burning subtitles of mkv and then adding watermark which is taking so long to convert one video. It takes like x2 time i guess. For example on my current server it takes 30 min on each command. My server may not be good enough. But i was thinking if there way to do this in one command instead? will it effect the speed? i really have almost zero knowledge on ffmpeg:

here is command for burning subtitle. I'm using python for achieving this:

ffmpeg -i subtitles=/Users/Test/Desktop/test.mkv -vf subtitles=subtitles=subtitles=/Users/Test/Desktop/test.mkv -c:v libx264 -c:a aac -preset ultrafast -strict -2 /Users/Test/Desktop/test.mp4

command for adding watermark:

ffmpeg -i /Users/Test/Desktop/test.mp4 -i /Users/Test/Desktop/watermark-logo.png -filter_complex "[1][0]scale2ref=w='iw*10/100':h='ow/mdar'[wm][vid]; [vid][wm]overlay=main_w-overlay_w-5:main_h-overlay_h-5" /Users/Test/Desktop/output.mp4

If there are more ways to speed up then kindly let me know. All i want to achieve this faster and expecting best result. Thank you.


Solution

  • First apply the subtitles on the video and then feed that to scale2ref inside the complex filtergraph.

    Use

    ffmpeg -i /Users/Test/Desktop/test.mkv -i /Users/Test/Desktop/watermark-logo.png -filter_complex "[0]subtitles=/Users/Test/Desktop/test.mkv[v];[1][v]scale2ref=w='iw*10/100':h='ow/mdar'[wm][vid]; [vid][wm]overlay=main_w-overlay_w-5:main_h-overlay_h-5" -preset fast /Users/Test/Desktop/output.mp4