summaryrefslogtreecommitdiffstats
path: root/abs/extra-testing/dpgconv/dpgconv-panscan.patch
blob: 471d51835f197bf75e5bca67f1e87056c866f0c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--- dpgconv-9.py.old	2009-10-28 19:33:46.000000000 +1030
+++ dpgconv-9.py	2009-10-28 19:28:01.000000000 +1030
@@ -49,9 +49,12 @@
 	--width xxx
 		destination video width (default: 256)
 	--keep-aspect
-		try to keep aspect ratio
+		try to keep aspect ratio by letterboxing
+        --keep-aspect-panscan
+		try to keep aspect ratio by cropping original
 	
 	NOTE:	width/height have no effect when --keep-aspect is set
+		--keep-aspect-panscan overrides --keep-aspect
 	
 	--mv
 		additional parameters for mencoder for video
@@ -150,8 +153,38 @@
 		v_pf = "format=rgb24,"
 		options.pf = 3
 
-	if options.aspect:
-		aspect = commands.getoutput( MPLAYER + " -frames 1 -vo null -ao null -identify \"" + file + "\" | grep -E \"^ID_VIDEO_ASPECT\"")
+	crop=""
+	if options.panscan:
+		options.width=256
+		options.height=192
+
+		aspect = commands.getoutput( MPLAYER + " -frames 1 -vo null -ao null -identify \"" + file + "\" | grep -E \"^ID_VIDEO_ASPECT\" | tail -1")
+		p1 = re.compile ("ID_VIDEO_ASPECT=(.*)")
+		m1 = p1.search( aspect )
+		width = commands.getoutput( MPLAYER + " -frames 1 -vo null -ao null -identify \"" + file + "\" | grep -E \"^ID_VIDEO_WIDTH\" | tail -1")
+		p2 = re.compile ("ID_VIDEO_WIDTH=(.*)")
+		m2 = p2.search( width )
+		height = commands.getoutput( MPLAYER + " -frames 1 -vo null -ao null -identify \"" + file + "\" | grep -E \"^ID_VIDEO_HEIGHT\" | tail -1")
+		p3 = re.compile ("ID_VIDEO_HEIGHT=(.*)")
+		m3 = p3.search( height )
+		if m1 and m2 and m3:
+			print "Input Aspect %s" % m1.group(1)
+			print "Input Width %s" % m2.group(1)
+			print "Input Height %s" % m3.group(1)
+			ar = float (m1.group(1))
+			iw = int (m2.group(1))
+			ih = int (m3.group(1))
+			if aspect > 1.333333:
+				cropw=int(round(iw / ar * 4 / 3, 0))
+				croph=ih
+			else:
+				cropw=iw
+				croph=int(round(ih * ar * 3 / 4, 0))
+			crop="crop="+`cropw`+":"+`croph`+","
+			print crop
+
+	elif options.aspect:
+		aspect = commands.getoutput( MPLAYER + " -frames 1 -vo null -ao null -identify \"" + file + "\" | grep -E \"^ID_VIDEO_ASPECT\" | tail -1")
 		p = re.compile ("ID_VIDEO_ASPECT=(.*)")
 		m = p.search( aspect )
 		if m:
@@ -169,13 +202,13 @@
 		if options.fps < 24:
 			print "mencoder won't work with double pass and fps < 24, forcing fps = 24"
 			options.fps = 24
-		v_cmd =  ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` +":::3,harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:vmax_b_frames=2:cmp=6:subcmp=6:precmp=6:dia=4:predia=4:bidir_refine=4:mv0_threshold=0:last_pred=3:vbitrate=" + `options.vbps` )
+		v_cmd =  ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + crop + "scale=" + `options.width` + ":" + `options.height` +":::3,harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:vmax_b_frames=2:cmp=6:subcmp=6:precmp=6:dia=4:predia=4:bidir_refine=4:mv0_threshold=0:last_pred=3:vbitrate=" + `options.vbps` )
 	elif options.hq:
-		v_cmd =  ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` +":::3,harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:cmp=6:subcmp=6:precmp=6:dia=3:predia=3:last_pred=3:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo" )
+		v_cmd =  ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + crop + "scale=" + `options.width` + ":" + `options.height` +":::3,harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:cmp=6:subcmp=6:precmp=6:dia=3:predia=3:last_pred=3:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo" )
 	elif options.lq:
-		v_cmd = ( " \"" + file + "\" -v -ofps " + `options.fps` + " -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` + ",harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo" )
+		v_cmd = ( " \"" + file + "\" -v -ofps " + `options.fps` + " -vf " + v_pf + crop + "scale=" + `options.width` + ":" + `options.height` + ",harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo" )
 	else :
-		v_cmd = ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + "scale=" + `options.width` + ":" + `options.height` + ":::3,harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:cmp=2:subcmp=2:precmp=2:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo")
+		v_cmd = ( " \""+ file +"\" -v -ofps " + `options.fps` + " -sws 9 -vf " + v_pf + crop + "scale=" + `options.width` + ":" + `options.height` + ":::3,harddup -nosound -ovc lavc -lavcopts vcodec=mpeg1video:vstrict=-2:mbd=2:trell:cbp:mv0:cmp=2:subcmp=2:precmp=2:vbitrate=" + `options.vbps` + " -o " + MPGTMP + " -of rawvideo")
 	
 	if options.nosub:
 		if options.sub != None:
@@ -459,6 +492,7 @@
 parser.add_option("-a","--abps", type="int", dest="abps", default=128)
 parser.add_option("--volnorm", action="store_true", dest="volnorm", default=False)
 parser.add_option("--keep-aspect", action="store_true", dest="aspect", default=False)
+parser.add_option("--keep-aspect-panscan", action="store_true", dest="panscan", default=False)
 parser.add_option("--height", type="int", dest="height", default=192)
 parser.add_option("--width", type="int", dest="width", default=256)
 parser.add_option("-z","--hz", type="int", dest="hz", default=32000)