easy_ffprobe/
audio_stream.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::streams::{option_string_to_int, string_to_int, StreamTags};
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8/// Tags specific for audio
9pub struct AudioTags {
10    #[serde(flatten)]
11    pub tags: StreamTags,
12    #[serde(rename = "ENCODER_OPTIONS")]
13    pub encoder_options: Option<String>,
14    #[serde(rename = "SOURCE_ID")]
15    pub source_id: Option<String>,
16    #[serde(rename = "COMMENT")]
17    pub comment: Option<String>,
18    #[serde(deserialize_with = "option_string_to_int", default)]
19    pub track: Option<i64>,
20    #[serde(flatten)]
21    pub extra: HashMap<String, serde_json::Value>,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25#[cfg_attr(feature = "__internal_deny_unknown_fields", serde(deny_unknown_fields))]
26/// Stream of type audio
27pub struct AudioStream {
28    /// The number of bits per sample in the audio stream.
29    pub bits_per_sample: i64,
30    /// The layout of audio channels.
31    /// eg. stereo
32    pub channel_layout: Option<String>,
33    /// number of channels
34    /// eg. 2
35    pub channels: i64,
36    /// The initial padding in the audio stream.
37    /// Padding in audio streams refers to extra bits or bytes added to the beginning of audio data to align it with specific boundaries or to provide some additional space for processing.
38    pub initial_padding: i64,
39    /// The sample format of the audio stream.
40    /// Smple format defines how each audio sample is represented in binary form. It describes the encoding method and the number of bits used to represent each sample.
41    ///
42    /// Common sample formats include:
43    /// s16: Signed 16-bit integer
44    /// s32: Signed 32-bit integer
45    /// flt: Floating point
46    /// dbl: Double precision floating point
47    /// todo: enum
48    pub sample_fmt: String,
49    /// The sample rate of the audio stream.
50    /// eg. 44100 Hz
51    #[serde(deserialize_with = "string_to_int")]
52    pub sample_rate: i64,
53    /// Bit rate of the video stream.
54    /// The bit_rate represents the number of bits that are processed per unit of time in the video stream. It is a measure of the video stream's data rate, indicating how much data is encoded for each second of video.
55    #[serde(deserialize_with = "option_string_to_int", default)]
56    pub bit_rate: Option<i64>,
57    /// Long name of the codec used for the video stream.
58    pub codec_long_name: String,
59    /// Short name of the codec used for the video stream.
60    /// Example: h264
61    pub codec_name: String,
62    /// Duration of the video stream in timestamp units.
63    pub duration_ts: Option<u64>,
64    /// Profile of the codec used for the video stream (e.g., Main, High).
65    // todo: enum
66    pub profile: Option<String>,
67    ///  This specifies the number of bits used to represent each component of the pixel. For example, in an 8-bit raw sample, each color component (e.g., red, green, and blue in an RGB format) is represented by 8 bits, allowing 256 different levels per component.
68    #[serde(deserialize_with = "option_string_to_int", default)]
69    pub bits_per_raw_sample: Option<i64>,
70    /// Metadata tags associated with the video stream.
71    pub tags: Option<AudioTags>,
72    #[cfg(feature = "__internal_deny_unknown_fields")]
73    codec_type: Option<serde_json::Value>,
74    #[cfg(feature = "__internal_deny_unknown_fields")]
75    start_time: Option<serde_json::Value>,
76    #[cfg(feature = "__internal_deny_unknown_fields")]
77    duration: Option<serde_json::Value>,
78}