save event output videos for deepstream 4.0.1

I tried the #2 patch given in But it’s for deepstream 3.0, and i want the patch for deepstream 4.0.1. Still, I am able to run it now successfully for a locally stored video but it’s not working for live stream video and this patch is saving the whole video, but I want to only save video of events.

plz share the code how can I achieve that

  1. while running a live stream video through RTSP/ through usb camera, this code is saving video but as soon as live stream video is stopped then deepstream stops but the video file generated gets corrupted, and it’s not playable( i tried vlc and quicktime player). plz suggest how can I stop the camera feed without getting this output file corrupted.
    I also tried opencv to open the corrupted file but i getting this error
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f9c01c000] moov atom not found
OpenCV: Couldn't read video stream from file "new1.mp4"

I also tried create_encode_file_bin() in


but it’s also saving the whole video and it also has the same issue with live-stream video.
3. what changes are needed in this patch to save the video file as well as display it?


deepstream-app is reference application and supports one kind of sink only. You can modify the pipline to add multiple sinks based on the custom logic you want to use. Regarding the file corruption, you need to send an EOS event to the filesink when you want to stop recording, this will save the file with the codec headers so it can be playable later.

You can refer these soultions which are similar to your use case -