subaligner.media_helper module¶
-
class
subaligner.media_helper.
MediaHelper
[source]¶ Bases:
object
Utility for processing media assets including audio, video and subtitle files.
-
AUDIO_FILE_EXTENSION
= ['.wav', '.aac']¶
-
FFMPEG_BIN
= 'ffmpeg'¶
-
extract_audio
(video_file_path, decompress: bool = False, freq: int = 16000) → str[source]¶ Extract audio track from the video file and save it to a WAV file.
- Parameters
{string} -- The input video file path. (video_file_path) –
- Keyword Arguments
{bool} -- Extract WAV if True otherwise extract AAC (default (decompress) – {False}).
{int} -- The audio sample frequency (default (freq) – {16000}).
- Returns
string – The file path of the extracted audio.
-
extract_audio_from_start_to_end
(audio_file_path: str, start: str, end: Optional[str] = None) → Tuple[str, Optional[float]][source]¶ Extract audio based on the start time and the end time and save it to a temporary file.
- Parameters
{string} -- The path of the audio file. (audio_file_path) –
{string} -- The start time (e.g. (start) – 00:00,750).
00 – 00:00,750).
- Keyword Arguments
{string} -- The end time (e.g., 00 (end) – 00:10,230) (default: {None}).
- Returns
tuple – The file path to the extracted audio and its duration.
-
get_audio_segment_starts_and_ends
(subs: List[pysrt.SubRipItem]) → Tuple[List[str], List[str], List[pysrt.SubRipFile]][source]¶ Group subtitle cues into larger segments in terms of silence gaps.
- Parameters
{list} -- A list of SupRip cues. (subs) –
- Returns
tuple – A list of start times, a list of end times and a list of grouped SubRip files.
-
get_duration_in_seconds
(start: Optional[str], end: Optional[str]) → Optional[float][source]¶ Get the duration in seconds between a start time and an end time.
- Parameters
{string} -- The start time (e.g. (start) – 00:00,750).
00 – 00:00,750).
{string} -- The end time (e.g. (end) – 00:10,230).
00 – 00:10,230).
- Returns
float – The duration in seconds.
-
get_frame_rate
(file_path: str) → float[source]¶ Extract the video frame rate. Will return 25 when input is audio
- Parameters
{string} -- The input audiovisual file path. (file_path) –
- Returns
float – The frame rate
-
refragment_with_min_duration
(subs: List[pysrt.SubRipItem], minimum_segment_duration: float) → List[pysrt.SubRipItem][source]¶ Re-fragment a list of subtitle cues into new cues each of spans a minimum duration
- Parameters
{list} -- A list of SupRip cues. (subs) –
{float} -- The minimum duration in seconds for each output subtitle cue. (minimum_segment_duration) –
- Returns
list – A list of new SupRip cues after fragmentation.
-