Recompressing videos fails with sdk5

Hello.

I have a particular use case where I collect videos with lossless compression and then, to save space when storing, I might want to compress them with lossy compression. For this I run a script which takes a video as input and re-records it (code at the end).

This used to work for ZED 2i with sdk 4 but I am not being able to make it work for ZED X in sdk 5. To try to understand whether it is a camera problem or an SDK problem, I tried to use a video filmed with ZED 2i and I couldn’t do it either. So I think it’s an sdk5 problem.

Below is the code and a frame from the resulting compressed video which is nothing more than a sequence of green frames. I’m currently using SDK5.0.5

Here’s the code I am using

import pyzed.sl as sl
import argparse 
import os 


def main(filepath, compression_mode, output_name, bitrate):
    """ Camera """
    cam = sl.Camera()
    
    """ Initialize camera """
    input_type = sl.InputType()
    input_type.set_from_svo_file(filepath)  # Set init parameter to run from the .svo 
    init = sl.InitParameters(input_t=input_type)
    init.depth_mode = sl.DEPTH_MODE.NONE

    status = cam.open(init)        
    if status != sl.ERROR_CODE.SUCCESS: # Ensure the camera opened successfully 
        print("Camera Open", status, "Exit program.")
        exit(1)
    else:
        print("Camera opened successfully")

    """ Recording parameters """
    recording_parameters = sl.RecordingParameters()
    recording_parameters.video_filename = output_name

    if compression_mode is not None:
        recording_parameters.compression_mode = getattr(sl.SVO_COMPRESSION_MODE, compression_mode)

    if bitrate is not None:
        recording_parameters.bitrate = bitrate
        
    # Enable recording to start writing to a new SVO file
    err = cam.enable_recording(recording_parameters)
    if err != sl.ERROR_CODE.SUCCESS:
        print("Recording ZED : ", err)
        exit(1)

    runtime = sl.RuntimeParameters()
    print("SVO is Recording, use Ctrl-C to stop.") # Start recording SVO, stop with Ctrl-C command
    frames_recorded = 0

    while cam.grab(runtime) == sl.ERROR_CODE.SUCCESS:
        frames_recorded += 1
        print("Frame count: " + str(frames_recorded), end="\r")

    cam.close()



if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Recompress SVO file with specified compression mode.")
    
    # Mandatory positional argument for the file path
    parser.add_argument('filepath', type=str, help='Path to the SVO file')
    
    # Optional arguments
    parser.add_argument('--compression_mode', type=str, default=None,
                        help='Compression mode for the output SVO (H264_LOSSLESS, H265_LOSSLESS, H264, H265)')
    parser.add_argument('--output_name', type=str,
                        help='Name of the output SVO file (default: input file name with compression mode suffix)')
    parser.add_argument('--bitrate', type=int, default=None,
                        help='Bitrate for video compression between 1000 and 60000 (if not set, the SDK will choose the optimal bitrate) ')

    args = parser.parse_args()
    
    # Set the default output name based on the compression mode if not provided
    if args.output_name is None:
        if args.compression_mode:
            compression_suffix = f"_{args.compression_mode}"
        else:
            compression_suffix = "_DEFAULT"
        args.output_name = f"{os.path.splitext(args.filepath)[0]}{compression_suffix}.svo"

    print("Starting script with the following parameters:")
    print(f"Filepath: {args.filepath}")
    print(f"Compression Mode: {'Not set (SDK will decide)' if args.compression_mode is None else args.compression_mode}")
    print(f"Output Name: {args.output_name}")
    print(f"Bitrate: {'Not set (SDK will decide)' if args.bitrate is None else args.bitrate}")
    print()

    main(args.filepath, args.compression_mode, args.output_name, args.bitrate)

Hello @troliveira,

Thank you for the report and for the script! Having a script which helps us to easily reproduce is highly appreciated!

As you reported, we confirm that their seem to be a regression in the 5.x releases (up to 5.0.5) regarding recording a recorded SVO.
This has been noted on our side and added to the backlog for the next release.

Please keep an eye at the release notes when we release the next patch/minor

Knowing that recording a recorded SVO is important for you, we’ll also make sure to add this use case in our tests

Best,
Julien