Ubuntu under GStreamer configuration and playback audio and video examples

Source: Internet
Author: User
Tags gstreamer

Official website:http://gstreamer.freedesktop.org


GStreamer Installation:

Installing with sudo apt-get install

sudo apt-get install Libgstreamer0.10-dev gstreamer-tools gstreamer0.10-tools Gstreamer0.10-doc
sudo apt-get install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly Gstreamer0.10-plugins-bad Gstreamer0.10-plugins-bad-multiverse


A plugin with the following GST is installed:

Gstreamer0.10-tools

Gstreamer0.10-x

Gstreamer0.10-plugins-base

Gstreamer0.10-plugins-good

gstreamer0.10-plugins-ugly

Gstreamer0.10-plugins-bad

Gstreamer0.10-ffmpeg

Gstreamer0.10-alsa

Gstreamer0.10-schroedinger

Gstreamer0.10-pulseaudio


There may be software that needs to be installed:

sudo apt-get install Bison

sudo apt-get install Flex

sudo apt-get install zlib1g

Mad Decode Plugin

Apt-get Install Libmad0-dev

Apt-get Install gstreamer0.10-plugins-ugly


Initializing GStreamer

#include <stdio.h> #include <gst/gst.h>int main (int   argc,   char *argv[]) {  const Gchar *nano_ STR;  Guint major, minor, Micro, nano;  Gst_init (&ARGC, &argv);  Gst_version (&major, &minor,µ, &nano);  if (nano = = 1)    nano_str = "(CVS)";  else if (nano = = 2)    nano_str = "(prerelease)";  else    nano_str = "";  printf ("This program is linked against GStreamer%d.%d.%d%s\n",          major, minor, Micro, nano_str);  return 0;}


#include <gst/gst.h> #include <glib.h>//define message handler functions, static Gboolean Bus_call (Gstbus *bus,gstmessage *msg,        Gpointer data) {Gmainloop *loop = (Gmainloop *) data;//This is a pointer to the main loop, exiting the loop switch (Gst_message_type (msg)) when accepting the EOS message {            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;    int main (int argc,char *argv[]) {Gmainloop *loop;    Gstelement *pipeline,*source,*decoder,*sink;//define components Gstbus *bus;    Gst_init (&AMP;ARGC,&AMP;ARGV); loop = G_main_loop_new (null,false);//create main loop, formally start loop after executing g_main_loop_run if(argc! = 2)        {G_printerr ("usage:%s <mp3 filename>\n", argv[0]);    return-1;    }//Create pipelines and Components pipeline = gst_pipeline_new ("Audio-player");    Source = Gst_element_factory_make ("Filesrc", "File-source");    Decoder = Gst_element_factory_make ("Mad", "Mad-decoder");    Sink = Gst_element_factory_make ("Autoaudiosink", "audio-output"); if (!pipeline| |! source| |! decoder| |! Sink) {G_printerr ("one element could not be created.        Exiting.\n ");    return-1; }//Set the location parameter of the source.    That is, the file address.    G_object_set (G_object (source), "location", argv[1],null);   Get pipeline Message bus = Gst_pipeline_get_bus (Gst_pipeline (pipeline));    Add Message Monitor Gst_bus_add_watch (Bus,bus_call,loop);    Gst_object_unref (bus);   Add components to the pipeline. Pipeline is a special component that can better make the data Flow Gst_bin_add_many (Gst_bin (pipeline), source,decoder,sink,null);   Connect the component Gst_element_link_many (source,decoder,sink,null) in turn;    Start playing gst_element_set_state (pipeline,gst_state_playing);    G_print ("running\n"); Start Cycle G_maIn_loop_run (loop);    G_print ("returned,stopping playback\n");    Gst_element_set_state (Pipeline,gst_state_null);    Gst_object_unref (Gst_object (pipeline)); return 0;}

Compile run

Gcc-wall test2.c-o test2 $ (pkg-config--cflags--libs gstreamer-0.10)
(Note!!!) This command is written in many places:Gcc-wall $ (pkg-config--cflags--libs gstreamer-0.10)-G Test2.c-o test2, simply compiled! )

./test2./abc.mp3



Play Video:

Ubuntu 12.04
gst-launch-0.10 filesrc location=/tmp/video_stream_pipe ! decodebin ! ffmpegcolorspace ! videoscale ! ximagesink sync=false
Ubuntu 13.10
gst-launch-1.0 filesrc location=/tmp/video_stream_pipe ! decodebin ! videoconvert ! xvimagesink sync=falsegst-launch-1.0 filesrc location=/tmp/video_stream_pipe ! decodebin ! videoconvert ! ximagesink sync=false

Ubuntu under GStreamer configuration and playback audio and video examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.