boom
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
main
|
||||||
@@ -7,3 +7,4 @@ build:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f myprog
|
rm -f myprog
|
||||||
|
rm -f *.mp4
|
||||||
|
|||||||
Binary file not shown.
+114
-77
@@ -1,109 +1,146 @@
|
|||||||
#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;
|
gchar *name, *debug = NULL;
|
||||||
gchar *name, *debug = NULL;
|
|
||||||
|
|
||||||
name = gst_object_get_path_string (message->src);
|
name = gst_object_get_path_string(message->src);
|
||||||
gst_message_parse_error (message, &err, &debug);
|
gst_message_parse_error(message, &err, &debug);
|
||||||
|
|
||||||
g_printerr ("ERROR: from element %s: %s\n", name, err->message);
|
g_printerr("ERROR: from element %s: %s\n", name, err->message);
|
||||||
if (debug != NULL)
|
if (debug != NULL)
|
||||||
g_printerr ("Additional debug info:\n%s\n", debug);
|
g_printerr("Additional debug info:\n%s\n", debug);
|
||||||
|
|
||||||
g_error_free (err);
|
g_error_free(err);
|
||||||
g_free (debug);
|
g_free(debug);
|
||||||
g_free (name);
|
g_free(name);
|
||||||
|
|
||||||
g_main_loop_quit (loop);
|
g_main_loop_quit(loop);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GST_MESSAGE_WARNING:{
|
case GST_MESSAGE_WARNING: {
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
gchar *name, *debug = NULL;
|
gchar *name, *debug = NULL;
|
||||||
|
|
||||||
name = gst_object_get_path_string (message->src);
|
name = gst_object_get_path_string(message->src);
|
||||||
gst_message_parse_warning (message, &err, &debug);
|
gst_message_parse_warning(message, &err, &debug);
|
||||||
|
|
||||||
g_printerr ("ERROR: from element %s: %s\n", name, err->message);
|
g_printerr("ERROR: from element %s: %s\n", name, err->message);
|
||||||
if (debug != NULL)
|
if (debug != NULL)
|
||||||
g_printerr ("Additional debug info:\n%s\n", debug);
|
g_printerr("Additional debug info:\n%s\n", debug);
|
||||||
|
|
||||||
g_error_free (err);
|
g_error_free(err);
|
||||||
g_free (debug);
|
g_free(debug);
|
||||||
g_free (name);
|
g_free(name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GST_MESSAGE_EOS:{
|
case GST_MESSAGE_EOS: {
|
||||||
g_print ("Got EOS\n");
|
g_print("Got EOS\n");
|
||||||
g_main_loop_quit (loop);
|
g_main_loop_quit(loop);
|
||||||
gst_element_set_state (pipeline, GST_STATE_NULL);
|
gst_element_set_state(pipeline, GST_STATE_NULL);
|
||||||
g_main_loop_unref (loop);
|
g_main_loop_unref(loop);
|
||||||
gst_object_unref (pipeline);
|
gst_object_unref(pipeline);
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sigintHandler(int unused) {
|
int sigintHandler(int unused) {
|
||||||
g_print("You ctrl-c-ed! Sending EoS");
|
g_print("You ctrl-c-ed! Sending EoS");
|
||||||
gst_element_send_event(pipeline, gst_event_new_eos());
|
gst_element_send_event(pipeline, gst_event_new_eos());
|
||||||
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);
|
||||||
muxer = gst_element_factory_make("mp4mux", NULL);
|
encoder = gst_element_factory_make("vaapih264enc", NULL);
|
||||||
sink = gst_element_factory_make("filesink", NULL);
|
|
||||||
|
|
||||||
if (!pipeline || !src || !convert || !encoder || !muxer || !sink) {
|
muxer = gst_element_factory_make("mp4mux", NULL);
|
||||||
g_error("Failed to create elements");
|
sink = gst_element_factory_make("filesink", NULL);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_set(sink, "location", "/home/talksik/code/gstreamer-tests/test-record/out.mp4", NULL);
|
alsa_src = gst_element_factory_make("alsasrc", NULL);
|
||||||
gst_bin_add_many(GST_BIN(pipeline), src, convert, encoder, muxer, sink, NULL);
|
audio_queue = gst_element_factory_make("queue", NULL);
|
||||||
if (!gst_element_link_many(src, convert, encoder, muxer, sink, NULL)){
|
audio_convert = gst_element_factory_make("audioconvert", NULL);
|
||||||
g_error("Failed to link elements");
|
audio_resample = gst_element_factory_make("audioresample", NULL);
|
||||||
return -2;
|
audio_encoder = gst_element_factory_make("voaacenc", NULL);
|
||||||
}
|
audio_parse = gst_element_factory_make("aacparse", NULL);
|
||||||
|
|
||||||
loop = g_main_loop_new(NULL, FALSE);
|
if (!pipeline || !src || !convert || !encoder || !muxer || !sink) {
|
||||||
|
g_error("Failed to create video elements");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
|
if (!alsa_src || !audio_queue || !audio_convert || !audio_resample ||
|
||||||
gst_bus_add_signal_watch(bus);
|
!audio_encoder || !audio_parse) {
|
||||||
g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(message_cb), NULL);
|
g_error("Failed to create audio elements");
|
||||||
gst_object_unref(GST_OBJECT(bus));
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
gst_element_set_state(pipeline, GST_STATE_PLAYING);
|
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)) {
|
||||||
|
g_error("Failed to link video elements");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
g_print("Starting loop");
|
if (!gst_element_link_many(alsa_src, audio_queue, audio_convert,
|
||||||
g_main_loop_run(loop);
|
audio_resample, audio_encoder, audio_parse, muxer,
|
||||||
|
NULL)) {
|
||||||
|
g_error("Failed to link audio elements");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
||||||
|
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
|
||||||
|
gst_bus_add_signal_watch(bus);
|
||||||
|
g_signal_connect(G_OBJECT(bus), "message", G_CALLBACK(message_cb), NULL);
|
||||||
|
gst_object_unref(GST_OBJECT(bus));
|
||||||
|
|
||||||
|
gst_element_set_state(pipeline, GST_STATE_PLAYING);
|
||||||
|
|
||||||
|
g_print("Starting loop");
|
||||||
|
g_main_loop_run(loop);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user