diff --git a/README.md b/README.md index f0ac45e..04a23a8 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,28 @@ # record mux another example with cli ```sh +# mux to file with fake audio + video gst-launch-1.0 -e videotestsrc ! x264enc ! mp4mux name=mux ! filesink location="bla.mp4" audiotestsrc ! lamemp3enc ! mux. +# diff mux than above +gst-launch-1.0 -vv videotestsrc ! videoconvert ! x264enc ! avimux name=mux ! filesink location="avimux_test.mp4" audiotestsrc ! voaacenc ! mux.^C + +# above but with actual audio src +gst-launch-1.0 videotestsrc ! x264enc ! mp4mux name=mux ! filesink location="bla.mp4" pulsesrc ! lamemp3enc ! mux. + +# and.... yep now with actual video src +# audio a little low? +gst-launch-1.0 -e v4l2src device="/dev/video0" ! videoconvert ! queue ! x264enc tune=zerolatency ! mux. pulsesrc ! queue ! audioconvert ! audioresample ! voaacenc ! aacparse ! qtmux name=mux ! filesink location=test_gstreamer_record.mp4 sync=false + +# same thing but works fine after restart. make sure alsa settings not screwed up tho? +gst-launch-1.0 -e v4l2src device="/dev/video0" ! videoconvert ! queue ! x264enc tune=zerolatency ! mux. alsasrc ! queue ! audioconvert ! audioresample ! voaacenc ! aacparse ! qtmux name=mux ! filesink location=test.mp4 sync=false +``` + +# ffmpeg +```sh +# video record +ffmpeg -f v4l2 -framerate 25 -video_size 640_480 -i dev/video0 output.mkv + +# video + audio record to file +./ffmpeg -f alsa -i hw:0 -f video4linux2 -i /dev/video0 + ``` diff --git a/dump.ogg b/dump.ogg deleted file mode 100644 index 3c57178..0000000 Binary files a/dump.ogg and /dev/null differ diff --git a/mux.mp4 b/mux.mp4 deleted file mode 100644 index e69de29..0000000 diff --git a/test-record/Makefile b/test-record/Makefile new file mode 100644 index 0000000..7d2f1b0 --- /dev/null +++ b/test-record/Makefile @@ -0,0 +1,9 @@ + +run: clean build + ./main + +build: + gcc -o main main.c `pkg-config --cflags --libs gstreamer-1.0 glib-2.0` + +clean: + rm -f myprog diff --git a/test-record/main b/test-record/main new file mode 100755 index 0000000..b306b2e Binary files /dev/null and b/test-record/main differ diff --git a/test-record/main.c b/test-record/main.c new file mode 100644 index 0000000..22c45c0 --- /dev/null +++ b/test-record/main.c @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include + +// gst-launch-1.0 v4l2src ! x264enc ! mp4mux ! filesink location=/home/rish/Desktop/okay.264 -e +static GMainLoop *loop; +static GstElement *pipeline, *src, *convert, *encoder, *muxer, *sink; +static GstBus *bus; + +static gboolean +message_cb (GstBus * bus, GstMessage * message, gpointer user_data) +{ + switch (GST_MESSAGE_TYPE (message)) { + case GST_MESSAGE_ERROR:{ + GError *err = NULL; + gchar *name, *debug = NULL; + + name = gst_object_get_path_string (message->src); + gst_message_parse_error (message, &err, &debug); + + g_printerr ("ERROR: from element %s: %s\n", name, err->message); + if (debug != NULL) + g_printerr ("Additional debug info:\n%s\n", debug); + + g_error_free (err); + g_free (debug); + g_free (name); + + g_main_loop_quit (loop); + break; + } + case GST_MESSAGE_WARNING:{ + GError *err = NULL; + gchar *name, *debug = NULL; + + name = gst_object_get_path_string (message->src); + gst_message_parse_warning (message, &err, &debug); + + g_printerr ("ERROR: from element %s: %s\n", name, err->message); + if (debug != NULL) + g_printerr ("Additional debug info:\n%s\n", debug); + + g_error_free (err); + g_free (debug); + g_free (name); + break; + } + case GST_MESSAGE_EOS:{ + g_print ("Got EOS\n"); + g_main_loop_quit (loop); + gst_element_set_state (pipeline, GST_STATE_NULL); + g_main_loop_unref (loop); + gst_object_unref (pipeline); + exit(0); + break; + } + default: + break; + } + + return TRUE; +} + +int sigintHandler(int unused) { + g_print("You ctrl-c-ed! Sending EoS"); + gst_element_send_event(pipeline, gst_event_new_eos()); + return 0; +} + +int main(int argc, char *argv[]) +{ + signal(SIGINT, sigintHandler); + gst_init (&argc, &argv); + + pipeline = gst_pipeline_new(NULL); + src = gst_element_factory_make("v4l2src", NULL); + convert = gst_element_factory_make("videoconvert", NULL); + encoder = gst_element_factory_make("x264enc", NULL); + muxer = gst_element_factory_make("mp4mux", NULL); + sink = gst_element_factory_make("filesink", NULL); + + if (!pipeline || !src || !convert || !encoder || !muxer || !sink) { + g_error("Failed to create elements"); + return -1; + } + + g_object_set(sink, "location", "/home/talksik/code/gstreamer-tests/test-record/out.mp4", NULL); + gst_bin_add_many(GST_BIN(pipeline), src, convert, encoder, muxer, sink, NULL); + if (!gst_element_link_many(src, convert, encoder, muxer, sink, NULL)){ + g_error("Failed to link elements"); + return -2; + } + + 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; +} diff --git a/test-record/out.mp4 b/test-record/out.mp4 new file mode 100644 index 0000000..c7c2b8c Binary files /dev/null and b/test-record/out.mp4 differ diff --git a/test.mp4 b/test.mp4 deleted file mode 100644 index 88f0ad1..0000000 Binary files a/test.mp4 and /dev/null differ