Add subtitle support for the web video player
Is your feature request related to a problem? Please describe.
When playing video files (like MP4s) that contain embedded subtitles, there is no way to view them. I understand this is a fundamental limitation of web browsers, which cannot render embedded subtitle streams directly from a video file.
Describe the solution you'd like
-
Probe for Subtitles: When a video page is requested, use
ffprobeor a similar tool to detect if and which subtitle tracks are embedded in the video file. Also search for [filename][.lang][.vtt/.srt], to find external files. -
Insert
<track>Tags: For each detected subtitle track, dynamically generate and insert an HTML<track>tag into the<video>element. Thesrcattribute for each tag should point to a unique URL that signals to extract that specific track (e.g.,src=".../video.mp4?sub-track=1&format=vtt"). -
On-Demand VTT Generation: When the browser requests one of these
srcURLs (i.e., when the user selects a subtitle), copyparty should useffmpegto extract only the requested subtitle track on-the-fly, convert it to the WebVTT (.vtt) format, and serve it directly to the browser. In case of external .srt file it could be converted usingffmpeg.
The generated HTML for the player could look something like this to make the subtitles available to the browser:
<video controls>
<source src="my-video.mp4" type="video/mp4" />
<track
label="English"
kind="subtitles"
srclang="en"
src="path/to/video.mp4?sub-track=0&format=vtt" />
<track
label="Deutsch"
kind="subtitles"
srclang="de"
src="path/to/video.mp4?sub-track=1&format=vtt" />
</video>
Key Advantage: The primary benefit of this approach is the seamless user experience. The user doesn't have to manually create or manage extra subtitle files, which are, as standalone files, of no interest to them. Instead, subtitles are simply available in the browser where they are needed, reducing the manual preparation effort for a media library to zero, while still allowing for external subtitles if that's what the user already has.
Describe alternatives you've considered
I attempted a manual workaround by extracting the subtitles myself and placing the .vtt and .srt files in the same directory, using the same filename as the video (e.g., my-movie.mp4 and my-movie.vtt).
However, this approach does not work because these files do not automatically get detected and the required <track> tags in the HTML do not get generated. As a result, the browser is never made aware of the external subtitle files.