Hi, Jaka,

I sometimes encounter this error, especially when running record (SDK) function with a high fps e.g. fps=30 or 60 to encode with MJPEG option:
F: [global] [ 0] [ThreadN] dispatcherResponseServe:925 no request for this response: XLINK_WRITE_RESP 1

Not always, but sometimes it happened like 50-50 chances. Any clue to make it stable? Power, bandwidth or anything?

Also, I noticed that in 'av_writer.py', the width and height was not specified when creating new stream, which lead to the meta data of video always with width and height as 640x480, even when I specified the resolution of video as '1080p'. Perhaps we need to add some lines to specify the width and height of frames in recording the video?

Thanks a lot!
Wu Bi

    Hi biwu
    Could you share a MRE please? The one with the highest error occurrence you can get.


    biwu 'av_writer.py', the width and height was not specified when creating new stream

    The width and height should be automatically set when passing a frame to the write method. Is the shape not recognized correctly? Try adding a print statement inside av_writer.py under line 158 shape = self.get_dimension(frame) to check.

    Perhaps we need to add some additional type checks.

    Thanks,
    Jaka

    Hi, Jaka,

    About the "av_writer.py" in my env: C:...\myenv\Lib\site-packages\depthai_sdk\recorders\video_writers\av_writer.py, I am not having 158 lines, I upload here. Maybe is the version problem? (I follow everything on the webpage: https://github.com/luxonis/depthai) (I couldn't make a proper insert code here):
    from datetime import timedelta
    from fractions import Fraction
    from pathlib import Path

    import depthai as dai

    from depthai_sdk.recorders.video_writers import AbstractWriter
    from depthai_sdk.recorders.video_writers.utils import create_writer_dir

    class AvWriter(AbstractWriter):
    start_ts: timedelta = None
    file = None

    def __init__(self, folder: Path, name: str, fourcc: str, fps: float):
        global av
        import av as av
    
        name = create_writer_dir(folder, name, 'mp4')
    
        self.start_ts = None
        self.folder = folder
        self.file = av.open(name, 'w')
        self._fps = fps
        self._fourcc = fourcc
    
        self._create_stream(self.file, fourcc, fps)
    
    def _create_stream(self, file, fourcc, fps) -> None:
        """Create stream in file with given fourcc and fps, works in-place."""
        stream = file.add_stream(fourcc, rate=int(fps))
        stream.time_base = Fraction(1, 1000 * 1000)  # Microseconds
    
        # We need to set pixel format for MJEPG, for H264/H265 it's yuv420p by default
        if fourcc == 'mjpeg':
            stream.pix_fmt = 'yuvj420p'
    
    def write(self, frame: dai.ImgFrame) -> None:
        packet = av.Packet(frame.getData())  # Create new packet with byte array
    
        # Set frame timestamp
        if self.start_ts is None:
            self.start_ts = frame.getTimestampDevice()
    
        ts = int((frame.getTimestampDevice() - self.start_ts).total_seconds() * 1e6)  # To microsec
        packet.dts = ts
        packet.pts = ts
    
        self.file.mux_one(packet)  # Mux the Packet into container
    
    def close(self):
        self.file.close()

    Here are the two ways of recording I used to produce the error (Both are able to produce the error):

    Test 1

    from depthai_sdk import OakCamera, RecordType
    import time
    with OakCamera() as oak:
    color = oak.create_camera('color', resolution='1080P', fps=60, encode='MJPEG')
    oak.visualize([color.out.encoded],fps=True) #optional
    oak.record([color.out.encoded], './record')
    oak.start()
    start_time = time.monotonic()
    while oak.running():
    if time.monotonic() - start_time > 5:
    break
    oak.poll()

    Test 2

    from depthai_sdk import OakCamera
    from depthai_sdk.record import RecordType
    with OakCamera() as oak:
    color = oak.create_camera('color', resolution='1080p', fps=60, encode='mjpeg')
    oak.record([color], path='./records', record_type=RecordType.VIDEO)
    oak.visualize([color.out.encoded])
    oak.start(blocking=True)

    Also I noticed that in Test 1, I can't reach 60 fps in the recorded video, but the Test 2 is able to. Could you also help to explain why? I would prefer the recording result from Test 2, but prefer a way of controlling the record like Test 1. Could you advice how to make a controllable record function with 60 fps MJPG vide? (record from SDK doesn't have a callback feature, correct?)

    Thanks and Regards
    Wu Bi

      jakaskerl

      Hi, Jaka,

      I am a little confused, because I found out that I'm having two DepthAI_SDK in my vs code folder. One is in my own virtual environment (this is the old version that doesn't have 158 lines), another is under my working folder (this is the right version I think). How do I make sure i import the right version or package? Could you help a bit? (I did follow from Github to make the installation, or do I miss out anything?)

      Thanks a lot!
      Wu BI

        Hi biwu
        You can run python3 -m pip install depthai_sdk -U inside your virtual environment to update the SDK version. Alternatively, you can use git pull to update the depthai repository and build the python package from source. I guess the first option is easier.

        To see which version you are using inside of the venv, try:

        import depthai_sdk
        print(depthai_sdk.__file__)

        Hope this helps,
        Jaka

        Hi, Jaka,

        After python3 -m pip install depthai_sdk -U, I got the packages in order and the data is correct. However, I got this error [2023-09-28 21:59:30] WARNING [libav.swscaler.decode:108] deprecated pixel format used, make sure you did set range correctly for this code below:

        from depthai_sdk import OakCamera, RecordType
        import time
        with OakCamera() as oak:

        color = oak.create_camera('color', resolution='1080P', fps=60, encode='MJPEG')

        oak.visualize([color.out.encoded],fps=True)     #optional
        # Sync & save all (encoded) streams
        oak.record([color.out.encoded], './record')
        oak.start()
        start_time = time.monotonic()
        while oak.running():
            if time.monotonic() - start_time > 5:
                break
            oak.poll()`

        what does the error mean?

        Best Regards
        Wu Bi

          Hi biwu
          Would I be right to assume this error appears after you have ended the recording?
          The libav.swscaler.decode is part of ffmpeg i think, which is used at the end to decode the encoded streams to mp4 (or whatever). I guess updating the ffmpeg should resolve this issue.

          Thanks,
          Jaka