Difference between revisions of "Gstreamer"

From ArmadeusWiki
Jump to: navigation, search
(Links)
m (Take photos)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Under_Construction}}
 
{{Note|gstreamer has only been introduced recently in Buildroot, so you will need to use our "still in development" migration to Buildroot 2010.xx version.}}
 
  
 
==Installation==
 
==Installation==
Line 66: Line 64:
 
<pre class="apf">
 
<pre class="apf">
 
# gst-launch audiotestsrc ! audioconvert ! audioresample ! alsasink
 
# gst-launch audiotestsrc ! audioconvert ! audioresample ! alsasink
Setting pipeline to PAUSED ...
+
</pre>
Pipeline is PREROLLING ...
+
* same test but with a given sound card (if you have more than one like on the [[APF6Dev]]):
Pipeline is PREROLLED ...
+
<pre class="apf">
Setting pipeline to PLAYING ...
+
# gst-launch audiotestsrc ! audioconvert ! audioresample ! alsasink device='sysdefault:CARD=imxhdmisoc'
New clock: GstAudioSinkClock
+
 
</pre>
 
</pre>
 
* play a music file (here a .ogg, supposing the libgstogg plugin was installed):
 
* play a music file (here a .ogg, supposing the libgstogg plugin was installed):
Line 76: Line 73:
 
# gst-launch filesrc location=toto.ogg ! decodebin ! audioconvert ! audioresample ! alsasink
 
# gst-launch filesrc location=toto.ogg ! decodebin ! audioconvert ! audioresample ! alsasink
 
</pre>
 
</pre>
* record a sound from a mic (APF27 only) and store it as an uncompressed wav file:
+
* record a sound from an Input Line/Mic and store it as an uncompressed wav file:
 
<pre class="apf">
 
<pre class="apf">
 
# gst-launch alsasrc ! audioconvert ! audioresample ! wavenc ! filesink location=mic.wav
 
# gst-launch alsasrc ! audioconvert ! audioresample ! wavenc ! filesink location=mic.wav
 
</pre>
 
</pre>
* record a sound from a mic (APF27 only) and compress it (ogg/worbis):
+
* record a sound from an Input Line/Mic and compress it (ogg/worbis):
 
<pre class="apf">
 
<pre class="apf">
 
# gst-launch alsasrc ! audioconvert ! audioresample ! vorbisenc ! oggmux ! filesink location=mic.ogg
 
# gst-launch alsasrc ! audioconvert ! audioresample ! vorbisenc ! oggmux ! filesink location=mic.ogg
 
</pre>
 
</pre>
* record a sound from a mic (APF27 only) @ 8KHz (16KHz is too CPU consuming), compress it with [[Speex]] and send it to your Host (here 192.168.1.2) at port 6666:
+
* record a sound from an Input Line/Mic @ 8KHz (16KHz is too CPU consuming on [[APF27]]), compress it with [[Speex]] and send it to your Host (here 192.168.1.2) at port 6666:
 
<pre class="apf">
 
<pre class="apf">
 
# gst-launch -v alsasrc ! audioconvert ! audioresample ! 'audio/x-raw-int,rate=8000,width=16,channels=1' ! speexenc ! rtpspeexpay ! udpsink host=192.168.1.2 port=6666
 
# gst-launch -v alsasrc ! audioconvert ! audioresample ! 'audio/x-raw-int,rate=8000,width=16,channels=1' ! speexenc ! rtpspeexpay ! udpsink host=192.168.1.2 port=6666
 
</pre>
 
</pre>
 +
* to live decode the stream on your PC:
 
<pre class="host">
 
<pre class="host">
 
$ gst-launch udpsrc port=6666 caps="application/x-rtp, media=(string)audio, clock-rate=(int)16000, encoding-name=(string)SPEEX, encoding-params=(string)1, payload=(int)110" ! gstrtpjitterbuffer ! rtpspeexdepay ! speexdec ! audioconvert ! audioresample ! autoaudiosink
 
$ gst-launch udpsrc port=6666 caps="application/x-rtp, media=(string)audio, clock-rate=(int)16000, encoding-name=(string)SPEEX, encoding-params=(string)1, payload=(int)110" ! gstrtpjitterbuffer ! rtpspeexdepay ! speexdec ! audioconvert ! audioresample ! autoaudiosink
 
</pre>
 
</pre>
 +
* to store the stream in Wav format on your PC:
 
<pre class="host">
 
<pre class="host">
 
$ gst-launch udpsrc port=6666 caps="application/x-rtp, media=(string)audio, clock-rate=(int)16000, encoding-name=(string)SPEEX, encoding-params=(string)1, payload=(int)110" ! gstrtpjitterbuffer ! rtpspeexdepay ! speexdec ! audioconvert ! audioresample ! wavenc ! filesink location=toto.wav
 
$ gst-launch udpsrc port=6666 caps="application/x-rtp, media=(string)audio, clock-rate=(int)16000, encoding-name=(string)SPEEX, encoding-params=(string)1, payload=(int)110" ! gstrtpjitterbuffer ! rtpspeexdepay ! speexdec ! audioconvert ! audioresample ! wavenc ! filesink location=toto.wav
 +
</pre>
 +
 +
===Video===
 +
====Plugins====
 +
* You'll need to activate a few plugins in Buildroot menuconfig to play videos with Gstreamer:
 +
<pre class="config">
 +
Package Selection for the target  --->
 +
    Audio and video libraries and applications  --->
 +
        ...
 +
        -*-  gst-plugins-base  --->
 +
              [*]  ffmpegcolorspace (mandatory for video playback)
 +
              ...
 +
              [*]  playback (mandatory)
 +
        [*]  gst-plugins-good  --->
 +
              [*]  videobox
 +
              [*]  videocrop
 +
        [*]  gst-plugins-bad  --->
 +
              [*]  fbdev
 +
</pre>
 +
 +
====Test installation====
 +
* To test your Gstreamer installation, you need to select a plugin in Buildroot menuconfig:
 +
<pre class="config">
 +
Package Selection for the target  --->
 +
    Audio and video libraries and applications  --->
 +
        ...
 +
        -*-  gst-plugins-base  --->
 +
              [*]  videotestsrc
 +
</pre>
 +
 +
* Then on your APF system, launch the following command:
 +
<pre class="apf">
 +
# gst-launch -v videotestsrc ! videocrop top=42 left=1 right=4 bottom=0 ! fbdevsink
 +
</pre>
 +
You must see a pattern displayed on the screen if your Gstreamer installation is working well.
 +
 +
====Play video====
 +
=====MPEG 1/2=====
 +
* If you want to play MPEG 1/2 video, you have to install some plugins in Buildroot menuconfig:
 +
<pre class="config">
 +
Package Selection for the target  --->
 +
    Audio and video libraries and applications  --->
 +
        ...
 +
        [*]  gst-plugins-bad  --->
 +
              [*]  mpegdemux
 +
              [*]  mpegtsmux
 +
              [*]  mpeg4videoparse
 +
              [*]  mpegvideoparse
 +
        [*]  gst-plugins-ugly  --->
 +
              [*]  mpegaudioparse
 +
              [*]  mpegstream
 +
</pre>
 +
 +
======With FFmpeg decoder======
 +
* In Buildroot menuconfig, select:
 +
<pre class="config">
 +
Package Selection for the target  --->
 +
    Audio and video libraries and applications  --->
 +
        ...
 +
        -*- ffmpeg  --->
 +
        ...
 +
        [*] gst-ffmpeg
 +
</pre>
 +
 +
* On your APF system, play the video with the command:
 +
<pre class="apf">
 +
# gst-launch filesrc location=VIDEO_FILE_LOCATION ! mpegdemux ! ffdec_mpegvideo ! ffmpegcolorspace ! fbdevsink
 +
</pre>
 +
 +
======With mpeg2dec decoder======
 +
* In Buildroot menuconfig, select:
 +
<pre class="config">
 +
Package Selection for the target  --->
 +
    Audio and video libraries and applications  --->
 +
        ...
 +
        [*]  gst-plugins-ugly  --->
 +
              [*]  mpeg2dec
 +
</pre>
 +
 +
* On your APF system, play the video with the command:
 +
<pre class="apf">
 +
# gst-launch filesrc location=VIDEO_FILE_LOCATION ! mpegdemux ! mpeg2dec ! ffmpegcolorspace ! fbdevsink
 +
</pre>
 +
 +
====Take photos====
 +
* You will need some more plugins:
 +
<pre class="config">
 +
Package Selection for the target  --->
 +
    Audio and video libraries and applications  --->
 +
        ...
 +
        [*]  gst-plugins-good  --->
 +
              [*]  jpeg (JPEG support)
 +
              [*]  png (PNG support)
 +
</pre>
 +
 +
* 1 photo:
 +
<pre class="apf">
 +
# gst-launch v4l2src num-buffers=1 ! video/x-raw-rgb,width=1024,height=768 ! ffmpegcolorspace ! pngenc ! filesink location=/root/photo.png
 +
</pre>
 +
 +
* lots of photo: :-)
 +
<pre class="apf">
 +
# gst-launch v4l2src ! video/x-raw-rgb,width=1024,height=768 ! ffmpegcolorspace ! pngenc ! multifilesink location=/root/photo%03d.png
 +
</pre>
 +
 +
{{Note|''ffmpegcolorspace'' should be replaced with ''videoconvert'' on recent gstreamer versions (1.10+) and ''pngenc'' can be replaced with ''jpegenc'' for JPEG format. ''v4l2src'' should be replaced by ''imxv4l2videosrc'' on Freescale kernels}}
 +
 +
==APF6 with Freescale kernel==
 +
On the APF6 with legacy Freescale kernel (''apf6legacy_defconfig'' or ''apf6legacy-4.1_defconfig''), you can use hardware H.264 VPU to decode/encode videos without using CPU.
 +
* First get some video for test ;-)
 +
<pre class="apf">
 +
# cd /usr/share/
 +
# wget http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov
 +
</pre>
 +
 +
* Play the H.264 video with hardware decoding and framebuffer rendering:
 +
<pre class="apf">
 +
# gst-launch filesrc location=/usr/share/big_buck_bunny_480p_h264.mov ! qtdemux ! vpudec ! mfw_v4lsink
 +
</pre>
 +
 +
* Same with audio:
 +
<pre class="apf">
 +
# gst-launch filesrc location=/usr/share/big_buck_bunny_480p_h264.mov ! qtdemux name=demux \
 +
    demux. ! queue max-size-buffers=0 max-size-time=0 ! vpudec ! mfw_v4lsink \
 +
    demux. ! queue max-size-buffers=0 max-size-time=0 ! decodebin ! audioconvert ! audioresample ! alsasink
 +
</pre>
 +
 +
* Display CSI camera input to HDMI monitor with 2D acceleration:
 +
<pre class="apf">
 +
# gst-launch-1.0 imxv4l2videosrc ! imxg2dvideosink
 
</pre>
 
</pre>
  

Latest revision as of 15:13, 14 December 2017

Installation

$ make menuconfig
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        [*] gstreamer
        [*]   require libxml2 for registry and load/save
        -*-   gst-plugins-base  --->
        [*]   gst-plugins-good  --->
        [*]   gst-plugins-bad  --->
        [*]   gst-plugins-ugly  --->

Plugins worth to activate:

  • base:
  • good:
  • bad:
  • ugly:

Usage

Check installed plugins

  • To see all installed plugins:
# gst-inspect
videoscale:  videoscale: Video scaler
queue2:  queue2: Queue               
ffmpegcolorspace:  ffmpegcolorspace: FFMPEG Colorspace converter
audiorate:  audiorate: Audio rate adjuster                      
audioconvert:  audioconvert: Audio converter                    
audioresample:  audioresample: Audio resampler                  
volume:  volume: Volume
...
  • To have more details about one particular plugin (here alsasrc):
# gst-inspect alsasrc
Factory Details:     
  Long name:    Audio source (ALSA)
  Class:        Source/Audio       
  Description:  Read from a sound card via ALSA
  Author(s):    Wim Taymans <wim@fluendo.com>  
  Rank:         primary (256)                  

Plugin Details:
  Name:                 alsa
  Description:          ALSA plugin library
  Filename:             /usr/lib/gstreamer-0.10/libgstalsa.so
  Version:              0.10.25                              
  License:              LGPL                                 
  Source module:        gst-plugins-base                     
  Binary package:       GStreamer Base Plug-ins source release
  Origin URL:           Unknown package origin                
...
<cut>

Audio

  • play a monotic tone to check your sound configuration is working (if not please configure ALSA):
# gst-launch audiotestsrc ! audioconvert ! audioresample ! alsasink
  • same test but with a given sound card (if you have more than one like on the APF6Dev):
# gst-launch audiotestsrc ! audioconvert ! audioresample ! alsasink device='sysdefault:CARD=imxhdmisoc'
  • play a music file (here a .ogg, supposing the libgstogg plugin was installed):
# gst-launch filesrc location=toto.ogg ! decodebin ! audioconvert ! audioresample ! alsasink
  • record a sound from an Input Line/Mic and store it as an uncompressed wav file:
# gst-launch alsasrc ! audioconvert ! audioresample ! wavenc ! filesink location=mic.wav
  • record a sound from an Input Line/Mic and compress it (ogg/worbis):
# gst-launch alsasrc ! audioconvert ! audioresample ! vorbisenc ! oggmux ! filesink location=mic.ogg
  • record a sound from an Input Line/Mic @ 8KHz (16KHz is too CPU consuming on APF27), compress it with Speex and send it to your Host (here 192.168.1.2) at port 6666:
# gst-launch -v alsasrc ! audioconvert ! audioresample ! 'audio/x-raw-int,rate=8000,width=16,channels=1' ! speexenc ! rtpspeexpay ! udpsink host=192.168.1.2 port=6666
  • to live decode the stream on your PC:
$ gst-launch udpsrc port=6666 caps="application/x-rtp, media=(string)audio, clock-rate=(int)16000, encoding-name=(string)SPEEX, encoding-params=(string)1, payload=(int)110" ! gstrtpjitterbuffer ! rtpspeexdepay ! speexdec ! audioconvert ! audioresample ! autoaudiosink
  • to store the stream in Wav format on your PC:
$ gst-launch udpsrc port=6666 caps="application/x-rtp, media=(string)audio, clock-rate=(int)16000, encoding-name=(string)SPEEX, encoding-params=(string)1, payload=(int)110" ! gstrtpjitterbuffer ! rtpspeexdepay ! speexdec ! audioconvert ! audioresample ! wavenc ! filesink location=toto.wav

Video

Plugins

  • You'll need to activate a few plugins in Buildroot menuconfig to play videos with Gstreamer:
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        -*-   gst-plugins-base  --->
              [*]   ffmpegcolorspace (mandatory for video playback)
              ...
              [*]   playback (mandatory)
        [*]   gst-plugins-good  --->
              [*]   videobox
              [*]   videocrop
        [*]   gst-plugins-bad  --->
              [*]   fbdev

Test installation

  • To test your Gstreamer installation, you need to select a plugin in Buildroot menuconfig:
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        -*-   gst-plugins-base  --->
              [*]   videotestsrc
  • Then on your APF system, launch the following command:
# gst-launch -v videotestsrc ! videocrop top=42 left=1 right=4 bottom=0 ! fbdevsink

You must see a pattern displayed on the screen if your Gstreamer installation is working well.

Play video

MPEG 1/2
  • If you want to play MPEG 1/2 video, you have to install some plugins in Buildroot menuconfig:
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        [*]   gst-plugins-bad  --->
              [*]   mpegdemux
              [*]   mpegtsmux
              [*]   mpeg4videoparse
              [*]   mpegvideoparse
        [*]   gst-plugins-ugly  --->
              [*]   mpegaudioparse
              [*]   mpegstream
With FFmpeg decoder
  • In Buildroot menuconfig, select:
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        -*- ffmpeg  --->
        ...
        [*] gst-ffmpeg
  • On your APF system, play the video with the command:
# gst-launch filesrc location=VIDEO_FILE_LOCATION ! mpegdemux ! ffdec_mpegvideo ! ffmpegcolorspace ! fbdevsink
With mpeg2dec decoder
  • In Buildroot menuconfig, select:
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        [*]   gst-plugins-ugly  --->
              [*]   mpeg2dec
  • On your APF system, play the video with the command:
# gst-launch filesrc location=VIDEO_FILE_LOCATION ! mpegdemux ! mpeg2dec ! ffmpegcolorspace ! fbdevsink

Take photos

  • You will need some more plugins:
Package Selection for the target  --->
    Audio and video libraries and applications  --->
        ...
        [*]   gst-plugins-good  --->
              [*]   jpeg (JPEG support)
              [*]   png (PNG support)
  • 1 photo:
# gst-launch v4l2src num-buffers=1 ! video/x-raw-rgb,width=1024,height=768 ! ffmpegcolorspace ! pngenc ! filesink location=/root/photo.png
  • lots of photo: :-)
# gst-launch v4l2src ! video/x-raw-rgb,width=1024,height=768 ! ffmpegcolorspace ! pngenc ! multifilesink location=/root/photo%03d.png
Note Note: ffmpegcolorspace should be replaced with videoconvert on recent gstreamer versions (1.10+) and pngenc can be replaced with jpegenc for JPEG format. v4l2src should be replaced by imxv4l2videosrc on Freescale kernels


APF6 with Freescale kernel

On the APF6 with legacy Freescale kernel (apf6legacy_defconfig or apf6legacy-4.1_defconfig), you can use hardware H.264 VPU to decode/encode videos without using CPU.

  • First get some video for test ;-)
# cd /usr/share/
# wget http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov
  • Play the H.264 video with hardware decoding and framebuffer rendering:
# gst-launch filesrc location=/usr/share/big_buck_bunny_480p_h264.mov ! qtdemux ! vpudec ! mfw_v4lsink
  • Same with audio:
# gst-launch filesrc location=/usr/share/big_buck_bunny_480p_h264.mov ! qtdemux name=demux \
    demux. ! queue max-size-buffers=0 max-size-time=0 ! vpudec ! mfw_v4lsink \
    demux. ! queue max-size-buffers=0 max-size-time=0 ! decodebin ! audioconvert ! audioresample ! alsasink
  • Display CSI camera input to HDMI monitor with 2D acceleration:
# gst-launch-1.0 imxv4l2videosrc ! imxg2dvideosink

Links