Tuesday, November 24, 2026SubscribeMastheadAbout
Cali ReporterCalifornia · National · West Coast · Good News

Advertisement

Technology

Local Captioning Workflow in Browser-Based Tools

A detailed explanation of the technical steps involved in creating captioned MP4s using a browser-based application, focusing on the audio processing, transcription, and video rendering pipeline.

Portrait of Benjamin Boyce
Artificial Intelligence & Technology · November 24, 2026
Share

AI-generated editorial illustration from an imagined camera angle.
AI-generated editorial illustration from an imagined camera angle. Source image: dev.to.

The process of generating captioned MP4s in a browser-based application begins with decoding the audio from the input video file. The audio is converted to a 16 kHz mono Float32 PCM format, which is necessary for the speech recognition pipeline. This step involves handling various sample rates and audio codecs, with a fallback streaming decoding path for memory-constrained cases. The decoded audio is stored as a large ArrayBuffer, which requires careful memory management to avoid excessive memory use (1). [1]

The transcription process is handled in a Web Worker using the Transformers.js library, which runs the Whisper model. The main thread receives updates on the progress, partial text, and completed words, allowing the interface to provide feedback to the user. The implementation also includes checks for a usable GPU adapter and provides a fallback WebAssembly path in case of failures. For longer audio files, the PCM is segmented around pauses, and each segment's offset is added back to the word timestamps to ensure accurate timing (1). [1]

The timing conversions between seconds, milliseconds, and frame numbers are managed carefully to avoid errors in the caption rendering. The conversion functions are kept explicit to ensure clarity and correctness. The phrase grouping logic is designed to break captions at punctuation and pauses, ensuring that adjacent captions have clear, non-overlapping intervals. This helps maintain consistency between the preview and the final exported MP4 (1). [1]

The drawing code used for the preview and export is shared between both components to ensure consistency in the visual style and layout. This approach allows for deterministic animations and ensures that the preview and exported frames are comparable. Fonts are loaded before they are used to prevent layout changes due to asynchronous font loading. The final MP4 is generated by decoding video frames in sequence, drawing the caption overlay, and encoding the result into an H.264 MP4 file using browser media APIs (1). [1]

Advertisement

The process of generating captioned MP4s in a browser-based application begins with decoding the audio from the input video file. The transcription process is handled in a Web Worker using the Transformers.js library, which runs the Whisper model. The audio decoding must be carefully managed to ensure compatibility with the speech pipeline, which expects 16 kHz, mono, Float32 PCM. This involves downmixing channels and resampling if necessary, as outlined in the implementation details (1). [1]

The transcription worker communicates with the main thread through a protocol that includes progress, partial text, and completed words, allowing the interface to provide meaningful feedback to the user. This protocol is essential for handling different states, such as model downloading and transcription, which are not the same (1). Additionally, the implementation checks for a usable GPU adapter and provides fallback paths, such as WebAssembly, to ensure the application remains functional even if WebGPU session initialization fails (1). [1]

Timing conversions between seconds, milliseconds, and frame numbers are managed carefully to avoid errors in the caption rendering. The conversions are kept explicit rather than scattered throughout the caption components. This ensures consistency in the visual style and layout, as the same conversion logic is used in both the preview and export processes (1). The phrase grouping logic also plays a crucial role in rendering correctness by breaking at punctuation and longer pauses, and clamping a phrase’s end against the next phrase’s start (1). [1]

The process of generating captioned MP4s in a browser-based application begins with decoding the audio from the input video file. The transcription process is handled in a Web Worker using the Transformers.js library, which runs the Whisper model. This separation allows the interface to provide meaningful feedback to the user by receiving progress, partial text, and completed words from the worker. The memory requirements for this process are significant, as ten minutes of 16 kHz, mono, Float32 PCM audio can consume approximately 38.4 MB of memory (Dev.to, 2023). [1]

Advertisement

Timing conversions between seconds, milliseconds, and frame numbers are managed carefully to avoid errors in the caption rendering. The transcription worker communicates with the main thread through a protocol that includes progress, partial text, and completed words, allowing the interface to provide meaningful feedback to the user. These conversions are explicitly handled to ensure that the timing data is consistent across different stages of the pipeline, such as between the model output and the renderer (Dev.to, 2023). [1]

The drawing code used for the preview and export is shared between both components to ensure consistency in the visual style and layout. This shared code allows the preview and export to use the same canvas rendering engine, making it easier to maintain and ensuring that the visual appearance of the captions is identical in both the preview and the final exported video. This approach also helps in maintaining deterministic animations by deriving the look from the supplied timeline time rather than using random values (Dev.to, 2023). [1]

The process of generating captioned MP4s in a browser-based application begins with decoding the audio from the input video file. This step is crucial because the speech recognition pipeline expects a specific audio format: 16 kHz, mono, Float32 PCM. The input video may have a different sample rate, multiple channels, or an audio codec that requires additional decoding. To handle these variations, the application uses Web Audio decoding, downmixes channels, and resamples the audio to meet the required format (Dev.to, 2023). [1]

The transcription process is handled in a Web Worker using the Transformers.js library, which runs the Whisper model. The worker communicates with the main thread through a protocol that includes progress, partial text, and completed words. This allows the interface to provide meaningful feedback to the user. Additionally, the worker checks for a usable GPU adapter and has a fallback to WebAssembly if the WebGPU session initialization fails, ensuring that the user's captioning session is not interrupted (Dev.to, 2023). [1]

Advertisement

Timing conversions between seconds, milliseconds, and frame numbers are managed carefully to avoid errors in the caption rendering. The important choice is where these conversions are applied. In the current export path, a decoded sample’s timestamp is in seconds. The drawing call converts it to the millisecond time the caption renderer expects. This explicit handling of timing ensures that the preview and export components remain consistent and avoid discrepancies (Dev.to, 2023). [1]

Sources

Dev.to

Prepared with AI assistance from the cited sources.

The Cali Reporter newsletter

The stories worth your time.

California, the country, and what comes next. Join our free newsletter for reporting that keeps you informed.

By joining, you agree to receive the Cali Reporter newsletter. Unsubscribe at any time. Privacy policy.

More in Technology

  • Modern Web Guidance 1.0 and Browser Compatibility

    Modern Web Guidance 1.0, announced by Chrome for Developers on November 10, introduces browser compatibility data to assist coding agents in building web features. The initiative emphasizes the importance of fallback…

  • Apache mod_http2 Vulnerability Detection with Nmap

    A new Nmap scripting module has been developed to detect the Apache mod_http2 vulnerability (CVE-2026-119618), addressing the challenges of identifying affected systems accurately.

  • Securing Remote Vendor Access in Industrial Networks

    Best practices for managing remote vendor access in operational technology (OT) networks emphasize controlled access points, multifactor authentication, and time-bound sessions to reduce cybersecurity risks.

Advertisement