GStreamer 0.10ã§é³å£°ãè¤æ°ã®åºåå ã¸åå²ããã(é³ãé³´ããã¨åæã«ãã¡ã¤ã«ã¸æ¸ãåºããªã©)
GStreamerã®ä»çµã¿ã®ä¸ã§ãããè¦ç´ (ãã©ã°ã¤ã³)ããåºåãããé³å£°ãã¼ã¿ã
- ãµã¦ã³ãã«ã¼ãã¸åºåãã(é³ãé³´ãã)
- ãã¡ã¤ã«ã«æ¸ãåºã
ã¨ãã£ãè¤æ°ã®åºåå
ã¸æ¸¡ãããã¨ãããã¨ãããã
ããããã¨ãã«å½¹ã«ç«ã¤ã®ãteeã¨ãããã©ã°ã¤ã³ã§ãã³ãã³ãã®teeã®ããã«ãåãåã£ããã¼ã¿ããã®ã¾ã¾2ã¤ã«åå²ãããæ©è½ãæã¤ããããç¨ããã¨ä¸ã®ãããªè¦æ±ã¯ç°¡åã«æºãããã
ãã ããteeã¨åæã«queueã¨ãããã©ã°ã¤ã³ã®è¦ç´ ã2ã¤ç¨æããteeããããããã®queueã¸ãªã³ã¯(æ¥ç¶)ããå½¢ã«ããªãã¨
http://gstreamer.freedesktop.org/wiki/FAQ#MypipelinewithmultiplesinksneverreachesthePAUSEDstate.2CwhatamIdoingwrong.3F
ã«æ¸ããã¦ããããã«PAUSEDã®ç¶æ
ã«ã§ããªãã¨ã®ãã¨ãªã®ã§ãPAUSEDã®ç¶æ
ã«ããããã°ã©ã ãæ¸ãå ´åã«ã¯æ³¨æããã
å¦çã®æµããå³ã«ããã¨
src > [éä¸ã®å¦çãè¡ãè¦ç´ ...] > tee > [éä¸ã®å¦çãè¡ãè¦ç´ ...] > sink1 (åºåå 1) (å ¥å) +--> [éä¸ã®å¦çãè¡ãè¦ç´ ...] > sink2 (åºåå 2)
ã®ããã«ãããã¨ã«ãªããteeããã®æ¥ç¶ã¯teeãã©ã°ã¤ã³ã®è¦ç´ ã®ã¡ã³ãé¢æ°link()ãããããã®queueãã©ã°ã¤ã³ã®è¦ç´ ã«å¯¾ãã¦å¼ã³åºãå½¢ã§è¡ãã
tee = gst.element_factory_make ('tee', 'tee') queue1 = gst.element_factory_make ('queue', 'queue1') queue2 = gst.element_factory_make ('queue', 'queue2') ... [teeã®1ã¤åã®è¦ç´ ].link (tee) tee.link (queue1) tee.link (queue2) queue1.link ( ... ) queue2.link ( ... )
ä¸ã¯ä¾ã§ãFLACãã¡ã¤ã«ã®å ´æã¨åºåWAVEãã¡ã¤ã«ã®å ´æãå¼æ°ã«æå®ãã¦å®è¡ããã¨ããããåçããªãããã³ã¼ãçµæãWAVEãã¡ã¤ã«ã«ä¿åããããGStreamer 0.10でwavparseプラグインをプログラム中で用いる上でのメモ(前半)ããGStreamer 0.10でwavparseプラグインをプログラム中で用いる上でのメモ(後半)ãã¨åæ§ããã¼ã¸ã§ã³2.6系以ä¸ã®Pythonã対象ã¨ããã
[ä»»æ]ãã¡ã¤ã«å: gstteetest.py
#! /usr/bin/python # -*- coding: utf-8 -*- from __future__ import print_function # 2.6系以ä¸ã§print()é¢æ°ãç¨ãã import sys class GstTeeTest: """ GStreamerã®teeãã©ã°ã¤ã³ãç¨ãããã¹ã FLACãã¡ã¤ã«ã®åçã¨WAVEãã¡ã¤ã«æ¸ãåºããåæã«è¡ããã¹ã """ __retval = 0 def __on_bus_message_error (self, bus, message): """ GStreamerã®ãã¹ã«ã¨ã©ã¼ã¡ãã»ã¼ã¸ãæµãã """ # ã¨ã©ã¼ã®è§£æå¦ç (gerror, debug) = message.parse_error () print (debug, file=sys.stderr) self.__retval = 1 # ã¡ã¤ã³ã«ã¼ããæãã self.__loop.quit () def main (self): """ ã¡ã¤ã³å¦ç """ # ã³ãã³ãè¡å¼æ°ãå ¥åãã¡ã¤ã«ã¨ãã if len (sys.argv) < 3: print ('usage: {0} [FLAC file] [WAVE file]'.format (sys.argv[0])) return 0 # ã¢ã¸ã¥ã¼ã«ã®èªã¿è¾¼ã¿ try: import gst except: print ('Error: GStreamer Python binding is not installed.', file=sys.stderr) return 1 try: import glib except: print ('Error: GLib Python binding is not installed.', file=sys.stderr) return 1 # ã¡ã¤ã³ã«ã¼ã self.__loop = glib.MainLoop () # ãã¡ã¤ã«ã®å ´æãGObjectããããã£locationã¨ã㦠# ãã®å 容ãéãã¦éãåºããã©ã°ã¤ã³ filesrc = gst.element_factory_make ('filesrc', 'src') filesrc.props.location = sys.argv[1] # FLACãããã解æ(ä¸èº«ã¯FLACã¨ã³ã³ã¼ãããã¦ããç¶æ ) flacparse = gst.element_factory_make ('flacparse', 'parse') # FLACã®ãã³ã¼ã(ããã§çã®é³å£°ãã¼ã¿ã«ãªã) flacdec = gst.element_factory_make ('flacdec', 'decode') # åå² # 注æ:å¿ ãåå²ãã次ã®è¦ç´ ã¯queueãã©ã°ã¤ã³ã«ãªãããã«ãã # ããããªãã¨ä¸å ·åãèµ·ãããã¨ããã # http://gstreamer.freedesktop.org/wiki/FAQ#MypipelinewithmultiplesinksneverreachesthePAUSEDstate.2CwhatamIdoingwrong.3F tee = gst.element_factory_make ('tee', 'tee') queue_audio = gst.element_factory_make ('queue', 'queue_audio') queue_file = gst.element_factory_make ('queue', 'queue_file') # å¤æ(ãããããªãã¨æ¬¡ã®sinkã«ã¤ãªãããªãå ´åããã) audioconvert = gst.element_factory_make ('audioconvert', 'convert') audioresample = gst.element_factory_make ('audioresample', 'resample') # èªåã§ãªã¼ãã£ãªåºåå ãæ¢ãã¦æ¸¡ãã¦ããã autoaudiosink = gst.element_factory_make ('autoaudiosink', 'audiosink') # WAVEãã¡ã¤ã«ã«ã¨ã³ã³ã¼ã wavenc = gst.element_factory_make ('wavenc', 'encode') # ãã¡ã¤ã«ã¸ã®æ¸ãåºã filesink = gst.element_factory_make ('filesink', 'filesink') filesink.props.location = sys.argv[2] # å¦çã®æµããéããã¤ãã©ã¤ã³ pl = gst.Pipeline () # å é¨ã¡ãã»ã¼ã¸ãå¦çãããã¹ bus = pl.get_bus () # ä¸ã®2ã¤ã®GObjectã·ã°ãã«ãæ¥ç¶ããããã«å¿ è¦ bus.add_signal_watch () # ã¹ããªã¼ã çµç«¯ã«ãªã£ããã¡ã¤ã³ã«ã¼ããæããããã«ãã bus.connect ('message::eos', lambda bus, message: self.__loop.quit ()) # ã¨ã©ã¼ã¡ãã»ã¼ã¸ãåºãã表示/çµäºã®ããã®ãã³ãã©ãå¼ã°ããããã«ãã bus.connect ('message::error', self.__on_bus_message_error) # ãã¤ãã©ã¤ã³ã«è¦ç´ ã追å (é çªã¯ä»»æ) pl.add (filesrc, flacparse, flacdec, tee, queue_audio, audioconvert, audioresample, autoaudiosink, queue_file, wavenc, filesink) # è¦ç´ ãæ¥ç¶ãã¦ãã # Pythonã§ã¯gst.LinkErrorãåºããValaã§ã¯æ»ãå¤ã§å¦çãã # # filesrc > flacparse > flacdec # > tee > queue_audio > audioconvert > audioresample > autoaudiosink (ãµã¦ã³ãã«ã¼ãåºå) # +--> queue_file > wavenc > filesink (ãã¡ã¤ã«æ¸ãåºã) try: filesrc.link (flacparse) flacparse.link (flacdec) # åå²ãããã¨ããã§teeã«å ¥ãã flacdec.link (tee) # teeããããããã®queueãã©ã°ã¤ã³ã«ãªã³ã¯ãã tee.link (queue_audio) tee.link (queue_file) # é³ãé³´ããããã®ã«ã¼ã queue_audio.link (audioconvert) audioconvert.link (audioresample) audioresample.link (autoaudiosink) # çµç¹ # WAVEãã¡ã¤ã«ã«æ¸ãåºãããã®ã«ã¼ã queue_file.link (wavenc) wavenc.link (filesink) # çµç¹ except gst.LinkError as msg: print ('Error: {0}'.format (msg), file=sys.stderr) return 1 # æºåå®äº # åçç¶æ ã«ãã¦ã¡ã¤ã³ã«ã¼ãéå§ pl.set_state (gst.STATE_PLAYING) try: self.__loop.run () except KeyboardInterrupt: # Ctrl+Cãæ¼ãããã¨ãã¯ããã§ã«ã¼ããæãã¦åæ¢ã»çµäº # ãããããªãã¨GStreamerã®CRITICALã¡ãã»ã¼ã¸ãåºã self.__loop.quit () # åæ¢ç¶æ ã«ãã¦çµäº pl.set_state (gst.STATE_NULL) return self.__retval if __name__ == '__main__': app = GstTeeTest () sys.exit (app.main ())
ä¸ã¯å®è¡ä¾ã
$ [gstteetest.pyã®å ´æ] [FLACãã¡ã¤ã«ã®å ´æ] [WAVEãã¡ã¤ã«ã®å ´æ]
é¢é£è¨äº:
åèURL:
使ç¨ãããã¼ã¸ã§ã³:
- Python 2.6.5
- PyGObject 2.21.1
- PyGST 0.10.18
- GStreamerã©ã¤ãã©ãª 0.10.29