2010-10-05
Mplayer: 字幕以外のところを飛ばして再生。
http://code.activestate.com/recipes/542195-access-mplayer-slave-mode-from-python/
を使って、 mplayer を slave モードで動かし、python から操作する。
「何秒間再生」がわからなかったので、system の sleep で代用。
MAX_SPACE 秒以下の間隔は無視して連続再生する。
mplayer.py に統合して、クラスのメソッドとして書いた方がいい気はする。
MAX_SPACE=5 from pysrt import SubRipFile, SubRipItem, SubRipTime import sys,os, mplayer from copy import deepcopy # paths path_to_srt = os.path.abspath(sys.argv[1]) # paths path_to_video = os.path.abspath(sys.argv[2]) # Open .srt file subs = SubRipFile.open(path_to_srt, "utf-8") SubRipFile.fixindex_0(subs) # Fix subs so that the index of each element matches their actual index st = subs[0].start ed = subs[0].end SECONDS_RATIO = 1000000 MINUTES_RATIO = SECONDS_RATIO * 60 HOURS_RATIO = MINUTES_RATIO * 60 def second(t): ordinal = t.hour * HOURS_RATIO \ + t.minute * MINUTES_RATIO \ + t.second * SECONDS_RATIO \ + t.microsecond return float(ordinal)/SECONDS_RATIO s = SubRipTime(0,0,10,500) tm = s.to_time() print second(tm) mp = mplayer.MPlayer() mp.command('loadfile', path_to_video) # mp.command('sub_load', path_to_srt) for i, sub in enumerate(subs[1:]): # Skip the first and last if i < len(subs)-1: # if i < 20: if sub.start - ed > SubRipTime(0,0,MAX_SPACE,0): one = SubRipTime(0,0,1,0) mp.command('seek %f 2' % second( (st-one).to_time())) print second( (ed-st).to_time() ) os.system('sleep %f' % second( (ed-st+one).to_time() )) st = sub.start ed = sub.end else: ed = sub.end else: ed = sub.end mp.command('seek %f 2' % second( (st-one).to_time())) print second( (ed-st).to_time() ) os.system('sleep %f' % second( (ed-st+one).to_time() )) mp.command('quit') #print command
トラックバック - http://d.hatena.ne.jp/matoge/20101005/1286285679
リンク元
- 2 http://k.hatena.ne.jp/keywordblog/fansub
- 2 http://www.google.co.jp/search?hl=ja&q=subs2srs&lr=lang_ja&rlz=
- 1 http://b.hatena.ne.jp/toton/20100820
- 1 http://search.yahoo.co.jp/search?p=STAR+WARS+script&aq=-1&ei=UTF-8&pstart=1&fr=top_ga1_sa&b=61
- 1 http://www.google.co.jp/search?hl=ja&biw=1680&bih=870&q=python+??????+revers&aq=f&aqi=g1&aql=&oq=&gs_rfai=
- 1 http://www.google.co.jp/search?hl=ja&q=Spaced+repetition+system&lr=lang_ja&rlz=
- 1 http://www.google.co.jp/search?hl=ja&rlz=1G1ACAW_JAJP371&q=spaced+repetition&aq=7&aqi=g9g-m1&aql=&oq=spaced+&gs_rfai=
- 1 http://www.google.co.jp/search?hl=ja&safe=active&client=firefox-a&hs=mqn&rlz=1R1GGGL_ja___JP315&q=deepcopy+python+reverse&btnG=検索
- 1 http://www.google.co.jp/search?hl=ja&source=hp&biw=1280&bih=835&q=spaced+repetition+software&aq=2&aqi=g3&aql=&oq=Spaced+repetition&gs_rfai=
- 1 http://www.google.co.jp/search?q=ピリオド 三点リーダ&hl=ja&ei=FXiuTODhBo6PcZfTuNwN&start=20&sa=N