Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ jobs:
env:
RUSTFLAGS: --cfg fframes_docsrs
RUSTDOCFLAGS: --cfg docsrs -D warnings
run: cargo doc --no-deps -p fframes-media -p fframes --features fframes/cli,fframes/captions,fframes/compile-time-svgtree,fframes/exif,fframes/3d
run: cargo doc --no-deps -p fframes-media -p fframes --features fframes/cli,fframes/captions,fframes/srt,fframes/compile-time-svgtree,fframes/exif,fframes/3d

release:
# A push to main publishes a nightly, a v* tag publishes that version (scripts/release-version.sh)
Expand Down Expand Up @@ -362,7 +362,7 @@ jobs:
cargo clippy $PACKAGES --tests -- -D warnings

- name: Unit tests
run: cargo test -p fframes -p fframes-media -p webvtt-parser -p fframes-media-dir-macro --features fframes/captions
run: cargo test -p fframes -p fframes-media -p webvtt-parser -p fframes-media-dir-macro --features fframes/captions,fframes/srt

- name: Render a video
run: cargo test -p e2e-tests --test render_smoke -- --nocapture
Expand Down
Binary file added e2e/snapshots/captions/7.8s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/captions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024"
publish = false

[dependencies]
fframes = { workspace = true, features = ["cli", "captions", "compile-time-svgtree"] }
fframes = { workspace = true, features = ["cli", "captions", "srt", "compile-time-svgtree"] }
serde = { version = "1", features = ["derive"] }

[features]
Expand Down
4 changes: 4 additions & 0 deletions examples/captions/media/outro.srt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1
00:00:07,650 --> 00:00:09,000
The same captions also load
from a SubRip (.srt) file.
14 changes: 11 additions & 3 deletions examples/captions/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! A small captions example: one media track, four presets and a typed word highlight.
//! A small captions example: one media track, four presets and a typed word highlight,
//! then a closing line loaded from an SRT file through the same media path.
use fframes::captions::{CaptionMode, CaptionRect, Captions};
use fframes::{AudioMap, Duration, FFramesContext, Frame, Svgr, Video, include_media_dir, svgr};

Expand All @@ -13,6 +14,7 @@ enum Highlight {

pub struct CaptionVideo {
modes: [Captions; 4],
outro: Captions,
}

impl Default for CaptionVideo {
Expand All @@ -33,6 +35,11 @@ impl Default for CaptionVideo {
.upcoming_fill("#64748b")
.outline("#0c1423", 2.0)
}),
outro: Captions::from_media("outro.srt", CaptionRect::new(1010.0, 40.0, 820.0, 130.0))
.font("DM Sans", 44)
.font_weight(500)
.active_fill("#f4f7fb")
.outline("#0c1423", 2.0),
}
}
}
Expand All @@ -43,7 +50,7 @@ impl Video for CaptionVideo {
const HEIGHT: usize = 1080;

fn duration(&self) -> Duration<'_> {
Duration::Seconds(8.0)
Duration::Seconds(9.0)
}

fn audio(&self) -> AudioMap<'_> {
Expand Down Expand Up @@ -72,6 +79,7 @@ impl Video for CaptionVideo {
let karaoke = self.modes[1].render(&mut frame, ctx);
let reveal = self.modes[2].render(&mut frame, ctx);
let word = self.modes[3].render(&mut frame, ctx);
let outro = self.outro.render(&mut frame, ctx);
svgr!(
<svg xmlns="http://www.w3.org/2000/svg" width="1920" height="1080" viewBox="0 0 1920 1080">
<rect width="1920" height="1080" fill="#0c1423" />
Expand All @@ -85,7 +93,7 @@ impl Video for CaptionVideo {
<text x="1010" y="640">"WORD"</text>
</g>
</g>
{highlight}{karaoke}{reveal}{word}
{highlight}{karaoke}{reveal}{word}{outro}
</svg>
)
}
Expand Down
2 changes: 1 addition & 1 deletion fframes-editor-controller/src/wasm_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<TVideo: Video, TMedia: StaticMediaProvider<'static> + 'static> WasmEditor<T
.insert(file.clone(), fframes::AudioData::Preloaded(audio_data));
}

/// Parse VTT or JSON through the shared subtitle parser and register the owned result.
/// Parse VTT, SRT or JSON through the shared subtitle parser and register the owned result.
pub fn add_subtitles_source(&self, file: String, content: String) -> Result<usize, JsValue> {
use fframes::media::FFramesSubtitles;

Expand Down
1 change: 1 addition & 0 deletions fframes-editor/src/services/mediaLoader.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion fframes-editor/src/services/mediaLoader.res
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ let processDynamicMedia = (
} else {
switch name->Js.String.toLowerCase->Js.String.split(".")->Utils.Array.last {
| Some("mp3" | "aac" | "ogg" | "wav" | "pcm" | "flac") => Some(resolveAudio)
| Some("vtt") => Some(resolveSubtitles)
| Some("vtt" | "srt") => Some(resolveSubtitles)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
| Some("json") => Some(resolveJson)
| Some("ttf" | "otf") => Some(resolveFont)
| Some("png" | "jpg" | "jpeg") => Some(resolveImage)
Expand Down
2 changes: 2 additions & 0 deletions fframes-media/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ ffmpeg-sys-fframes = { workspace = true, features = ["build", "static"] }
# by default we enable only platform specific encoders that
# would be always populated by the platform sysroot itself
default = []
# SubRip (`.srt`) subtitles: `CaptionTrack::from_srt` and detection in `CaptionTrack::parse`
srt = []
# Preserve prebuilt downloads and omit host CPU flags when building from source.
build-portable = ["ffmpeg-sys-fframes/build-portable"]
# enable various encoder & decoders libraries
Expand Down
3 changes: 3 additions & 0 deletions fframes-media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ mod error;
mod font;
mod images;
mod raw_file;
// Detection is always compiled so that SRT input without the feature gets a clear error.
#[cfg_attr(not(feature = "srt"), allow(dead_code))]
mod srt;
pub mod subtitles;
mod subtitles_data;
mod video_types;
Expand Down
Loading