No Video
Ian Davidson
id012c3076 at blueyonder.co.uk
Sat Jan 5 09:06:36 PST 2013
If I use the following command, I can record Audio and Video into an AVI
File.
gst-launch-1.0 -e v4l2src norm=PAL ! videorate !
'video/x-raw,format=(string)I420,width=320,height=240,framerate=(fraction)25/1'
! queue ! mux. alsasrc ! audioconvert !
'audio/x-raw,rate=44100,channels=2' ! queue ! mux. avimux name=mux !
filesink location=script-test.avi
I would like to replicate that in a program and my program is below.
However, the video does not make it through - the Audio plays OK when I
play the avi file.
It had been suggested that videorate and audiorate might be beneficial
for me. In my program, if I included audiorate (as indicated by the
commented out lines), I just heard a brief burst of sound at the
beginning of the clip, whereas without audiorate, I heard the full
audio. Including/excluding videorate does not seem to make any
difference at the moment.
I tried to set a value for "norm" on the v4l2src as PAL, but the
compiler did not recognise the ENUM value. The only way I could set it
was to use the value indicated by gst-inspect.
I assume that I have done something stupid again, but I cannot see what
it is.
Thanks for your help.
Ian
#include <gst/gst.h>
#include <glib.h>
static gboolean
bus_call (GstBus *bus,
GstMessage *msg,
gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
static void
on_pad_added (GstElement *element,
GstPad *pad,
gpointer data)
{
GstPad *sinkpad;
GstElement *decoder = (GstElement *) data;
/* We can now link this pad with the vorbis-decoder sink pad */
g_print ("Dynamic pad created, linking demuxer/decoder\n");
sinkpad = gst_element_get_static_pad (decoder, "sink");
gst_pad_link (pad, sinkpad);
gst_object_unref (sinkpad);
}
int
main (int argc,
char *argv[])
{
GMainLoop *loop;
GstElement *pipeline, *vsource, *vcapsfilter, *vidrate, *queue1;
GstElement *asource, *aconv, *audrate, *acapsfilter, *queue2;
GstElement *mux, *sink;
GstBus *bus;
guint bus_watch_id;
GstCaps *caps;
/* Initialisation */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s <AVI filename>\n", argv[0]);
return -1;
}
/* Create gstreamer elements */
pipeline = gst_pipeline_new ("av-recorder");
vsource = gst_element_factory_make ("v4l2src", "vid-source");
vcapsfilter = gst_element_factory_make ("capsfilter", "vid-caps");
vidrate = gst_element_factory_make ("videorate", "vidrate");
queue1 = gst_element_factory_make ("queue", "queue1");
asource = gst_element_factory_make ("alsasrc", "alsa-source");
aconv = gst_element_factory_make ("audioconvert", "audio-conv");
acapsfilter = gst_element_factory_make ("capsfilter", "audio-caps");
audrate = gst_element_factory_make ("audiorate", "audrate");
queue2 = gst_element_factory_make ("queue", "queue2");
mux = gst_element_factory_make ("avimux", "avi-mux");
sink = gst_element_factory_make ("filesink", "file-output");
if (!pipeline || !vsource || !vcapsfilter || !vidrate || !queue1 ||
!asource || !aconv || !audrate || !acapsfilter || !queue2 || !mux ||
!sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Set up the pipeline */
/* we set the output filename to the sink element */
g_object_set (G_OBJECT (sink), "location", argv[1], NULL);
/* we set the video capabilities on the vidcaps element */
caps =
gst_caps_from_string("video/x-raw,format=(string)I420,width=320,height=240,framerate=(fraction)25/1");
g_object_set (G_OBJECT (vcapsfilter), "caps", caps, NULL);
gst_caps_unref (caps);
/* we set the audio capabilities on the audiocaps element */
caps = gst_caps_from_string("audio/x-raw,rate=44100,channels=2");
g_object_set (G_OBJECT (acapsfilter), "caps", caps, NULL);
gst_caps_unref (caps);
g_object_set (G_OBJECT (vsource), "norm", 255, NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* we add all elements into the pipeline */
/* vsource, vcapsfilter, vidrate, queue1,
asource, aconv, acapsfilter, queue2,
mux, sink */
gst_bin_add_many (GST_BIN (pipeline),
vsource, vcapsfilter, queue1,
/* vsource, vidrate, vcapsfilter, queue1,*/
asource, aconv, acapsfilter, queue2,
/* asource, aconv, audrate, acapsfilter, queue2,*/
mux, sink, NULL);
/* we link the elements together */
/* vsource -> vcapsfilter -> vidrate -> queue1 -> avimux
asource -> aconv -> acapsfilter -> queue2 -> avimux
mux -> sink */
gst_element_link_many (vsource, vcapsfilter, queue1, mux, NULL);
/* gst_element_link_many (vsource, vcapsfilter, vidrate, queue1, mux,
NULL);*/
gst_element_link_many (asource, aconv, acapsfilter, queue2, mux, NULL);
/* gst_element_link_many (asource, aconv, audrate, acapsfilter, queue2,
mux, NULL);*/
gst_element_link_many (mux, sink, NULL);
/* Set the pipeline to "playing" state*/
g_print ("Now recording: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Iterate */
g_print ("Recording (or not!)...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping recording\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (loop);
return 0;
}
--
--
Ian Davidson
--
Facts used in this message may or may not reflect an underlying
objective reality. Facts are supplied for personal use only.
Recipients quoting supplied information do so at their own risk. Facts
supplied may vary in whole or part from widely accepted standards.
While painstakingly researched, facts may or may not be indicative of
actually occurring events or natural phenomena.
The author accepts no responsibility for personal loss or injury
resulting from memorisation and subsequent use.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20130105/529b442d/attachment-0001.html>
More information about the gstreamer-devel
mailing list