This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using DMAI to lower encodedecode framerate

I would like to lower the framerate of the video being captured in the encodedecode demo running on a DM365, but I'm not sure how to go about it.  Is this something that can be accomplished with DMAI calls? or will I need to generate a new codec with a lower framerate?

I'm new to DaVinci application development, so any direction you can give me would be very helpful.

 

- Brian

  • Hi Brian,

    One thing you can do is to throttle the framerate by throwing away captured frames. This can be done in the function CaptureThrFxn() in Capture.c in the while loop that does Capture_get().


       while (!gblGetQuit()) {

            /* Get a buffer from the capture driver to encode */
            if (Capture_get(hCapture, &hCapBuf) < 0) {
                ERR("Failed to get capture buffer\n");
                cleanup(THREAD_FAILURE);
            }

            /* Copy captured frame into destination buffer */
            if (Framecopy_execute(hFc, hCapBuf, hDstBuf) < 0) {
                ERR("Failed to execute frame copy job\n");
                cleanup(THREAD_FAILURE);
            }

            /* Send color converted buffer to video thread for encoding */
            if (Fifo_put(envp->hOutFifo, hDstBuf) < 0) {
                ERR("Failed to send buffer to display thread\n");
                cleanup(THREAD_FAILURE);
            }

            /* Return a buffer to the capture driver */
            if (Capture_put(hCapture, hCapBuf) < 0) {
                ERR("Failed to put capture buffer\n");
                cleanup(THREAD_FAILURE);
            }
            ...

    Skip the Framecopy_execute and Fifo_put calls for frames you'd like to drop.

    Best regards,

    Vincent

  • Thanks Vincent, this worked out for us.  We actually had to skip the Fifo_get call as well (if that's not skipped the loop stops executing after a few iterations).

    Another minor concern is that we are reducing the framerate in order to reduce the bitrate of the compressed video stream, but when we reduce the framerate, the reported bitrate isn't actually decreasing.  Any idea why this is occurring?

     

    - Brian

  • Hi Brian,

    Glad it worked out for you. In the encodedecode() function in encodedecode/video.c, this function call is used to accumulate the number of bits processed:

        gblIncVideoBytesProcessed(Buffer_getNumBytesUsed(hEncBuf));

    You may want to make sure that this function is never called when you drop a frame. Also, the actual bitrate is computed in drawDynamicData() in ctrl.c:

        /* Calculate the video bit rate */
        videoKbpsf   = gblGetAndResetVideoBytesProcessed() * 8.0 / deltaTime;
        videoKbps    = videoKbpsf + 0.5;

    Verify that gblGetAndResetVideoBytesProcessed is returning smaller values at lower frame rates and that deltaTime is more or less the same. This should help you track down what went wrong.

    Best regards,

    Vincent

  • Just a question, Vincent, on your example code: is there any reason why you should not return the buffer to the capture driver as soon as the framecopy job is finished ?

    In this case (Fifo_put) the operation in between is probably not significant, of course.