I have a saved video file from a camera, which saved in the format of mkv encode h264. How can I get the specific frame, for example frame 10th, from the video file and save it as a jpg image file by using gstreamer?
We have suggested a sample in
If it does not fully meet your requirement, would need other users to share experience.
Thank you for your kind reply.
As I am new to gstreamer, I created a script as below to capture one frame from a file and save it as jpg format, which does not work:
gst-launch-1.0 filesrc location=test_h264.mkv num-buffers=1 ! "video/x-raw, format=(string)I420, width=(int)2592, height=(int)1944,framerate=1/1" ! nvjpegenc ! multifilesink location=still-5m-mkv.jpg
I don’t know how and where to add the code to capture the expected frame( e.g. 10th frame) from a file to make it work.
Would you please help me on this. Thank you very much.
It may not be possible to save specific frames in gst-launch-1.0 command. You can follow the sample to initialize two pipelines. One pipeline is to send frames to appsink, and the other pipeline can decide if this frame needs to be encoded and saved.
Although the good way might be using frame step (but as said by DaneLLL this would require more than a gst-launch command), you might try the bad (or ugly?) way.
First be sure you have a different partition from rootfs for storing frames (if filled, you may not be able to normally use your system), or be sure you have enough room for your experiment. So know the size of a jpegenc encoded frame for your case (you are using high resolution) and number of frames.
Be sure your disk is able to write that amount of data at that rate. You may check on more than a few seconds for better estimation. If not enough, you may consider using a NVME SSD.
So cd to your external (or risky storage), create a new directory and cd to it, then launch this command that will encode each frame into jpeg (with CPU only, no idea if this works for your resolution on Nano) and save to disk. This command should support up to 99999 frames (unless your partition gets full before).
gst-launch-1.0 -ev filesrc location=<wherever_it_is>/test_h264.mkv ! decodebin ! nvvidconv ! jpegenc ! multifilesink location=test_%05d.jpg
and you’ll then get your jpg encoded frame from its number.
Thank you for your help. I think I would not go with this method