convert
format_timedelta(time, precision=3)
Formats a timedelta to hh:mm:ss.s[*precision] and pads with 0 if there aren't more numbers to work with. Mostly to be used for ogm/xml files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time
|
timedelta
|
The timedelta |
required |
precision
|
int
|
3 = milliseconds, 6 = microseconds, 9 = nanoseconds |
3
|
Returns:
Type | Description |
---|---|
str
|
The formatted string |
Source code in muxtools/utils/convert.py
frame_to_ms(f, fps=Fraction(24000, 1001), compensate=False)
Converts a frame number to it's ms value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
int
|
The frame number |
required |
fps
|
Fraction | PathLike
|
A Fraction containing fps_num and fps_den. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
compensate
|
bool
|
Whether to place the timestamp in the middle of said frame Useful for subtitles, not so much for audio where you'd want to be accurate |
False
|
Returns:
Type | Description |
---|---|
float
|
The resulting ms |
Source code in muxtools/utils/convert.py
frame_to_timedelta(f, fps=Fraction(24000, 1001), compensate=False, rounding=True)
Converts a frame number to a timedelta. Mostly used in the conversion for manually defined chapters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
int
|
The frame number |
required |
fps
|
Fraction | PathLike
|
A Fraction containing fps_num and fps_den. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
compensate
|
bool
|
Whether to place the timestamp in the middle of said frame Useful for subtitles, not so much for audio where you'd want to be accurate |
False
|
rounding
|
bool
|
Round compensated value to centi seconds if True |
True
|
Returns:
Type | Description |
---|---|
timedelta
|
The resulting timedelta |
Source code in muxtools/utils/convert.py
mpls_timestamp_to_timedelta(timestamp)
Converts a mpls timestamp (from BDMV Playlist files) to a timedelta.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamp
|
int
|
The mpls timestamp |
required |
Returns:
Type | Description |
---|---|
timedelta
|
The resulting timedelta |
Source code in muxtools/utils/convert.py
timedelta_from_formatted(formatted)
Parses a string with the format of hh:mm:ss.sss Mostly to be used for ogm/xml files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
formatted
|
str
|
The timestamp string |
required |
Returns:
Type | Description |
---|---|
timedelta
|
The parsed timedelta |
Source code in muxtools/utils/convert.py
timedelta_to_frame(time, fps=Fraction(24000, 1001), exclude_boundary=False, allow_rounding=True)
Converts a timedelta to a frame number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time
|
timedelta
|
The timedelta |
required |
fps
|
Fraction | PathLike
|
A Fraction containing fps_num and fps_den. Also accepts a timecode (v2) file. |
Fraction(24000, 1001)
|
exclude_boundary
|
bool
|
Associate frame boundaries with the previous frame rather than the current one. Use this option when dealing with subtitle start/end times. |
False
|
allow_rounding
|
bool
|
Use the next int if the difference to the next frame is smaller than 0.01. This should probably not be used for subtitles. We are not sure. |
True
|
Returns:
Type | Description |
---|---|
int
|
The resulting frame number |