Skip to content

Instantly share code, notes, and snippets.

@greg-randall
Last active May 15, 2021 18:24
Show Gist options
  • Save greg-randall/a75d5a0824f609430924c737f6c6244e to your computer and use it in GitHub Desktop.
Save greg-randall/a75d5a0824f609430924c737f6c6244e to your computer and use it in GitHub Desktop.
Hardcode Subs with FFMPEG - SRT & WebVTT both seem to work.
ffmpeg -i input-without-subs.mp4 -c:v libx264 -vb 20M -c:a copy -vf subtitles=subs.srt output-with-subs.mp4
To change the font size use this one:
ffmpeg -i input.mp4 -c:a copy -c:v libx264 -vb 20M -vf "subtitles=try_1.en_us.srt:force_style='Fontsize=24'" output-with-subs.mp4
To do a two pass encode while hardcoding subs:
ffmpeg -y -i input.mp4 -vf subtitles=subs.srt -c:v libx264 -b:v 5000k -pass 1 -an -f mp4 /dev/null
ffmpeg -y -i input.mp4 -vf subtitles=subs.srt -c:v libx264 -b:v 5000k -pass 2 -c:a copy output.mp4
@agambewe
Copy link

can this be used on laravel?

@greg-randall
Copy link
Author

I don't know laravel well but in PHP you could use exec. You'd need ffmpeg installed on the server. https://www.php.net/manual/en/function.exec.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment