Video Encoder¶
- class VideoEncoder[source]¶
- __init__(
- coding_structure: CodingStructure,
- shared_coolchic_parameter: CoolChicEncoderParameter,
- shared_frame_encoder_manager: FrameEncoderManager,
A VideoEncoder object is our main object. Its purpose is to encode a video i.e. one I-frame followed by 0 to N inter (P or B) frames.
- Parameters:
coding_structure (CodingStructure) – The coding structure (organization of the different frames) used to encode the video.
shared_coolchic_parameter (CoolChicEncoderParameter) – Common parameters for all Cool-chic of all frames (e.g. synthesis architecture). Can be overridden later in the encode function to better suits the need of each individual frame.
shared_frame_encoder_manager (FrameEncoderManager) – Common training parameters for all frames (e.g. max. number of iterations). It can be overridden later in the encode function to better suits the need of each individual frame.
- encode(
- path_original_sequence: str,
- device: Literal['cpu', 'cuda:0'],
- workdir: str,
- job_duration_min: int = -1,
Main training function of a
VideoEncoder
. Encode all required frames (i.e. as stated inself.coding_structure
) of the video located atpath_original_sequence
. This will fill the dictionaryself.all_frame_encoders
containing the successively overfitted frame encoders.There is a series of nested loops to encode the video, following roughly this process:
# Code all frames for idx_coding_order in range(n_frames): # Perform n_loops independent encoding for idx_loop in range(n_loops): # Find the best initialization frame_encoder = warmup(...) # Perform the successive training stages for training_phase in all_training_phases: frame_encoder = train(frame_encoder, training_phase) # Training is over, test and save results = test(frame_encoder) frame_encoder.save()
- Parameters:
path_original_sequence (str) – Absolute path to the original image or video to be compressed.
device (Literal['cpu', 'cuda:0']) – On which device should the training run
workdir (str) – Where we’ll save many thing
job_duration_min (int) – Exit and save the job after this duration is passed. Use -1 to only exit at the end of the entire encoding. Default to -1.
- Returns:
Either
TrainingExitCode.REQUEUE
if job has run for longer thanjob_duration_min
and should be put back into the job queue, orTrainingExitCode.END
if the encoding is actually over.- Return type:
TrainingExitCode
- get_frame_workdir(workdir: str, frame_display_order: int) str [source]¶
Compute the absolute path for the workdir of one frame.
- Parameters:
workdir (str) – Main working directory of the video encoder
frame_display_order (int) – Display order of the frame
- Returns:
Working directory of the frame
- Return type:
str
- concat_results_file(workdir: str) None [source]¶
Look at all the already encoded frames inside
workdir
and concatenate their result files (workdir/frame_XXX/results_best.tsv
) into a single result fileworkdir/results_best.tsv
.- Parameters:
workdir (str) – Working directory of the video encoder
- Return type:
None
- get_ref_data(
- frame: Frame,
Return a list of the (decoded) reference frames. The decoded data are obtained by recursively inferring the already learned FrameEncoder.
- get_lmbda_from_depth(depth: float, initial_lmbda: float) float [source]¶
Perform the QP offset as follows:
\[\lambda_i = (\frac{3}{2})^{d} \lambda,\]- Parameters:
depth (float) – The depth \(d\) of the frame in the GOP. See encoder/utils/coding_structure.py for more info
initial_lmbda (float) – The lmbda of the I frame \(\lambda\).
- Returns:
The lambda of the current frame \(\lambda_i\).
- Return type:
float
- save(save_path: str) None [source]¶
Save current VideoEncoder at given path. It contains everything, the
CodingStructure
, the shared parameters between the different frames as well as all the successiveFrameEncoder
and their respectiveFrameEncoderManager
.- Parameters:
save_path (str) – Where to save the model
- Return type:
None
- load_video_encoder(load_path: str) VideoEncoder [source]¶
Load a video encoder.
- Parameters:
load_path (str) – Absolute path where the VideoEncoder should be loaded.
- Returns:
The loaded VideoEncoder
- Return type: