easy_ffprobe/chapter.rs
1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5use crate::Ratio;
6
7#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
8#[cfg_attr(feature = "__internal_deny_unknown_fields", serde(deny_unknown_fields))]
9/// Chapter parsed
10pub struct Chapter {
11 /// This is an identifier for the chapter. It's a unique number that distinguishes this chapter from others.
12 pub id: i64,
13 /// This represents the time base of the chapter, which is a rational number. Time base is used to convert time stamps into seconds. It's usually formatted as a fraction, like "1/1000", meaning each unit in the time stamps is 1/1000 of a second.
14 pub time_base: Ratio,
15 /// This is the start time of the chapter, in units of time_base. To get the start time in seconds, you'd multiply this value by the time base.
16 pub start: i64,
17 /// This is the end time of the chapter, in units of time_base. Similar to start, this can be converted to seconds.
18 pub end: i64,
19 /// This holds additional metadata tags associated with the chapter, such as its title.
20 pub tags: ChapterTags,
21 #[cfg(feature = "__internal_deny_unknown_fields")]
22 start_time: Option<serde_json::Value>,
23 #[cfg(feature = "__internal_deny_unknown_fields")]
24 end_time: Option<serde_json::Value>,
25}
26
27impl Chapter {
28 pub fn start_time(&self) -> Duration {
29 Duration::from_millis(
30 ((self.start * self.time_base.numerator() as i64) as f64
31 / self.time_base.denominator() as f64
32 * 1000.) as u64,
33 )
34 }
35
36 pub fn end_time(&self) -> Duration {
37 Duration::from_millis(
38 ((self.end * self.time_base.numerator() as i64) as f64
39 / self.time_base.denominator() as f64
40 * 1000.) as u64,
41 )
42 }
43}
44
45#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
46/// Tags for chapter
47pub struct ChapterTags {
48 /// This is the title of the chapter. Titles can provide descriptive names for chapters, such as "Introduction" or "Chapter 1: Getting Started".
49 pub title: String,
50}