Skip to content

Commit

Permalink
Add WebVTT-in-video-stream support (#196)
Browse files Browse the repository at this point in the history
* Fix `whisper_buffer` and `resampled_buffer` data race

`media_unpause` was causing `wisper_buffer` to be freed while
`vad_based_segmentation`/`hybrid_vad_segmentation` need that buffer
to not be modified for the duration of those calls

* Slightly improve handling for weird subtitle output filenames

* Squashed 'deps/c-webvtt-in-video-stream/' content from commit 5579ca6

git-subtree-dir: deps/c-webvtt-in-video-stream
git-subtree-split: 5579ca6dc9dcf94e3c14631c6c01b2ee4dfcf005

* Add WIP webvtt sei functionality

* Add webvtt recording/streaming settings

* Make latency_to_video_in_msecs and send_frequency_hz configurable

* Make webvtt languages configurable

* Add translation and main language separately

* Add rust CI integration
  • Loading branch information
palana authored Feb 3, 2025
1 parent fe9a521 commit b3be219
Show file tree
Hide file tree
Showing 26 changed files with 2,460 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build-project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ jobs:
restore-keys: |
${{ runner.os }}-ccache-${{ matrix.architecture }}-
- uses: actions-rust-lang/setup-rust-toolchain@v1
if: matrix.architecture == 'arm64'
with:
target: aarch64-apple-darwin

- uses: actions-rust-lang/setup-rust-toolchain@v1
if: matrix.architecture == 'x86_64'
with:
target: x86_64-apple-darwin

- name: Set Up Codesigning 🔑
uses: ./.github/actions/setup-macos-codesigning
if: fromJSON(needs.check-event.outputs.codesign)
Expand Down Expand Up @@ -197,6 +207,8 @@ jobs:
echo "pluginName=${product_name}" >> $GITHUB_OUTPUT
echo "pluginVersion=${product_version}" >> $GITHUB_OUTPUT
- uses: actions-rust-lang/setup-rust-toolchain@v1

- uses: actions/cache@v4
id: ccache-cache
with:
Expand Down Expand Up @@ -271,6 +283,8 @@ jobs:
"pluginName=${ProductName}" >> $env:GITHUB_OUTPUT
"pluginVersion=${ProductVersion}" >> $env:GITHUB_OUTPUT
- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Build Plugin 🧱
uses: ./.github/actions/build-plugin
with:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/check-format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ jobs:
uses: ./.github/actions/run-cmake-format
with:
failCondition: error

cargo-fmt:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: rustfmt
uses: actions-rust-lang/rustfmt@v1
with:
manifest-path: deps/c-webvtt-in-video-stream/Cargo.toml
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ if(DEFINED ENV{LOCALVOCAL_EXTRA_VERBOSE})
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE LOCALVOCAL_EXTRA_VERBOSE)
endif()

option(ENABLE_WEBVTT "Enable WebVTT embedding" ON)

if(ENABLE_WEBVTT)
include(cmake/BuildWebVTT.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE c_webvtt_in_video_stream)
target_compile_definitions(c_webvtt_in_video_stream INTERFACE ENABLE_WEBVTT)
endif()

target_sources(
${CMAKE_PROJECT_NAME}
PRIVATE src/plugin-main.c
Expand Down
23 changes: 23 additions & 0 deletions cmake/BuildWebVTT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include(FetchContent)

set(Rust_RUSTUP_INSTALL_MISSING_TARGET true)

if(OS_MACOS)
if("$ENV{MACOS_ARCH}" STREQUAL "x86_64")
set(Rust_CARGO_TARGET "x86_64-apple-darwin")
endif()
endif()

FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
)
FetchContent_MakeAvailable(Corrosion)

# Import targets defined in a package or workspace manifest `Cargo.toml` file
corrosion_import_crate(MANIFEST_PATH "${CMAKE_SOURCE_DIR}/deps/c-webvtt-in-video-stream/Cargo.toml" CRATE_TYPES
"staticlib" PROFILE release)

set_target_properties(c_webvtt_in_video_stream PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_SOURCE_DIR}/deps/c-webvtt-in-video-stream/target/")
6 changes: 6 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ vad_threshold="VAD Threshold"
log_level="Internal Log Level"
log_words="Log Output to Console"
caption_to_stream="Stream Captions"
webvtt_group="WebVTT"
webvtt_caption_to_stream="Add WebVTT captions to stream"
webvtt_caption_to_recording="Add WebVTT captions to recording"
webvtt_latency_to_video_in_msecs="Latency to video (milliseconds)"
webvtt_send_frequency_hz="Send frequency (Hz)"
webvtt_language_description="Language $1"
subtitle_sources="Output Destination"
none_no_output="None / No output"
file_output_enable="Save to File"
Expand Down
1 change: 1 addition & 0 deletions deps/c-webvtt-in-video-stream/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions deps/c-webvtt-in-video-stream/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.formatOnSave": true,
"evenBetterToml.formatter.reorderKeys": true,
"evenBetterToml.formatter.reorderArrays": true,
"evenBetterToml.formatter.trailingNewline": true,
"rust-analyzer.check.command": "clippy"
}
Loading

0 comments on commit b3be219

Please sign in to comment.