GStreamer 0.10ã§wavparseãã©ã°ã¤ã³ãããã°ã©ã ä¸ã§ç¨ããä¸ã§ã®ã¡ã¢(åå)
GStreamerã®ãã©ã°ã¤ã³ãç¨ãã¦WAVEãã¡ã¤ã«ãåçãããã¨ãã«wavparseã¨ãããã©ã°ã¤ã³ã使ãã(WAVEãã¡ã¤ã«ããçã®é³å£°ãã¼ã¿ãå¾ããã)ãä¾ãã°gst-launch-0.10ãç¨ããã¨
$ gst-launch-0.10 filesrc location=[WAVEãã¡ã¤ã«ã®å ´æ] ! wavparse ! audioconvert ! audioresample ! autoaudiosink
ã®ããã«ãã¦ãã®ãã¡ã¤ã«ãåçã§ããã
ããããèªä½ã®ããã°ã©ã ã§
- ãã¤ãã©ã¤ã³ãªãã¸ã§ã¯ããä½æ
- åè¦ç´ (ãã©ã°ã¤ã³)ãä½æãã¦ãã¤ãã©ã¤ã³ãªãã¸ã§ã¯ãã«è¿½å
- è¦ç´ ãé çªéãã«æ¥ç¶(ãªã³ã¯)ãã
- ãã¤ãã©ã¤ã³ã®ç¶æ ãSTATE_PLAYINGã«ãã
- GLibã®ã¡ã¤ã³ã«ã¼ããéå§
ã¨ãã¦ãããããåããã¦ã¿ãã¨è¦ç´ ã®æ¥ç¶(ãªã³ã¯)ã®æ®µéã§wavparseãããã®æ¬¡ã®ãã©ã°ã¤ã³ã¸ã®æ¥ç¶(ã ã)ã確å®ã«å¤±æããã
ããã§ã¯ãã®ä»¶ã«ã¤ãã¦ãæ±ãããè¨èªã«ã¤ãã¦ã¯Pythonã®ãã¤ã³ãã£ã³ã°(PyGST)ãç¨ãã¦ãããå¦çã®è¦é ã¯Valaè¨èªãªã©ã®ä»ã®è¨èªã§ãåæ§(Cè¨èªã®å ´åã¯ãªãã¸ã§ã¯ãã®åç
§ã«ã¦ã³ã¿æä½ãªã©ã追å ã§å¿
è¦ã«ãªã)ã
失æä¾
ãã®è¨äºãæ¸ãããæç¹ã§ã¯GStreamerã®Pythonãã¤ã³ãã£ã³ã°ã¯ãã¼ã¸ã§ã³2ç³»ã®Pythonåããªã®ã§2ç³»ãç¨ãããã¨ã«ãªãããprint()é¢æ°ãªã©ã®æ°ããæ¸ãæ¹ãç¨ãã¦ããé¢ä¿ã§ãä¸ã®ã¹ã¯ãªããã¯ãã¼ã¸ã§ã³2.6系以ä¸ã対象ã¨ããã
[ä»»æ]ãã¡ã¤ã«å: playwave_ng.py
#! /usr/bin/python # -*- coding: utf-8 -*- from __future__ import print_function # 2.6系以ä¸ã§print()é¢æ°ãç¨ãã import sys class PlayWaveNG: """ GStreamerãç¨ãã¦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) < 2: print ('usage: {0} [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] # WAVEãããã解æãã¦çã®é³å£°ãã¼ã¿ãå¾ã wavparse = gst.element_factory_make ('wavparse', 'parse') # å¤æ(ãããããªãã¨æ¬¡ã®sinkã«ã¤ãªãããªãå ´åããã) audioconvert = gst.element_factory_make ('audioconvert', 'convert') audioresample = gst.element_factory_make ('audioresample', 'resample') # èªåã§ãªã¼ãã£ãªåºåå ãæ¢ãã¦æ¸¡ãã¦ããã autoaudiosink = gst.element_factory_make ('autoaudiosink', 'sink') # å¦çã®æµããéããã¤ãã©ã¤ã³ 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, wavparse, audioconvert, audioresample, autoaudiosink) # è¦ç´ ãæ¥ç¶ãã¦ãã # Pythonã§ã¯gst.LinkErrorãåºããValaã§ã¯æ»ãå¤ã§å¦çãã try: filesrc.link (wavparse) # ããã§ç¢ºå®ã«å¤±æãã wavparse.link (audioconvert) audioconvert.link (audioresample) audioresample.link (autoaudiosink) 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 = PlayWaveNG () sys.exit (app.main ())
ä¸ã¯å®è¡ä¾ããã¡ã¤ã«ãæå®ãã¦ããªã³ã¯ã®é¨åã§å¤±æãã¦ããã
$ [playwave_ng.pyã®å ´æ] [WAVEãã¡ã¤ã«ã®å ´æ] Error: failed to link parse with convert
使ç¨ãããã¼ã¸ã§ã³:
- Python 2.6.5
- PyGObject 2.21.1
- PyGST 0.10.18
- GStreamerã©ã¤ãã©ãª 0.10.29