diff options
Diffstat (limited to 'stream/src/webvtt.rs')
-rw-r--r-- | stream/src/webvtt.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/stream/src/webvtt.rs b/stream/src/webvtt.rs new file mode 100644 index 0000000..74a12a5 --- /dev/null +++ b/stream/src/webvtt.rs @@ -0,0 +1,37 @@ +use anyhow::{anyhow, Context, Result}; +use jellybase::CONF; +use jellycommon::{stream::StreamSpec, LocalTrack, Node}; +use jellyremuxer::extract::extract_track; +use jellytranscoder::subtitles::webvtt_from_ass_blocks; +use tokio::io::{AsyncWriteExt, DuplexStream}; + +pub async fn webvtt_stream( + node: Node, + track_sources: Vec<LocalTrack>, + spec: StreamSpec, + mut b: DuplexStream, +) -> Result<()> { + // TODO cache + + let local_track = track_sources + .get(*spec.tracks.get(0).ok_or(anyhow!("no track selected"))?) + .ok_or(anyhow!("track does not exist"))? + .clone(); + + let codec_private = local_track + .codec_private + .clone() + .ok_or(anyhow!("ASS is missing required codec private data"))?; + + let ass_blocks = + tokio::task::spawn_blocking(move || extract_track(CONF.library_path.clone(), local_track)) + .await??; + + let webvtt = webvtt_from_ass_blocks(node.public.title, codec_private, ass_blocks) + .context("transcoding subtitles")?; + + tokio::task::spawn(async move { + let _ = b.write_all(webvtt.as_bytes()).await; + }); + Ok(()) +} |