Increasing play speed decoding from mp4 file

Hi,
I would like to increase play speed when decoding from mp4 file. I dont know if it is possible but I tried videorate rate element but it did not change the speed.
This is the pipeline :

    pipeMP4_1 = 'filesrc location=/home/test/Documents/GstreamerTest/sample_mp4/2023-11-14T14-25-01.mp4 ! qtdemux name=demux ! h265parse ! nvv4l2decoder enable-max-performance=true ! nvvidconv ! video/x-raw, format=BGRx, width=1280, height=720 ! videorate ! video/x-raw, rate=2.0 ! videoconvert ! appsink'

Thanks

Hi,
Do you mean yo would like to play 30-fps video file in 60 fps, like 2x fast forward? Or 30-fps video file cannot be played in 30 fps?

Hi,

Sorry about the confusion. I have a 25 fps 4k mp4 file that has 4 minutes duration. I would like to capture this image in opencv in 2x speed and in this way video duration will be 2 minutes. This is what I am trying. So it is 2x fast forward in your question. I tried to double fps in pipeline but it did not effect, video was playing in normal speed. I searched and saw rate in videorate element can speed the video but it did not work either. Since I could not find any other example I wanted to ask here.

Thanks

Hi,
Please ty the command and check if you see 2x video playback:

$ DISPLAY=:0 gst-launch-1.0 filesrc location= videoplayback.mp4 ! qtdemux ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw ! videorate rate=2 ! xvimagesink
1 Like

When I modify my pipeline with your it works

    pipeMP4_1 = 'filesrc location=/home/test/Documents/GstreamerTest/sample_mp4/2023-11-14T14-25-01.mp4 ! qtdemux ! queue ! h265parse ! nvv4l2decoder enable-max-performance=true !  nvvidconv ! video/x-raw(memory:NVMM),format=BGRx ! videorate rate=2.5 ! nvvidconv ! queue ! appsink'


But I am facing a different problem now.
When video is playing it sometimes says this :

FPS: 24.99624753394147, read time: 0.031426429748535156, post process time: -0.031426429748535156
FPS: 24.95554283708331, read time: 0.0323028564453125, post process time: -0.0323028564453125
FPS: 24.987347068305574, read time: 0.03145480155944824, post process time: -0.03145480155944824
Opening in BLOCKING MODE 
NvMMLiteOpen : Block : BlockType = 279 
NVMEDIA: Reading vendor.tegra.display-size : status: 6 
NvMMLiteBlockCreate : Block : BlockType = 279 
FPS: 21.897061173496812, read time: 0.04397726058959961, post process time: -0.04397726058959961
FPS: 28.143399554739673, read time: 0.03153204917907715, post process time: -0.03153204917907715

It happens 4 or 5 times in 2 minutes video play. How can I solve this?

And also by doing this fps remains the same with the videos fps which is 25. So I guess in this case I am dropping some frames to speed the video. Is there another way to speed without dropping or duplicating frames.

Thanks

Hi,
Please set sync=0 to appsink like:

import sys
import cv2

def read_cam():
    cap = cv2.VideoCapture("filesrc location=test.mkv ! matroskademux ! h264parse ! nvv4l2decoder enable-max-performance=1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink sync=0 ")
    if cap.isOpened():
        count = 0;
        while True:
            ret_val, img = cap.read();
            if not ret_val:
                break;
            count = count + 1
            if count % 150 == 0:
                print("decoded frames:", count)
    else:
        print("rtsp open failed")

    cap.release()

if __name__ == '__main__':
    read_cam()

So that you can get decoded buffers immediately. If you need to have interval between the buffer, you can add delay while calling cap.read()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.