video-subtitle 0.1.0

Video subtitles: FFmpeg extract audio → Whisper ASR → SRT → FFmpeg burn-in
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::fs::File;
use std::io::Write;
use std::path::Path;

use crate::error::Result;
use crate::srt::captions_to_srt;
use crate::types::Caption;

/// 将字幕列表写入 SubRip 文件。
///
/// 若 `path` 已存在会被覆盖([`std::fs::File::create`])。
/// 内容编码为 UTF-8 字节,无 BOM。
pub fn write_srt(path: &Path, captions: &[Caption]) -> Result<()> {
    let content = captions_to_srt(captions);
    let mut file = File::create(path)?;
    file.write_all(content.as_bytes())?;
    Ok(())
}