#include #include #include #include #include #include #include #include using namespace std; #define USE(x) ((void)(x)) static GstPipeline *gst_pipeline = nullptr; static string launch_string; int main(int argc, char** argv) { USE(argc); USE(argv); gst_init (&argc, &argv); GMainLoop *main_loop; main_loop = g_main_loop_new (NULL, FALSE); ostringstream launch_stream; int w = 1920; int h = 1080; launch_stream << "nvcamerasrc ! " << "video/x-raw(memory:NVMM), width="<< w <<", height="<< h <<", framerate=30/1 ! " << "omxh265enc ontrol-rate=2 bitrate=8000000 preset-level=3 SliceIntraRefreshEnable=true name=video_enc ! h265parse ! " << "video/x-h265,stream-format=byte-stream ! " << "filesink location=b.h265 "; launch_string = launch_stream.str(); g_print("Using launch string: %s\n", launch_string.c_str()); GError *error = nullptr; gst_pipeline = (GstPipeline*) gst_parse_launch(launch_string.c_str(), &error); if (gst_pipeline == nullptr) { g_print( "Failed to parse launch: %s\n", error->message); return -1; } if(error) g_error_free(error); GstElement *encoder = gst_bin_get_by_name(GST_BIN(gst_pipeline), "video_enc"); if(!GST_IS_ELEMENT(encoder)) { g_print( "Failed to get encoder from pipeline \n"); return -1; } gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_PLAYING); GstFlowReturn ret; sleep(1); g_signal_emit_by_name (encoder, "force-IDR", NULL, &ret); sleep(2); g_signal_emit_by_name (encoder, "force-IDR", NULL, &ret); sleep(7); //g_main_loop_run (main_loop); gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL); gst_object_unref(GST_OBJECT(gst_pipeline)); g_main_loop_unref(main_loop); g_print("going to exit \n"); return 0; }