OSDN Git Service

implement sar using encode function.
[rec10/rec10-git.git] / rec10 / trunk / src / ts2x264.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import commands
6 import configreader
7 import os
8 import os.path
9 import re
10 import random
11
12 import recdblist
13 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
14     """
15     pinで指定されたファイルをpoutにx264でエンコードして書き出す
16     """
17     dualpass = 0
18     is24fps=0
19     size="HD"
20     crf=18
21     quality=4
22     quality=int(configreader.getenv("x264_preset"))
23     crf=int(configreader.getenv("crf"))
24     if re.search("H", opts):
25         size = "HD"
26     if re.search("S", opts):
27         size = "WVGA"
28     if re.search("F", opts):
29         size = "FullHD"
30     if re.search("W",opts):
31         size = "WVGA"
32     if re.search("MW8", opts):
33         size = "QVGA_BASE"
34         crf=crf+4
35     if re.search("MW9", opts):
36         size = "WVGA_BASE"
37         crf=crf+2
38     if re.search("v", opts):
39         is24fps=1
40         crf=int(configreader.getenv("animation_crf"))
41     if re.search("a", opts):
42         is24fps=1
43         crf=int(configreader.getenv("animation_crf"))
44     if re.search("q",opts):
45         quality=quality-2
46     if re.search("w",opts):
47         quality=quality-1
48     if re.search("e",opts):
49         quality=quality+1
50     if re.search("r",opts):
51         quality=quality+2
52     if re.search("u",opts):
53         crf=crf+2
54     if re.search("i",opts):
55         crf=crf+1
56     if re.search("o",opts):
57         crf=crf-1
58     if re.search("p",opts):
59         crf=crf-2
60     if re.search("d",opts):
61         encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf)
62     elif re.search("5",opts):
63         encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf)
64     elif re.search("Y",opts):
65         encode_sar(pin,pout,size,is24fps,quality,crf)
66     elif re.search("Z",opts):
67         encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf)
68     elif re.search("b",opts):
69         try:
70             tm2v=pin.replace(".ts",".m2v")
71             encode(tm2v, pout,size,is24fps,quality,crf)
72         except Exception, inst:
73             recdblist.Commonlogex("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst))
74     else:
75         try:
76             encode(pin, pout,size,is24fps,quality,crf)
77         except Exception, inst:
78             recdblist.Commonlogex("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst))
79 def encode(pin,pout,size,is24fps,quality,crf):
80     mencoder=configreader.getpath("mencoder")
81     x264=configreader.getpath("x264")
82     encvf=""
83     txt=""
84     encvf="-vf yadif=0,pp=l5"
85     harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
86     ofps="-ofps 30000/1001"
87     fps="-fps 30000/1001"
88     x264fps="--fps 30000/1001"
89     x264streamsize=""
90     x264preset=""
91     x264tune=""
92     x264_bitrate="5000"
93     x264_thread="auto"
94     try:
95         xtt=configreader.getenv("x264_thread")
96         xtt=int(xtt)
97         if xtt>0:
98             x264_thread=str(xtt)
99     except:
100         x264_thread="auto"
101     x264_addline=configreader.getenv("x264_addline")
102     if is24fps==1:
103         ofps="-ofps 24000/1001"
104         fps="-fps 30000/1001"
105         x264fps="--fps 24000/1001"
106         x264tune="--tune animation"
107         encvf="-vf pullup,softskip"
108         harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
109     if size == "HD":
110         encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
111         x264streamsize=u"1280x720"
112         x264_bitrate="2500"
113     elif size == "WVGA":
114         encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup
115         x264streamsize=u"854x480"
116         x264_bitrate="1500"
117     elif size == "FullHD":
118         encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup
119         x264streamsize=u"1920x1080"
120         x264_bitrate="5000"
121     elif size == "SD":
122         encvf = encvf + ",scale=720:-2::0:3,expand=720:480"+harddup
123         x264streamsize=u"720x480"
124         x264_bitrate="1250"
125     elif size == "QVGA_BASE":
126         encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup
127         x264streamsize=u"320x240"
128         x264_bitrate="300"
129     elif size == "WVGA_BASE":
130         encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup
131         x264streamsize=u"854x480"
132         x264_bitrate="1500"
133     else:
134         encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
135         x264streamsize=u"1280x720"
136         x264_bitrate="2500"
137     if quality==1:
138         x264preset=u"--preset ultrafast"
139     elif quality==2:
140         x264preset=u"--preset veryfast"
141     elif quality==3:
142         x264preset=u"--preset fast"
143     elif quality==4:
144         x264preset=u"--preset medium"
145     elif quality==5:
146         x264preset=u"--preset slow"
147     elif quality==6:
148         x264preset=u"--preset slower"
149     if size == "WVGA_BASE" or size == "QVGA_BASE":
150         x264profile=" --level 32 --profile baseline "
151     else:
152         x264profile=" --level 41 --profile high "
153     x264crf=u"--crf "+str(crf)
154     os.environ['LANG']="ja_JP.UTF-8"
155     random.seed(pin)
156     random.jumpahead(10)
157     streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 999999)))
158     os.system(u"mkfifo "+streampath)
159     encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet -sws 9 "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" &"
160     encexe=encexe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u"  --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
161     encexe=u"nice -n 19 " +encexe
162     recdblist.printutf8(encexe)
163     txt=""
164     try:
165         txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8')
166     except:
167         ""
168     os.system("rm "+streampath)
169     recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)
170 def encode_sar(pin,pout,size,is24fps,quality,crf):
171     mencoder=configreader.getpath("mencoder")
172     x264=configreader.getpath("x264")
173     encvf=""
174     txt=""
175     encvf="-vf yadif=0,pp=l5"
176     harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
177     ofps="-ofps 30000/1001"
178     fps="-fps 30000/1001"
179     x264fps="--fps 30000/1001"
180     x264streamsize=""
181     x264preset=""
182     x264tune=""
183     x264_bitrate="5000"
184     x264_thread="auto"
185     tsar=getMoviePAR(pin)
186     x264_sar="--sar "+str(tsar[0])+":"+str(tsar[1])
187     try:
188         xtt=configreader.getenv("x264_thread")
189         xtt=int(xtt)
190         if xtt>0:
191             x264_thread=str(xtt)
192     except:
193         x264_thread="auto"
194     x264_addline=configreader.getenv("x264_addline")
195     if is24fps==1:
196         ofps="-ofps 24000/1001"
197         fps="-fps 30000/1001"
198         x264fps="--fps 24000/1001"
199         x264tune="--tune animation"
200         encvf="-vf pullup,softskip"
201         harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
202     if size == "HD":
203         tsize=get_par_size(pin,720)
204         encvf = encvf + ",scale=-3:720::0:3"+harddup
205         x264streamsize=str(tsize[0])+u"x720"
206         x264_bitrate="2500"
207     elif size == "WVGA":
208         tsize=get_par_size(pin,480)
209         encvf = encvf + ",scale=-3:480::0:3"+harddup
210         x264streamsize=str(tsize[0])+u"x480"
211         x264_bitrate="1500"
212     elif size == "FullHD":
213         tsize=get_par_size(pin,1080)
214         encvf = encvf + ",scale=-3:1080::0:3"+harddup
215         x264streamsize=str(tsize[0])+u"x1080"
216         x264_bitrate="5000"
217     elif size == "QVGA_BASE":
218         tsize=get_par_size(pin,240)
219         encvf = encvf + ",scale=-3:240::0:3"+harddup
220         x264streamsize=str(tsize[0])+u"x240"
221         x264_bitrate="300"
222     elif size == "WVGA_BASE":
223         tsize=get_par_size(pin,480)
224         encvf = encvf + ",scale=-3:480::0:3"+harddup
225         x264streamsize=str(tsize[0])+u"x480"
226         x264_bitrate="1500"
227     else:
228         tsize=get_par_size(pin,720)
229         encvf = encvf + ",scale=-3:720::0:3"+harddup
230         x264streamsize=str(tsize[0])+u"x720"
231         x264_bitrate="2500"
232     if quality==1:
233         x264preset=u"--preset ultrafast"
234     elif quality==2:
235         x264preset=u"--preset veryfast"
236     elif quality==3:
237         x264preset=u"--preset fast"
238     elif quality==4:
239         x264preset=u"--preset medium"
240     elif quality==5:
241         x264preset=u"--preset slow"
242     elif quality==6:
243         x264preset=u"--preset slower"
244     if size == "WVGA_BASE" or size == "QVGA_BASE":
245         x264profile=" --level 32 --profile baseline "
246     else:
247         x264profile=" --level 41 --profile high "
248     x264crf=u"--crf "+str(crf)
249     os.environ['LANG']="ja_JP.UTF-8"
250     random.seed(pin)
251     random.jumpahead(10)
252     streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 999999)))
253     os.system(u"mkfifo "+streampath)
254     encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet -sws 9 "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" &"
255     encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u"  --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
256     encexe=u"nice -n 19 " +encexe
257     recdblist.printutf8(encexe)
258     txt=""
259     try:
260         txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8')
261     except:
262         ""
263     os.system("rm "+streampath)
264     recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)
265
266 def encode_ffmpeg(pin,pout,size,is24fps,quality,crf):
267     """
268     
269     """
270     ffmpeg=configreader.getpath("ffmpeg")
271     x264=configreader.getpath("x264")
272     fps=u"-r 29.970030 "
273     x264fps="--fps 30000/1001"
274     x264streamsize=""
275     x264preset=""
276     x264tune=""
277     x264_bitrate="2500"
278     x264_thread="auto"
279     try:
280         xtt=configreader.getenv("x264_thread")
281         xtt=int(xtt)
282         if xtt>0:
283             x264_thread=str(xtt)
284     except:
285         x264_thread="auto"
286     x264_addline=configreader.getenv("x264_addline")
287     if size == "HD":
288         s = "-s 1280x720 "
289         x264streamsize=u"1280x720"
290         x264_bitrate="2500"
291     elif size == "WVGA":
292         s = "-s 854x480 "
293         x264streamsize=u"854x480"
294         x264_bitrate="1500"
295     elif size == "FullHD":
296         s = "-s 1920x1080 "
297         x264streamsize=u"1920x1080"
298         x264_bitrate="5000"
299     elif size == "SD":
300         s = "-s 720x480 "
301         x264streamsize=u"720x480"
302         x264_bitrate="1250"
303     elif size == "QVGA_BASE":
304         s = "-s 320x240 "
305         x264streamsize=u"320x240"
306         x264_bitrate="300"
307     elif size == "WVGA_BASE":
308         s = "-s 854x480 "
309         x264streamsize=u"854x480"
310         x264_bitrate="1500"
311     else:
312         s = "-s 1280x720 "
313         x264streamsize=u"1280x720"
314         x264_bitrate="2500"
315     if quality==1:
316         x264preset=u"--preset ultrafast"
317     elif quality==2:
318         x264preset=u"--preset veryfast"
319     elif quality==3:
320         x264preset=u"--preset fast"
321     elif quality==4:
322         x264preset=u"--preset medium"
323     elif quality==5:
324         x264preset=u"--preset slow"
325     elif quality==6:
326         x264preset=u"--preset slower"
327     if size == "WVGA_BASE" or size == "QVGA_BASE":
328         x264profile=" --level 32 --profile baseline "
329     else:
330         x264profile=" --level 41 --profile high "
331     x264crf=u"--crf "+str(crf)
332     txt=""
333     os.environ['LANG']="ja_JP.UTF-8"
334     exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
335     exe=exe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" - "+x264streamsize
336     exe = "nice -n 19 " + exe
337     txt=""
338     recdblist.printutf8(exe)
339     try:
340         txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
341     except:
342         ""
343     recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
344 def encode_ffmpeg_sar(pin,pout,size,is24fps,quality,crf):
345     """
346
347     """
348     ffmpeg=configreader.getpath("ffmpeg")
349     x264=configreader.getpath("x264")
350     fps=u"-r 29.970030 "
351     x264fps="--fps 30000/1001"
352     x264streamsize=""
353     x264preset=""
354     x264tune=""
355     x264_bitrate="2500"
356     x264_thread="auto"
357     tsar=getMoviePAR(pin)
358     x264_sar="--sar "+str(tsar[0])+":"+str(tsar[1])
359     try:
360         xtt=configreader.getenv("x264_thread")
361         xtt=int(xtt)
362         if xtt>0:
363             x264_thread=str(xtt)
364     except:
365         x264_thread="auto"
366     x264_addline=configreader.getenv("x264_addline")
367     if size == "HD":
368         tsize=get_par_size(pin,720)
369         s = "-s "+str(tsize[0])+"x720 "
370         x264streamsize=str(tsize[0])+u"x720"
371         x264_bitrate="2500"
372     elif size == "WVGA":
373         tsize=get_par_size(pin,480)
374         s = "-s "+str(tsize[0])+"x480 "
375         x264streamsize=str(tsize[0])+u"x480"
376         x264_bitrate="1500"
377     elif size == "FullHD":
378         tsize=get_par_size(pin,1080)
379         s = "-s "+str(tsize[0])+"x1080 "
380         x264streamsize=str(tsize[0])+u"x1080"
381         x264_bitrate="5000"
382     elif size == "SD":
383         tsize=get_par_size(pin,480)
384         s = "-s "+str(tsize[0])+"x480 "
385         x264streamsize=str(tsize[0])+u"x480"
386         x264_bitrate="1250"
387     elif size == "QVGA_BASE":
388         tsize=get_par_size(pin,240)
389         s = "-s "+str(tsize[0])+"x240 "
390         x264streamsize=str(tsize[0])+u"x240"
391         x264_bitrate="300"
392     elif size == "WVGA_BASE":
393         tsize=get_par_size(pin,480)
394         s = "-s "+str(tsize[0])+"x480 "
395         x264streamsize=str(tsize[0])+u"x480"
396         x264_bitrate="1500"
397     else:
398         tsize=get_par_size(pin,720)
399         s = "-s "+str(tsize[0])+"x720 "
400         x264streamsize=str(tsize[0])+u"x720"
401         x264_bitrate="2500"
402     if quality==1:
403         x264preset=u"--preset ultrafast"
404     elif quality==2:
405         x264preset=u"--preset veryfast"
406     elif quality==3:
407         x264preset=u"--preset fast"
408     elif quality==4:
409         x264preset=u"--preset medium"
410     elif quality==5:
411         x264preset=u"--preset slow"
412     elif quality==6:
413         x264preset=u"--preset slower"
414     if size == "WVGA_BASE" or size == "QVGA_BASE":
415         x264profile=" --level 32 --profile baseline "
416     else:
417         x264profile=" --level 41 --profile high "
418     x264crf=u"--crf "+str(crf)
419     txt=""
420     os.environ['LANG']="ja_JP.UTF-8"
421     exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
422     exe=exe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" - "+x264streamsize
423     exe = "nice -n 19 " + exe
424     txt=""
425     recdblist.printutf8(exe)
426     try:
427         txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
428     except:
429         ""
430     recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
431 def encode_ffmpeg_kai(pin,pout,size,is24fps,quality,crf):
432     """
433
434     """
435     ffmpeg=configreader.getpath("ffmpeg")
436     x264=configreader.getpath("x264")
437     fps=u"-r 29.970030 "
438     x264fps="--fps 30000/1001"
439     x264streamsize=""
440     x264preset=""
441     x264tune=""
442     x264_bitrate="2500"
443     x264_thread="auto"
444     try:
445         xtt=configreader.getenv("x264_thread")
446         xtt=int(xtt)
447         if xtt>0:
448             x264_thread=str(xtt)
449     except:
450         x264_thread="auto"
451     x264_addline=configreader.getenv("x264_addline")
452     if size == "HD":
453         padx=get16_9ffmpeg_s(pin,1280,720)
454         s = "-s "+str(1280-2*padx)+"x720 "
455         if padx>0:
456             s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
457         x264streamsize=u"1280x720"
458         x264_bitrate="2500"
459     elif size == "WVGA":
460         padx=get16_9ffmpeg_s(pin,854,480)
461         s = "-s "+str(854-2*padx)+"x480 "
462         if padx>0:
463             s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
464         x264streamsize=u"854x480"
465         x264_bitrate="1500"
466     elif size == "FullHD":
467         padx=get16_9ffmpeg_s(pin,1920,1080)
468         s = "-s "+str(1920-2*padx)+"x1080 "
469         if padx>0:
470             s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
471         x264streamsize=u"1920x1080"
472         x264_bitrate="5000"
473     elif size == "SD":
474         s = "-s 720x480 "
475         x264streamsize=u"720x480"
476         x264_bitrate="1250"
477     elif size == "QVGA_BASE":
478         s = "-s 320x240 "
479         x264streamsize=u"320x240"
480         x264_bitrate="300"
481     elif size == "WVGA_BASE":
482         s = "-s 854x480 "
483         x264streamsize=u"854x480"
484         x264_bitrate="1500"
485     else:
486         padx=get16_9ffmpeg_s(pin,1280,720)
487         s = "-s "+str(1280-2*padx)+"x720 "
488         if padx>0:
489             s=s+"-padleft "+str(padx)+" -padright "+str(padx)+" "
490         x264streamsize=u"1280x720"
491         x264_bitrate="2500"
492     if quality==1:
493         x264preset=u"--preset ultrafast"
494     elif quality==2:
495         x264preset=u"--preset veryfast"
496     elif quality==3:
497         x264preset=u"--preset fast"
498     elif quality==4:
499         x264preset=u"--preset medium"
500     elif quality==5:
501         x264preset=u"--preset slow"
502     elif quality==6:
503         x264preset=u"--preset slower"
504     if size == "WVGA_BASE" or size == "QVGA_BASE":
505         x264profile=" --level 32 --profile baseline "
506     else:
507         x264profile=" --level 41 --profile high "
508     x264crf=u"--crf "+str(crf)
509     txt=""
510     os.environ['LANG']="ja_JP.UTF-8"
511     exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
512     exe=exe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" - "+x264streamsize
513     exe = "nice -n 19 " + exe
514     txt=""
515     recdblist.printutf8(exe)
516     try:
517         txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
518     except:
519         ""
520     recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
521 def getMovieSize(pin):
522     ffmpeg=configreader.getpath("ffmpeg")
523     os.environ['LANG']="ja_JP.UTF-8"
524     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
525     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
526     rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
527     sizeMaxX=0
528     sizeMaxY=0
529     txtls=txts.split("\n")
530     for t in txtls:
531         rM=rT.match(t)
532         if rM:
533             sizetxt=rM.group(1)
534             partxt=rM.group(2)
535             tX=int(sizetxt.split("x")[0])
536             tY=int(sizetxt.split("x")[1])
537             tEX=int(partxt.split(":")[0])
538             tEY=int(partxt.split(":")[1])
539             tX2=tX*tEX*10/tEY
540             if tX2>10*int(tX2/10):
541                 tX2=tX2/10+1
542             else:
543                 tX2=tX2/10
544             if sizeMaxX<tX2:
545                 sizeMaxX=tX2
546                 sizeMaxY=tY
547     return [sizeMaxX,sizeMaxY]
548 def getMovieBaseSize(pin):
549     ffmpeg=configreader.getpath("ffmpeg")
550     os.environ['LANG']="ja_JP.UTF-8"
551     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
552     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
553     rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
554     sizeMaxX=0
555     sizeMaxY=0
556     txtls=txts.split("\n")
557     for t in txtls:
558         rM=rT.match(t)
559         if rM:
560             sizetxt=rM.group(1)
561             partxt=rM.group(2)
562             tX=int(sizetxt.split("x")[0])
563             tY=int(sizetxt.split("x")[1])
564             tEX=int(partxt.split(":")[0])
565             tEY=int(partxt.split(":")[1])
566             if sizeMaxX<tX:
567                 sizeMaxX=tX
568                 sizeMaxY=tY
569     return [sizeMaxX,sizeMaxY]
570 def getMoviePAR(pin):
571     ffmpeg=configreader.getpath("ffmpeg")
572     os.environ['LANG']="ja_JP.UTF-8"
573     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
574     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
575     rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
576     #rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
577     sizeMaxX=0
578     parx=0
579     pary=0
580     txtls=txts.split("\n")
581     for t in txtls:
582         rM=rT.match(t)
583         if rM:
584             sizetxt=rM.group(1)
585             dartxt=rM.group(2)
586             tX=int(sizetxt.split("x")[0])
587             tY=int(sizetxt.split("x")[1])
588             tEX=int(dartxt.split(":")[0])
589             tEY=int(dartxt.split(":")[1])
590             if sizeMaxX<tX:
591                 sizeMaxX=tX
592                 parx=tEX
593                 pary=tEY
594     return [parx,pary]
595 def getMovieDAR(pin):
596     ffmpeg=configreader.getpath("ffmpeg")
597     os.environ['LANG']="ja_JP.UTF-8"
598     exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
599     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
600     rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
601     sizeMaxX=0
602     darx=0
603     dary=0
604     txtls=txts.split("\n")
605     for t in txtls:
606         rM=rT.match(t)
607         if rM:
608             sizetxt=rM.group(1)
609             dartxt=rM.group(2)
610             tX=int(sizetxt.split("x")[0])
611             tY=int(sizetxt.split("x")[1])
612             tEX=int(dartxt.split(":")[0])
613             tEY=int(dartxt.split(":")[1])
614             if sizeMaxX<tX:
615                 sizeMaxX=tX
616                 darx=tEX
617                 dary=tEY
618     return [darx,dary]
619 def get16_9ffmpeg_s(pin,x,y):
620     try:
621         tDAR=getMovieDAR(pin)
622         if (tDAR[0]==16 and tDAR[1]==9):
623             return 0
624         elif tDAR==[0,0]:
625             return 0
626         else:
627             tSize=getMovieSize(pin)
628             tn=x-tSize[1]*x/tSize[0]
629             tn=tn/4
630             tn=tn*2#偶数にするための処理
631             return tn
632     except:
633         return 0
634 def get_par_size(pin,y):
635     tSize=getMovieBaseSize(pin)
636     print tSize
637     print y
638     tX=tSize[0]*10*y/tSize[1]
639     tY=y
640     print tX
641     if tX>int(tX/10)*10:
642         tX=tX/10+1
643     else:
644         tX=tX/10
645     print [tX,tY]
646     return [tX,tY]