This commit is contained in:
talksik
2023-11-01 14:42:27 -07:00
parent 36eb55378d
commit 0423094708
5 changed files with 116 additions and 77 deletions
+1
View File
@@ -0,0 +1 @@
main
+1
View File
@@ -7,3 +7,4 @@ build:
clean: clean:
rm -f myprog rm -f myprog
rm -f *.mp4
BIN
View File
Binary file not shown.
+51 -14
View File
@@ -1,17 +1,20 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <string.h>
#include <signal.h> #include <signal.h>
#include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
// gst-launch-1.0 v4l2src ! x264enc ! mp4mux ! filesink location=/home/rish/Desktop/okay.264 -e // gst-launch-1.0 v4l2src ! x264enc ! mp4mux ! filesink
// location=/home/rish/Desktop/okay.264 -e
static GMainLoop *loop; static GMainLoop *loop;
static GstElement *pipeline, *src, *convert, *encoder, *muxer, *sink; static GstElement *pipeline, *src, *convert, *encoder, *muxer, *sink, *video_queue;
static GstElement *alsa_src, *audio_queue, *audio_convert, *audio_resample,
*audio_encoder, *audio_parse;
static GstBus *bus; static GstBus *bus;
static gboolean static gboolean message_cb(GstBus *bus, GstMessage *message,
message_cb (GstBus * bus, GstMessage * message, gpointer user_data) gpointer user_data) {
{
switch (GST_MESSAGE_TYPE(message)) { switch (GST_MESSAGE_TYPE(message)) {
case GST_MESSAGE_ERROR: { case GST_MESSAGE_ERROR: {
GError *err = NULL; GError *err = NULL;
@@ -69,27 +72,61 @@ int sigintHandler(int unused) {
return 0; return 0;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
signal(SIGINT, sigintHandler); signal(SIGINT, sigintHandler);
gst_init(&argc, &argv); gst_init(&argc, &argv);
pipeline = gst_pipeline_new(NULL); pipeline = gst_pipeline_new(NULL);
src = gst_element_factory_make("v4l2src", NULL); src = gst_element_factory_make("v4l2src", NULL);
convert = gst_element_factory_make("videoconvert", NULL); convert = gst_element_factory_make("videoconvert", NULL);
encoder = gst_element_factory_make("x264enc", NULL); video_queue = gst_element_factory_make("queue", NULL);
encoder = gst_element_factory_make("vaapih264enc", NULL);
muxer = gst_element_factory_make("mp4mux", NULL); muxer = gst_element_factory_make("mp4mux", NULL);
sink = gst_element_factory_make("filesink", NULL); sink = gst_element_factory_make("filesink", NULL);
alsa_src = gst_element_factory_make("alsasrc", NULL);
audio_queue = gst_element_factory_make("queue", NULL);
audio_convert = gst_element_factory_make("audioconvert", NULL);
audio_resample = gst_element_factory_make("audioresample", NULL);
audio_encoder = gst_element_factory_make("voaacenc", NULL);
audio_parse = gst_element_factory_make("aacparse", NULL);
if (!pipeline || !src || !convert || !encoder || !muxer || !sink) { if (!pipeline || !src || !convert || !encoder || !muxer || !sink) {
g_error("Failed to create elements"); g_error("Failed to create video elements");
return -1; return -1;
} }
g_object_set(sink, "location", "/home/talksik/code/gstreamer-tests/test-record/out.mp4", NULL); if (!alsa_src || !audio_queue || !audio_convert || !audio_resample ||
gst_bin_add_many(GST_BIN(pipeline), src, convert, encoder, muxer, sink, NULL); !audio_encoder || !audio_parse) {
g_error("Failed to create audio elements");
return -1;
}
g_object_set(sink, "location", "./out.mp4", "sync", false, NULL);
gst_bin_add_many(GST_BIN(pipeline),
src,
video_queue,
convert,
encoder,
muxer,
sink,
alsa_src,
audio_queue,
audio_convert,
audio_resample,
audio_encoder,
audio_parse,
NULL);
if (!gst_element_link_many(src, convert, encoder, muxer, sink, NULL)) { if (!gst_element_link_many(src, convert, encoder, muxer, sink, NULL)) {
g_error("Failed to link elements"); g_error("Failed to link video elements");
return -2;
}
if (!gst_element_link_many(alsa_src, audio_queue, audio_convert,
audio_resample, audio_encoder, audio_parse, muxer,
NULL)) {
g_error("Failed to link audio elements");
return -2; return -2;
} }
Binary file not shown.