muxtools.utils.convert
ExtrapolatingVideoTimestamps
ExtrapolatingVideoTimestamps(pts_list: list[int], time_scale: Fraction, normalize: bool = True, rounding_method: RoundingMethod = RoundingMethod.ROUND)
Bases: VideoTimestamps
Simple class extending VideoTimestamps to add back extrapolation for frames past the video.
This works by getting the average framerate from the existing timestamps and assuming CFR from then on.
Source code in
muxtools/utils/convert.py
get_timemeta_from_video
get_timemeta_from_video(video_file: PathLike, index: int = 0, out_file: PathLike | None = None, metadata: ParsedFile | None = None, caller: Any | None = None) -> VideoMeta
Parse timestamps from an existing video file using ffprobe.
They're saved as a custom meta file in the current workdir and named based on the input.
Also automatically reused (with a debug log) if already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_file
|
PathLike
|
Input video. Path or String. |
required |
index
|
int
|
Relative video track index. |
0
|
out_file
|
PathLike | None
|
Output file. If None given, the above behavior applies. |
None
|
caller
|
Any | None
|
Caller used for the logging |
None
|
Returns:
| Type | Description |
|---|---|
VideoMeta
|
Videometa object |
Source code in
muxtools/utils/convert.py
resolve_timesource_and_scale
resolve_timesource_and_scale(timesource: PathLike | Fraction | float | list[int] | VideoMeta | ABCTimestamps | tuple[Path | str, int] | None = None, timescale: TimeScale | Fraction | int | None = None, rounding_method: RoundingMethod = RoundingMethod.ROUND, allow_warn: bool = True, fetch_from_setup: bool = False, caller: Any | None = None) -> ABCTimestamps
Instantiates a timestamps class from various inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timesource
|
PathLike | Fraction | float | list[int] | VideoMeta | ABCTimestamps | tuple[Path | str, int] | None
|
The source of timestamps/timecodes. For actual timestamps, this can be a timestamps (v1/v2/v4) file, a muxtools VideoMeta json file, a video file or a list of integers. For FPS based timestamps, this can be a Fraction object, a float or even a string representing a fraction. Like |
None
|
timescale
|
TimeScale | Fraction | int | None
|
Unit of time (in seconds) in terms of which frame timestamps are represented. While you can pass an int, the needed type is always a Fraction and will be converted via If |
None
|
rounding_method
|
RoundingMethod
|
The rounding method used to round/floor the PTS (Presentation Time Stamp). |
ROUND
|
allow_warn
|
bool
|
Allow this function to print warnings. If you know what you're doing feel free to disable this for your own use. |
True
|
fetch_from_setup
|
bool
|
Whether or not this function should fallback to the sub defaults from the current Setup. |
False
|
caller
|
Any | None
|
Caller used for the logging |
None
|
Returns:
| Type | Description |
|---|---|
ABCTimestamps
|
Instantiated timestamps object from the videotimestamps library |
Source code in
muxtools/utils/convert.py
format_timedelta
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
timedelta_from_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
sizeof_fmt
Human readable file size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
File size in bytes/bits |
required | |
unit
|
Unit to use (change to "b" for bits) |
'B'
|
Returns:
| Type | Description |
|---|---|
|
Formatted size |