The package provides methods to handle subtitles, including adding subtitle tracks, burning subtitles into the video, and extracting subtitles.
To add a subtitle file as an input (e.g., for soft subs):
FFmpeg::fromPath('video.mp4')
->addSubtitle('subs.srt')
->subtitleCodec('mov_text') // Optional: convert to MP4 compatible format
->save('output.mp4');To burn subtitles into the video (hard subs):
FFmpeg::fromPath('video.mp4')
->burnSubtitles('subs.srt')
->save('output.mp4');Note: This uses the
subtitlesfilter. The path to the subtitle file is automatically escaped for FFmpeg.
To extract subtitles from a video file:
FFmpeg::fromPath('video.mkv')
->extractSubtitles()
->save('subs.srt');You can also specify the stream index if there are multiple subtitle tracks:
// Extract the second subtitle stream (index 1)
FFmpeg::fromPath('video.mkv')
->extractSubtitles(1)
->save('subs.srt');To simply copy subtitles from input to output without re-encoding:
FFmpeg::fromPath('video.mkv')
->subtitleCodec('copy')
->save('output.mkv');