Duplicate frame from previous video in GStreamer

ToanVnET toanrd.vnet at gmail.com
Wed Apr 29 07:13:50 UTC 2020


I'm going to record video with multi file. When I record video with GStreamer
in C, I face with this issue:

My configuration:

Video duration is 5 minutes Resolution : 1280x720

<http://gstreamer-devel.966125.n4.nabble.com/file/t379416/a.png> 

Why does it happen ?

This is my code:

#include <gst/gst.h>
#include <stdio.h>
#include <stdlib.h>

GstElement *pipeline, *source, *queue, *videoconvert, *filesink, *enc, *mux,
*frameratefilter, *videorate;
GMainLoop *loop;
GstBus *bus;
char filename[50];

int i=1;

void updateFilename(){
   sprintf(filename, "%02d.mp4",i);

   i++;
}

gboolean bus_callback(GstBus *bus, GstMessage *msg, gpointer data){
GstElement *pipeline = GST_ELEMENT(data);
switch (GST_MESSAGE_TYPE(msg)){
case GST_MESSAGE_EOS:
{
   gst_element_set_state (pipeline, GST_STATE_NULL);
   //pipeline = gst_pipeline_new ("video-pipeline");
   updateFilename();
   g_object_set(G_OBJECT(filesink), "location", filename, NULL);
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
   g_print("Enroll to record...\n"); }
   break;
}
   default:
   break;
}
   return TRUE;
}

int main(int argc, char *argv[]) {

   updateFilename();
   /* Initialize GStreamer */
   gst_init (&argc, &argv);
   loop = g_main_loop_new (NULL, FALSE);

   /* Create the elements */
   source = gst_element_factory_make ("imxv4l2src", NULL);

   // Elements for write video
   videoconvert = gst_element_factory_make("videoconvert",NULL);
   queue = gst_element_factory_make("queue",NULL);
   filesink = gst_element_factory_make("filesink",NULL);
   enc = gst_element_factory_make("vpuenc_h264",NULL);
   mux = gst_element_factory_make("h264parse",NULL);
   frameratefilter = gst_element_factory_make("capsfilter", NULL);
   videorate = gst_element_factory_make("videorate", NULL);

   // Set parameters for some elements
   g_object_set(G_OBJECT(source), "num-buffers", 100, NULL);
   g_object_set(G_OBJECT(source), "device", "/dev/video0", NULL);
   g_object_set(G_OBJECT(filesink), "location", filename, "async", 0, NULL);
   g_object_set(G_OBJECT(frameratefilter), "caps",
gst_caps_from_string("video/x-raw,width=1280,height=720,framerate=(fraction)15/1"),
NULL);

   /* Create the empty pipeline */
   pipeline = gst_pipeline_new ("video-pipeline");

   if (!pipeline || !source || !queue || !videoconvert || !filesink || !enc
|| !mux || !frameratefilter || !videorate) {
   g_printerr ("Not all elements could be created.\n");
   return -1;
   }
   gst_bin_add_many (GST_BIN (pipeline), source, videoconvert, queue,
filesink, enc, mux, frameratefilter, videorate, NULL);

   if (gst_element_link_many(source, videoconvert, frameratefilter, queue,
videorate, enc, mux, filesink, NULL) != TRUE){
      g_error("Failed to link save elements!");
      gst_object_unref (pipeline);
      return -1;
}

   gst_element_set_state (pipeline, GST_STATE_PLAYING);

   bus = gst_element_get_bus (pipeline);
   gst_bus_add_watch (bus, bus_callback, pipeline);
   gst_object_unref (bus);

   g_main_loop_run (loop);

   gst_element_set_state (pipeline, GST_STATE_NULL);
   gst_object_unref (pipeline);
   return 0;
}
I tried to set state of each elements and mix some but It's not working. The
size of video output is bigger and bigger like that. How to solve this issue
? Anyone got it before ?

Thank you so much,

Toan



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list