Mercurial > mplayer.hg
annotate libmpcodecs/ve_xvid4.c @ 18648:7cc939d4a9e2
filter left & right edges too (yeah the code is lame i know...)
author | michael |
---|---|
date | Thu, 08 Jun 2006 12:30:53 +0000 |
parents | 20aca9baf5d8 |
children | a1807995e2ab |
rev | line source |
---|---|
11437 | 1 /***************************************************************************** |
2 * | |
13610 | 3 * - XviD 1.x export module for mplayer/mencoder - |
11437 | 4 * |
13610 | 5 * Copyright(C) 2003 Marco Belli <elcabesa@inwind.it> |
6 * 2003-2004 Edouard Gomez <ed.gomez@free.fr> | |
11437 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 ****************************************************************************/ | |
23 | |
24 /***************************************************************************** | |
25 * Includes | |
26 ****************************************************************************/ | |
27 | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 #include <string.h> | |
31 #include <errno.h> | |
32 #include <math.h> | |
33 #include <limits.h> | |
11920 | 34 #include <time.h> |
11437 | 35 |
17012 | 36 #include "config.h" |
37 #include "mp_msg.h" | |
11437 | 38 |
39 #ifdef HAVE_XVID4 | |
40 | |
41 #include "codec-cfg.h" | |
42 #include "stream.h" | |
43 #include "demuxer.h" | |
44 #include "stheader.h" | |
45 | |
46 #include "muxer.h" | |
47 | |
48 #include "img_format.h" | |
49 #include "mp_image.h" | |
50 #include "vf.h" | |
51 | |
52 #include <xvid.h> | |
53 #include <stdio.h> | |
54 #include <stdarg.h> | |
55 #include <limits.h> | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
56 #include <assert.h> |
11437 | 57 |
58 #include "m_option.h" | |
59 | |
60 #define FINE (!0) | |
61 #define BAD (!FINE) | |
62 | |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
63 #define MAX_ZONES 64 |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
64 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
65 // Profile flag definitions |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
66 #define PROFILE_ADAPTQUANT 0x00000001 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
67 #define PROFILE_BVOP 0x00000002 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
68 #define PROFILE_MPEGQUANT 0x00000004 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
69 #define PROFILE_INTERLACE 0x00000008 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
70 #define PROFILE_QPEL 0x00000010 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
71 #define PROFILE_GMC 0x00000020 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
72 #define PROFILE_4MV 0x00000040 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
73 #define PROFILE_DXN 0x00000080 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
74 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
75 // Reduce code duplication in profiles[] array |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
76 #define PROFILE_S (PROFILE_4MV) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
77 #define PROFILE_AS (PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_MPEGQUANT|PROFILE_INTERLACE|PROFILE_QPEL|PROFILE_GMC) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
78 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
79 typedef struct |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
80 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
81 char *name; ///< profile name |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
82 int id; ///< mpeg-4 profile id; iso/iec 14496-2:2001 table G-1 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
83 int width; ///< profile width restriction |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
84 int height; ///< profile height restriction |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
85 int fps; ///< profile frame rate restriction |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
86 int max_objects; ///< ?????? |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
87 int total_vmv_buffer_sz; ///< macroblock memory; when BVOPS=false, vmv = 2*vcv; when BVOPS=true, vmv = 3*vcv |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
88 int max_vmv_buffer_sz; ///< max macroblocks per vop |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
89 int vcv_decoder_rate; ///< macroblocks decoded per second |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
90 int max_acpred_mbs; ///< percentage |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
91 int max_vbv_size; ///< max vbv size (bits) 16368 bits |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
92 int max_video_packet_length; ///< bits |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
93 int max_bitrate; ///< bits per second |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
94 int vbv_peakrate; ///< max bits over anyone second period; 0=don't care |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
95 int dxn_max_bframes; ///< dxn: max consecutive bframes |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
96 unsigned int flags; ///< flags for allowed options/dxn note the definitions for PROFILE_S and PROFILE_AS |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
97 } profile_t; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
98 |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
99 // Code taken from Libavcodec and ve_lavc.c to handle Aspect Ratio calculation |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
100 |
13610 | 101 typedef struct xvid_rational_s{ |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
102 int num; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
103 int den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
104 } XVIDRational; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
105 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
106 #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
107 #define ABS(a) ((a) >= 0 ? (a) : (-(a))) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
108 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
109 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
110 static int64_t xvid_gcd(int64_t a, int64_t b){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
111 if(b) return xvid_gcd(b, a%b); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
112 else return a; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
113 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
114 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
115 static int xvid_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
116 int exact=1, sign=0; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
117 int64_t gcd; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
118 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
119 assert(den != 0); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
120 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
121 if(den < 0){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
122 den= -den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
123 nom= -nom; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
124 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
125 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
126 if(nom < 0){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
127 nom= -nom; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
128 sign= 1; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
129 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
130 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
131 gcd = xvid_gcd(nom, den); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
132 nom /= gcd; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
133 den /= gcd; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
134 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
135 if(nom > max || den > max){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
136 XVIDRational a0={0,1}, a1={1,0}; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
137 exact=0; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
138 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
139 for(;;){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
140 int64_t x= nom / den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
141 int64_t a2n= x*a1.num + a0.num; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
142 int64_t a2d= x*a1.den + a0.den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
143 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
144 if(a2n > max || a2d > max) break; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
145 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
146 nom %= den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
147 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
148 a0= a1; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
149 a1= (XVIDRational){a2n, a2d}; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
150 if(nom==0) break; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
151 x= nom; nom=den; den=x; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
152 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
153 nom= a1.num; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
154 den= a1.den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
155 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
156 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
157 assert(xvid_gcd(nom, den) == 1); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
158 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
159 if(sign) nom= -nom; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
160 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
161 *dst_nom = nom; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
162 *dst_den = den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
163 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
164 return exact; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
165 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
166 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
167 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
168 static XVIDRational xvid_d2q(double d, int max){ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
169 XVIDRational a; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
170 int exponent= MAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
171 int64_t den= 1LL << (61 - exponent); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
172 xvid_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
173 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
174 return a; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
175 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
176 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
177 // Code taken from XviD VfW source for profile support |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
178 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
179 /* default vbv_occupancy is (64/170)*vbv_buffer_size */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
180 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
181 const profile_t profiles[] = |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
182 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
183 /* name p@l w h fps obj Tvmv vmv vcv ac% vbv pkt bps vbv_peak dbf flags */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
184 /* unrestricted profile (default) */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
185 { "unrestricted", 0x00, 0, 0, 0, 0, 0, 0, 0, 100, 0*16368, -1, 0, 0, -1, 0xffffffff & ~PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
186 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
187 { "sp0", 0x08, 176, 144, 15, 1, 198, 99, 1485, 100, 10*16368, 2048, 64000, 0, -1, PROFILE_S }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
188 /* simple@l0: max f_code=1, intra_dc_vlc_threshold=0 */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
189 /* if ac preidition is used, adaptive quantization must not be used */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
190 /* <=qcif must be used */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
191 { "sp1", 0x01, 176, 144, 15, 4, 198, 99, 1485, 100, 10*16368, 2048, 64000, 0, -1, PROFILE_S|PROFILE_ADAPTQUANT }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
192 { "sp2", 0x02, 352, 288, 15, 4, 792, 396, 5940, 100, 40*16368, 4096, 128000, 0, -1, PROFILE_S|PROFILE_ADAPTQUANT }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
193 { "sp3", 0x03, 352, 288, 15, 4, 792, 396, 11880, 100, 40*16368, 8192, 384000, 0, -1, PROFILE_S|PROFILE_ADAPTQUANT }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
194 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
195 { "asp0", 0xf0, 176, 144, 30, 1, 297, 99, 2970, 100, 10*16368, 2048, 128000, 0, -1, PROFILE_AS }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
196 { "asp1", 0xf1, 176, 144, 30, 4, 297, 99, 2970, 100, 10*16368, 2048, 128000, 0, -1, PROFILE_AS }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
197 { "asp2", 0xf2, 352, 288, 15, 4, 1188, 396, 5940, 100, 40*16368, 4096, 384000, 0, -1, PROFILE_AS }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
198 { "asp3", 0xf3, 352, 288, 30, 4, 1188, 396, 11880, 100, 40*16368, 4096, 768000, 0, -1, PROFILE_AS }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
199 /* ISMA Profile 1, (ASP) @ L3b (CIF, 1.5 Mb/s) CIF(352x288), 30fps, 1.5Mbps max ??? */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
200 { "asp4", 0xf4, 352, 576, 30, 4, 2376, 792, 23760, 50, 80*16368, 8192, 3000000, 0, -1, PROFILE_AS }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
201 { "asp5", 0xf5, 720, 576, 30, 4, 4860, 1620, 48600, 25, 112*16368, 16384, 8000000, 0, -1, PROFILE_AS }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
202 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
203 // information provided by DivXNetworks, USA. |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
204 // "DivX Certified Profile Compatibility v1.1", February 2005 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
205 { "dxnhandheld", 0x00, 176, 144, 15, 1, 198, 99, 1485, 100, 32*8192, -1, 537600, 800000, 0, PROFILE_ADAPTQUANT|PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
206 { "dxnportntsc", 0x00, 352, 240, 30, 1, 990, 330, 36000, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
207 { "dxnportpal", 0x00, 352, 288, 25, 1, 1188, 396, 36000, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
208 { "dxnhtntsc", 0x00, 720, 480, 30, 1, 4050, 1350, 40500, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE|PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
209 { "dxnhtpal", 0x00, 720, 576, 25, 1, 4860, 1620, 40500, 100, 384*8192, -1, 4854000, 8000000, 1, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE|PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
210 { "dxnhdtv", 0x00, 1280, 720, 30, 1,10800, 3600, 108000, 100, 768*8192, -1, 9708400, 16000000, 2, PROFILE_4MV|PROFILE_ADAPTQUANT|PROFILE_BVOP|PROFILE_INTERLACE|PROFILE_DXN }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
211 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
212 { NULL, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000000 }, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
213 }; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
214 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
215 /** |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
216 * \brief return the pointer to a chosen profile |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
217 * \param str the profile name |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
218 * \return pointer of the appropriate profiles array entry or NULL for a mistyped profile name |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
219 */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
220 static profile_t *profileFromName(char *str) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
221 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
222 profile_t *cur = profiles; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
223 while (cur->name && strcasecmp(cur->name, str)) cur++; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
224 if(!cur->name) return NULL; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
225 return cur; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
226 } |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
227 |
11437 | 228 /***************************************************************************** |
229 * Configuration options | |
230 ****************************************************************************/ | |
231 | |
16602 | 232 extern char* passtmpfile; |
233 | |
11437 | 234 static int xvidenc_bitrate = 0; |
235 static int xvidenc_pass = 0; | |
236 static float xvidenc_quantizer = 0; | |
237 | |
238 static int xvidenc_packed = 0; | |
239 static int xvidenc_closed_gop = 1; | |
240 static int xvidenc_interlaced = 0; | |
241 static int xvidenc_quarterpel = 0; | |
242 static int xvidenc_gmc = 0; | |
15070
bde4030f9134
Better defaults encoding settings for XviD, intended to be a good tradeoff CPU/PSNR.
gpoirier
parents:
14878
diff
changeset
|
243 static int xvidenc_trellis = 1; |
11437 | 244 static int xvidenc_cartoon = 0; |
245 static int xvidenc_hqacpred = 1; | |
15070
bde4030f9134
Better defaults encoding settings for XviD, intended to be a good tradeoff CPU/PSNR.
gpoirier
parents:
14878
diff
changeset
|
246 static int xvidenc_chromame = 1; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
247 static int xvidenc_chroma_opt = 0; |
15070
bde4030f9134
Better defaults encoding settings for XviD, intended to be a good tradeoff CPU/PSNR.
gpoirier
parents:
14878
diff
changeset
|
248 static int xvidenc_vhq = 1; |
bde4030f9134
Better defaults encoding settings for XviD, intended to be a good tradeoff CPU/PSNR.
gpoirier
parents:
14878
diff
changeset
|
249 static int xvidenc_bvhq = 1; |
11437 | 250 static int xvidenc_motion = 6; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
251 static int xvidenc_turbo = 0; |
11437 | 252 static int xvidenc_stats = 0; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
253 static int xvidenc_max_key_interval = 0; /* Let xvidcore set a 10s interval by default */ |
11437 | 254 static int xvidenc_frame_drop_ratio = 0; |
255 static int xvidenc_greyscale = 0; | |
15638
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
256 static int xvidenc_luminance_masking = 0; |
11920 | 257 static int xvidenc_debug = 0; |
258 static int xvidenc_psnr = 0; | |
11437 | 259 |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
260 static int xvidenc_max_bframes = 2; |
17703 | 261 static int xvidenc_num_threads = 0; |
11437 | 262 static int xvidenc_bquant_ratio = 150; |
263 static int xvidenc_bquant_offset = 100; | |
264 static int xvidenc_bframe_threshold = 0; | |
265 | |
266 static int xvidenc_min_quant[3] = {2, 2, 2}; | |
267 static int xvidenc_max_quant[3] = {31, 31, 31}; | |
268 static char *xvidenc_intra_matrix_file = NULL; | |
269 static char *xvidenc_inter_matrix_file = NULL; | |
270 static char *xvidenc_quant_method = NULL; | |
271 | |
272 static int xvidenc_cbr_reaction_delay_factor = 0; | |
273 static int xvidenc_cbr_averaging_period = 0; | |
274 static int xvidenc_cbr_buffer = 0; | |
275 | |
276 static int xvidenc_vbr_keyframe_boost = 0; | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
277 static int xvidenc_vbr_overflow_control_strength = 5; |
11437 | 278 static int xvidenc_vbr_curve_compression_high = 0; |
279 static int xvidenc_vbr_curve_compression_low = 0; | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
280 static int xvidenc_vbr_max_overflow_improvement = 5; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
281 static int xvidenc_vbr_max_overflow_degradation = 5; |
11437 | 282 static int xvidenc_vbr_kfreduction = 0; |
11586 | 283 static int xvidenc_vbr_kfthreshold = 0; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
284 static int xvidenc_vbr_container_frame_overhead = 24; /* mencoder uses AVI container */ |
11437 | 285 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
286 // commandline profile option string - default to unrestricted |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
287 static char *xvidenc_profile = "unrestricted"; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
288 |
11437 | 289 static char *xvidenc_par = NULL; |
290 static int xvidenc_par_width = 0; | |
291 static int xvidenc_par_height = 0; | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
292 static float xvidenc_dar_aspect = 0.0f; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
293 static int xvidenc_autoaspect = 0; |
11437 | 294 |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
295 static char *xvidenc_zones = NULL; // zones string |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
296 |
11437 | 297 m_option_t xvidencopts_conf[] = |
298 { | |
299 /* Standard things mencoder should be able to treat directly */ | |
300 {"bitrate", &xvidenc_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL}, | |
301 {"pass", &xvidenc_pass, CONF_TYPE_INT, CONF_RANGE, 1, 2, NULL}, | |
302 {"fixed_quant", &xvidenc_quantizer, CONF_TYPE_FLOAT, CONF_RANGE, 1, 31, NULL}, | |
303 | |
304 /* Features */ | |
305 {"quant_type", &xvidenc_quant_method, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
306 {"me_quality", &xvidenc_motion, CONF_TYPE_INT, CONF_RANGE, 0, 6, NULL}, | |
307 {"chroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
308 {"nochroma_me", &xvidenc_chromame, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
309 {"chroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
310 {"nochroma_opt", &xvidenc_chroma_opt, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 311 {"vhq", &xvidenc_vhq, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL}, |
13610 | 312 {"bvhq", &xvidenc_bvhq, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL}, |
11437 | 313 {"max_bframes", &xvidenc_max_bframes, CONF_TYPE_INT, CONF_RANGE, 0, 20, NULL}, |
17703 | 314 {"threads", &xvidenc_num_threads, CONF_TYPE_INT, 0, 0, 0, NULL}, |
11437 | 315 {"bquant_ratio", &xvidenc_bquant_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL}, |
316 {"bquant_offset", &xvidenc_bquant_offset, CONF_TYPE_INT, CONF_RANGE, 0, 200, NULL}, | |
317 {"bf_threshold", &xvidenc_bframe_threshold, CONF_TYPE_INT, CONF_RANGE, -255, 255, NULL}, | |
318 {"qpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
319 {"noqpel", &xvidenc_quarterpel, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 320 {"gmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
321 {"nogmc", &xvidenc_gmc, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 322 {"trellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
323 {"notrellis", &xvidenc_trellis, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 324 {"packed", &xvidenc_packed, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
325 {"nopacked", &xvidenc_packed, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 326 {"closed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
327 {"noclosed_gop", &xvidenc_closed_gop, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11491 | 328 {"interlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
329 {"nointerlacing", &xvidenc_interlaced, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 330 {"cartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
331 {"nocartoon", &xvidenc_cartoon, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 332 {"hq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
333 {"nohq_ac", &xvidenc_hqacpred, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 334 {"frame_drop_ratio", &xvidenc_frame_drop_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, |
335 {"max_key_interval", &xvidenc_max_key_interval, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, | |
336 {"greyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 0, 1, NULL}, | |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
337 {"nogreyscale", &xvidenc_greyscale, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
15638
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
338 {"lumi_mask", &xvidenc_luminance_masking, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
339 {"nolumi_mask", &xvidenc_luminance_masking, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
340 {"turbo", &xvidenc_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
11920 | 341 {"debug", &xvidenc_debug, CONF_TYPE_INT , 0 ,0,-1,NULL}, |
11437 | 342 {"stats", &xvidenc_stats, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
11920 | 343 {"psnr", &xvidenc_psnr , CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
11437 | 344 |
345 | |
346 /* section [quantizer] */ | |
347 {"min_iquant", &xvidenc_min_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
348 {"max_iquant", &xvidenc_max_quant[0], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
349 {"min_pquant", &xvidenc_min_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
350 {"max_pquant", &xvidenc_max_quant[1], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
351 {"min_bquant", &xvidenc_min_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
352 {"max_bquant", &xvidenc_max_quant[2], CONF_TYPE_INT, CONF_RANGE, 1, 31, NULL}, | |
353 {"quant_intra_matrix", &xvidenc_intra_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL}, | |
354 {"quant_inter_matrix", &xvidenc_inter_matrix_file, CONF_TYPE_STRING, 0, 0, 100, NULL}, | |
355 | |
356 /* section [cbr] */ | |
11491 | 357 {"rc_reaction_delay_factor", &xvidenc_cbr_reaction_delay_factor, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, |
358 {"rc_averaging_period", &xvidenc_cbr_averaging_period, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, | |
359 {"rc_buffer", &xvidenc_cbr_buffer, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, | |
11437 | 360 |
361 /* section [vbr] */ | |
362 {"keyframe_boost", &xvidenc_vbr_keyframe_boost, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
363 {"curve_compression_high", &xvidenc_vbr_curve_compression_high, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
364 {"curve_compression_low", &xvidenc_vbr_curve_compression_low, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
365 {"overflow_control_strength", &xvidenc_vbr_overflow_control_strength, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
366 {"max_overflow_improvement", &xvidenc_vbr_max_overflow_improvement, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
367 {"max_overflow_degradation", &xvidenc_vbr_max_overflow_degradation, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
368 {"kfreduction", &xvidenc_vbr_kfreduction, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, | |
11586 | 369 {"kfthreshold", &xvidenc_vbr_kfthreshold, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, |
11437 | 370 {"container_frame_overhead", &xvidenc_vbr_container_frame_overhead, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL}, |
371 | |
372 /* Section Aspect Ratio */ | |
373 {"par", &xvidenc_par, CONF_TYPE_STRING, 0, 0, 0, NULL}, | |
374 {"par_width", &xvidenc_par_width, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL}, | |
375 {"par_height", &xvidenc_par_height, CONF_TYPE_INT, CONF_RANGE, 0, 255, NULL}, | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
376 {"aspect", &xvidenc_dar_aspect, CONF_TYPE_FLOAT, CONF_RANGE, 0.1, 9.99, NULL}, |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
377 {"autoaspect", &xvidenc_autoaspect, CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
13853
5a786c7e4df4
have each XviD's option flag have its (no)counterpart
gpoirier
parents:
13675
diff
changeset
|
378 {"noautoaspect", &xvidenc_autoaspect, CONF_TYPE_FLAG, 0, 1, 0, NULL}, |
11437 | 379 |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
380 /* Section Zones */ |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
381 {"zones", &xvidenc_zones, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
382 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
383 /* section profiles */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
384 {"profile", &xvidenc_profile, CONF_TYPE_STRING, 0, 0, 0, NULL}, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
385 |
11437 | 386 /* End of the config array */ |
387 {NULL, 0, 0, 0, 0, 0, NULL} | |
388 }; | |
389 | |
390 /***************************************************************************** | |
391 * Module private data | |
392 ****************************************************************************/ | |
393 | |
394 typedef struct _xvid_mplayer_module_t | |
395 { | |
396 /* Instance related global vars */ | |
397 void *instance; | |
398 xvid_gbl_init_t init; | |
399 xvid_enc_create_t create; | |
400 xvid_enc_frame_t frame; | |
401 xvid_plugin_single_t onepass; | |
402 xvid_plugin_2pass1_t pass1; | |
403 xvid_plugin_2pass2_t pass2; | |
404 | |
405 /* This data must survive local block scope, so here it is */ | |
406 xvid_enc_plugin_t plugins[7]; | |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
407 xvid_enc_zone_t zones[MAX_ZONES]; |
11437 | 408 |
409 /* MPEG4 stream buffer */ | |
410 muxer_stream_t *mux; | |
411 | |
412 /* Stats accumulators */ | |
413 int frames; | |
414 long long sse_y; | |
415 long long sse_u; | |
416 long long sse_v; | |
417 | |
418 /* Min & Max PSNR */ | |
419 int min_sse_y; | |
420 int min_sse_u; | |
421 int min_sse_v; | |
11920 | 422 int min_framenum; |
11437 | 423 int max_sse_y; |
424 int max_sse_u; | |
425 int max_sse_v; | |
11920 | 426 int max_framenum; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
427 |
11920 | 428 int pixels; |
13610 | 429 |
430 /* DAR/PAR and all that thingies */ | |
431 int d_width; | |
432 int d_height; | |
433 FILE *fvstats; | |
11437 | 434 } xvid_mplayer_module_t; |
435 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
436 static int dispatch_settings(xvid_mplayer_module_t *mod); |
11437 | 437 static int set_create_struct(xvid_mplayer_module_t *mod); |
438 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi); | |
13610 | 439 static void update_stats(xvid_mplayer_module_t *mod, xvid_enc_stats_t *stats); |
440 static void print_stats(xvid_mplayer_module_t *mod); | |
441 static void flush_internal_buffers(xvid_mplayer_module_t *mod); | |
442 static const char *par_string(int parcode); | |
11437 | 443 static const char *errorstring(int err); |
444 | |
445 /***************************************************************************** | |
446 * Video Filter API function definitions | |
447 ****************************************************************************/ | |
448 | |
449 /*============================================================================ | |
450 * config | |
451 *==========================================================================*/ | |
452 | |
453 static int | |
454 config(struct vf_instance_s* vf, | |
455 int width, int height, int d_width, int d_height, | |
456 unsigned int flags, unsigned int outfmt) | |
457 { | |
458 int err; | |
459 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; | |
460 | |
461 /* Complete the muxer initialization */ | |
462 mod->mux->bih->biWidth = width; | |
463 mod->mux->bih->biHeight = height; | |
464 mod->mux->bih->biSizeImage = | |
13610 | 465 mod->mux->bih->biWidth * mod->mux->bih->biHeight * 3 / 2; |
12061 | 466 mod->mux->aspect = (float)d_width/d_height; |
11437 | 467 |
468 /* Message the FourCC type */ | |
469 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
470 "videocodec: XviD (%dx%d fourcc=%x [%.4s])\n", | |
471 width, height, mod->mux->bih->biCompression, | |
472 (char *)&mod->mux->bih->biCompression); | |
473 | |
13610 | 474 /* Total number of pixels per frame required for PSNR */ |
475 mod->pixels = mod->mux->bih->biWidth*mod->mux->bih->biHeight; | |
476 | |
11437 | 477 /*-------------------------------------------------------------------- |
478 * Dispatch all module settings to XviD structures | |
479 *------------------------------------------------------------------*/ | |
480 | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
481 mod->d_width = d_width; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
482 mod->d_height = d_height; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
483 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
484 if(dispatch_settings(mod) == BAD) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
485 return(BAD); |
11437 | 486 |
487 /*-------------------------------------------------------------------- | |
488 * Set remaining information in the xvid_enc_create_t structure | |
489 *------------------------------------------------------------------*/ | |
490 | |
491 if(set_create_struct(mod) == BAD) | |
492 return(BAD); | |
493 | |
494 /*-------------------------------------------------------------------- | |
495 * Encoder instance creation | |
496 *------------------------------------------------------------------*/ | |
497 | |
498 err = xvid_encore(NULL, XVID_ENC_CREATE, &mod->create, NULL); | |
499 | |
500 if(err<0) { | |
501 mp_msg(MSGT_MENCODER, MSGL_ERR, | |
502 "xvid: xvidcore returned a '%s' error\n", errorstring(err)); | |
503 return(BAD); | |
504 } | |
505 | |
506 /* Store the encoder instance into the private data */ | |
507 mod->instance = mod->create.handle; | |
508 | |
17659 | 509 mod->mux->decoder_delay = mod->create.max_bframes ? 1 : 0; |
510 | |
11437 | 511 return(FINE); |
512 } | |
513 | |
514 /*============================================================================ | |
515 * uninit | |
516 *==========================================================================*/ | |
517 | |
518 static void | |
519 uninit(struct vf_instance_s* vf) | |
520 { | |
521 | |
522 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; | |
523 | |
524 /* Destroy xvid instance */ | |
525 xvid_encore(mod->instance, XVID_ENC_DESTROY, NULL, NULL); | |
526 | |
13610 | 527 /* Display stats (if any) */ |
528 print_stats(mod); | |
11437 | 529 |
13610 | 530 /* Close PSNR file if ever opened */ |
531 if (mod->fvstats) { | |
532 fclose(mod->fvstats); | |
533 mod->fvstats = NULL; | |
11437 | 534 } |
535 | |
13610 | 536 /* Free allocated memory */ |
537 if(mod->frame.quant_intra_matrix) | |
538 free(mod->frame.quant_intra_matrix); | |
539 | |
540 if(mod->frame.quant_inter_matrix) | |
541 free(mod->frame.quant_inter_matrix); | |
542 | |
543 if(mod->mux->bih) | |
544 free(mod->mux->bih); | |
545 | |
546 free(vf->priv); | |
547 vf->priv=NULL; | |
11437 | 548 |
549 return; | |
550 } | |
551 | |
552 /*============================================================================ | |
553 * control | |
554 *==========================================================================*/ | |
555 | |
556 static int | |
557 control(struct vf_instance_s* vf, int request, void* data) | |
558 { | |
13610 | 559 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; |
560 | |
561 switch(request){ | |
562 case VFCTRL_FLUSH_FRAMES: | |
563 if(mod)/*paranoid*/ | |
564 flush_internal_buffers(mod); | |
565 break; | |
566 } | |
11437 | 567 return(CONTROL_UNKNOWN); |
568 } | |
569 | |
570 /*============================================================================ | |
571 * query_format | |
572 *==========================================================================*/ | |
573 | |
574 static int | |
575 query_format(struct vf_instance_s* vf, unsigned int fmt) | |
576 { | |
577 switch(fmt){ | |
578 case IMGFMT_YV12: | |
579 case IMGFMT_IYUV: | |
580 case IMGFMT_I420: | |
581 return(VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW); | |
582 case IMGFMT_YUY2: | |
583 case IMGFMT_UYVY: | |
584 return(VFCAP_CSP_SUPPORTED); | |
585 } | |
586 return(BAD); | |
587 } | |
588 | |
589 /*============================================================================ | |
590 * put_image | |
591 *==========================================================================*/ | |
592 | |
593 static int | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17703
diff
changeset
|
594 put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts) |
11437 | 595 { |
596 int size; | |
597 xvid_enc_stats_t stats; | |
598 xvid_mplayer_module_t *mod = (xvid_mplayer_module_t *)vf->priv; | |
599 | |
600 /* Prepare the stats */ | |
601 memset(&stats,0,sizeof( xvid_enc_stats_t)); | |
602 stats.version = XVID_VERSION; | |
603 | |
604 /* ------------------------------------------------------------------- | |
605 * Set remaining information in the xvid_enc_frame_t structure | |
606 * NB: all the other struct members were initialized by | |
607 * dispatch_settings | |
608 * -----------------------------------------------------------------*/ | |
609 | |
610 if(set_frame_struct(mod, mpi) == BAD) | |
611 return(BAD); | |
612 | |
613 /* ------------------------------------------------------------------- | |
614 * Encode the frame | |
615 * ---------------------------------------------------------------- */ | |
616 | |
617 size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats); | |
618 | |
619 /* Analyse the returned value */ | |
620 if(size<0) { | |
621 mp_msg(MSGT_MENCODER, MSGL_ERR, | |
622 "xvid: xvidcore returned a '%s' error\n", errorstring(size)); | |
623 return(BAD); | |
624 } | |
625 | |
626 /* If size is == 0, we're done with that frame */ | |
17659 | 627 if(size == 0) { |
628 ++mod->mux->encoder_delay; | |
629 return(FINE); | |
630 } | |
11437 | 631 |
13610 | 632 /* xvidcore returns stats about encoded frame in an asynchronous way |
633 * accumulate these stats */ | |
634 update_stats(mod, &stats); | |
11437 | 635 |
636 /* xvidcore outputed bitstream -- mux it */ | |
637 muxer_write_chunk(mod->mux, | |
638 size, | |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17012
diff
changeset
|
639 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE); |
11437 | 640 |
641 return(FINE); | |
642 } | |
643 | |
644 /*============================================================================ | |
645 * vf_open | |
646 *==========================================================================*/ | |
647 | |
648 static int | |
649 vf_open(vf_instance_t *vf, char* args) | |
650 { | |
651 xvid_mplayer_module_t *mod; | |
652 xvid_gbl_init_t xvid_gbl_init; | |
653 xvid_gbl_info_t xvid_gbl_info; | |
654 | |
655 /* Setting libmpcodec module API pointers */ | |
656 vf->config = config; | |
14878 | 657 vf->default_caps = VFCAP_CONSTANT; |
11437 | 658 vf->control = control; |
659 vf->uninit = uninit; | |
660 vf->query_format = query_format; | |
661 vf->put_image = put_image; | |
662 | |
663 /* Allocate the private part of the codec module */ | |
664 vf->priv = malloc(sizeof(xvid_mplayer_module_t)); | |
665 mod = (xvid_mplayer_module_t*)vf->priv; | |
666 | |
667 if(mod == NULL) { | |
668 mp_msg(MSGT_MENCODER,MSGL_ERR, | |
669 "xvid: memory allocation failure (private data)\n"); | |
670 return(BAD); | |
671 } | |
672 | |
673 /* Initialize the module to zeros */ | |
674 memset(mod, 0, sizeof(xvid_mplayer_module_t)); | |
675 mod->min_sse_y = mod->min_sse_u = mod->min_sse_v = INT_MAX; | |
676 mod->max_sse_y = mod->max_sse_u = mod->max_sse_v = INT_MIN; | |
677 | |
678 /* Bind the Muxer */ | |
679 mod->mux = (muxer_stream_t*)args; | |
680 | |
681 /* Initialize muxer BITMAP header */ | |
14549
acf3241be19b
Initialized BITMAPINFOHEADER to 0 to avoid problems, esp. windows has problems
reimar
parents:
13853
diff
changeset
|
682 mod->mux->bih = calloc(1, sizeof(BITMAPINFOHEADER)); |
11437 | 683 |
684 if(mod->mux->bih == NULL) { | |
685 mp_msg(MSGT_MENCODER,MSGL_ERR, | |
686 "xvid: memory allocation failure (BITMAP header)\n"); | |
687 return(BAD); | |
688 } | |
689 | |
690 mod->mux->bih->biSize = sizeof(BITMAPINFOHEADER); | |
691 mod->mux->bih->biWidth = 0; | |
692 mod->mux->bih->biHeight = 0; | |
693 mod->mux->bih->biPlanes = 1; | |
13610 | 694 mod->mux->bih->biBitCount = 12; |
11437 | 695 mod->mux->bih->biCompression = mmioFOURCC('X','V','I','D'); |
696 | |
697 /* Retrieve information about the host XviD library */ | |
698 memset(&xvid_gbl_info, 0, sizeof(xvid_gbl_info_t)); | |
699 xvid_gbl_info.version = XVID_VERSION; | |
700 | |
701 if (xvid_global(NULL, XVID_GBL_INFO, &xvid_gbl_info, NULL) < 0) { | |
13610 | 702 mp_msg(MSGT_MENCODER,MSGL_WARN, "xvid: could not get information about the library\n"); |
11437 | 703 } else { |
704 mp_msg(MSGT_MENCODER,MSGL_INFO, "xvid: using library version %d.%d.%d (build %s)\n", | |
705 XVID_VERSION_MAJOR(xvid_gbl_info.actual_version), | |
706 XVID_VERSION_MINOR(xvid_gbl_info.actual_version), | |
707 XVID_VERSION_PATCH(xvid_gbl_info.actual_version), | |
708 xvid_gbl_info.build); | |
709 } | |
710 | |
711 /* Initialize the xvid_gbl_init structure */ | |
712 memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init_t)); | |
713 xvid_gbl_init.version = XVID_VERSION; | |
11920 | 714 xvid_gbl_init.debug = xvidenc_debug; |
11437 | 715 |
716 /* Initialize the xvidcore library */ | |
717 if (xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL) < 0) { | |
718 mp_msg(MSGT_MENCODER,MSGL_ERR, "xvid: initialisation failure\n"); | |
719 return(BAD); | |
720 } | |
721 | |
722 return(FINE); | |
723 } | |
724 | |
725 /***************************************************************************** | |
726 * Helper functions | |
727 ****************************************************************************/ | |
728 | |
729 static void *read_matrix(unsigned char *filename); | |
730 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
731 static int dispatch_settings(xvid_mplayer_module_t *mod) |
11437 | 732 { |
733 xvid_enc_create_t *create = &mod->create; | |
734 xvid_enc_frame_t *frame = &mod->frame; | |
735 xvid_plugin_single_t *onepass = &mod->onepass; | |
736 xvid_plugin_2pass2_t *pass2 = &mod->pass2; | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
737 XVIDRational ar; |
11437 | 738 |
739 const int motion_presets[7] = | |
740 { | |
741 0, | |
742 0, | |
743 0, | |
744 0, | |
745 XVID_ME_HALFPELREFINE16, | |
746 XVID_ME_HALFPELREFINE16 | XVID_ME_ADVANCEDDIAMOND16, | |
747 XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | | |
748 XVID_ME_HALFPELREFINE8 | XVID_ME_USESQUARES16 | |
749 }; | |
750 | |
16615 | 751 //profile is unrestricted as default |
752 profile_t *selected_profile = profileFromName("unrestricted"); | |
753 if(xvidenc_profile) | |
754 selected_profile = profileFromName(xvidenc_profile); | |
755 if(!selected_profile) | |
756 { | |
757 mp_msg(MSGT_MENCODER,MSGL_ERR, | |
758 "xvid:[ERROR] \"%s\" is an invalid profile name\n", xvidenc_profile); | |
759 return(BAD); | |
760 } | |
11437 | 761 |
762 /* ------------------------------------------------------------------- | |
763 * Dispatch all settings having an impact on the "create" structure | |
764 * This includes plugins as they are passed to encore through the | |
765 * create structure | |
766 * -----------------------------------------------------------------*/ | |
767 | |
768 /* ------------------------------------------------------------------- | |
769 * The create structure | |
770 * ---------------------------------------------------------------- */ | |
771 | |
772 create->global = 0; | |
773 | |
11920 | 774 if(xvidenc_psnr) |
775 xvidenc_stats = 1; | |
776 | |
11437 | 777 if(xvidenc_stats) |
778 create->global |= XVID_GLOBAL_EXTRASTATS_ENABLE; | |
779 | |
780 create->num_zones = 0; | |
781 create->zones = NULL; | |
782 create->num_plugins = 0; | |
783 create->plugins = NULL; | |
17703 | 784 create->num_threads = xvidenc_num_threads; |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
785 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
786 if( (selected_profile->flags & PROFILE_BVOP) && |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
787 /* dxn: prevent bframes usage if interlacing is selected */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
788 !((selected_profile->flags & PROFILE_DXN) && xvidenc_interlaced) ) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
789 { |
11437 | 790 create->max_bframes = xvidenc_max_bframes; |
791 create->bquant_ratio = xvidenc_bquant_ratio; | |
792 create->bquant_offset = xvidenc_bquant_offset; | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
793 if(xvidenc_packed) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
794 create->global |= XVID_GLOBAL_PACKED; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
795 if(xvidenc_closed_gop) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
796 create->global |= XVID_GLOBAL_CLOSED_GOP; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
797 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
798 /* dxn: restrict max bframes, require closed gop |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
799 and require packed b-frames */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
800 if(selected_profile->flags & PROFILE_DXN) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
801 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
802 if(create->max_bframes > selected_profile->dxn_max_bframes) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
803 create->max_bframes = selected_profile->dxn_max_bframes; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
804 create->global |= XVID_GLOBAL_CLOSED_GOP; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
805 create->global |= XVID_GLOBAL_PACKED; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
806 } |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
807 } |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
808 else |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
809 create->max_bframes = 0; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
810 |
16515
1218c5859ce8
10l: fully working DXN profile support require XviD 1.1.x. Earlier version will work but will lack VBV support
gpoirier
parents:
16481
diff
changeset
|
811 #if XVID_API >= XVID_MAKE_API(4,1) |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
812 /* dxn: always write divx5 userdata */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
813 if(selected_profile->flags & PROFILE_DXN) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
814 create->global |= XVID_GLOBAL_DIVX5_USERDATA; |
16515
1218c5859ce8
10l: fully working DXN profile support require XviD 1.1.x. Earlier version will work but will lack VBV support
gpoirier
parents:
16481
diff
changeset
|
815 #endif |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
816 |
11437 | 817 create->max_key_interval = xvidenc_max_key_interval; |
818 create->frame_drop_ratio = xvidenc_frame_drop_ratio; | |
819 create->min_quant[0] = xvidenc_min_quant[0]; | |
820 create->min_quant[1] = xvidenc_min_quant[1]; | |
821 create->min_quant[2] = xvidenc_min_quant[2]; | |
822 create->max_quant[0] = xvidenc_max_quant[0]; | |
823 create->max_quant[1] = xvidenc_max_quant[1]; | |
824 create->max_quant[2] = xvidenc_max_quant[2]; | |
825 | |
826 | |
827 /* ------------------------------------------------------------------- | |
828 * The single pass plugin | |
829 * ---------------------------------------------------------------- */ | |
830 | |
13675
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
831 if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate; |
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
832 else onepass->bitrate = xvidenc_bitrate*1000; |
11437 | 833 onepass->reaction_delay_factor = xvidenc_cbr_reaction_delay_factor; |
834 onepass->averaging_period = xvidenc_cbr_averaging_period; | |
835 onepass->buffer = xvidenc_cbr_buffer; | |
836 | |
837 /* ------------------------------------------------------------------- | |
838 * The pass2 plugin | |
839 * ---------------------------------------------------------------- */ | |
840 | |
841 pass2->keyframe_boost = xvidenc_vbr_keyframe_boost; | |
842 pass2->overflow_control_strength = xvidenc_vbr_overflow_control_strength; | |
843 pass2->curve_compression_high = xvidenc_vbr_curve_compression_high; | |
844 pass2->curve_compression_low = xvidenc_vbr_curve_compression_low; | |
845 pass2->max_overflow_improvement = xvidenc_vbr_max_overflow_improvement; | |
846 pass2->max_overflow_degradation = xvidenc_vbr_max_overflow_degradation; | |
847 pass2->kfreduction = xvidenc_vbr_kfreduction; | |
11586 | 848 pass2->kfthreshold = xvidenc_vbr_kfthreshold; |
11437 | 849 pass2->container_frame_overhead = xvidenc_vbr_container_frame_overhead; |
850 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
851 /* VBV */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
852 |
16515
1218c5859ce8
10l: fully working DXN profile support require XviD 1.1.x. Earlier version will work but will lack VBV support
gpoirier
parents:
16481
diff
changeset
|
853 #if XVID_API >= XVID_MAKE_API(4,1) |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
854 pass2->vbv_size = selected_profile->max_vbv_size; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
855 pass2->vbv_initial = (selected_profile->max_vbv_size*3)>>2; /* 75% */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
856 pass2->vbv_maxrate = selected_profile->max_bitrate; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
857 pass2->vbv_peakrate = selected_profile->vbv_peakrate*3; |
16515
1218c5859ce8
10l: fully working DXN profile support require XviD 1.1.x. Earlier version will work but will lack VBV support
gpoirier
parents:
16481
diff
changeset
|
858 #endif |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
859 // XXX: xvidcore currently provides a "peak bits over 3 seconds" constraint. |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
860 // according to the latest dxn literature, a 1 second constraint is now used |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
861 |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
862 create->profile = selected_profile->id; |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
863 |
11437 | 864 /* ------------------------------------------------------------------- |
865 * The frame structure | |
866 * ---------------------------------------------------------------- */ | |
867 frame->vol_flags = 0; | |
868 frame->vop_flags = 0; | |
869 frame->motion = 0; | |
870 | |
871 frame->vop_flags |= XVID_VOP_HALFPEL; | |
872 frame->motion |= motion_presets[xvidenc_motion]; | |
873 | |
874 if(xvidenc_stats) | |
875 frame->vol_flags |= XVID_VOL_EXTRASTATS; | |
876 | |
877 if(xvidenc_greyscale) | |
878 frame->vop_flags |= XVID_VOP_GREYSCALE; | |
879 | |
880 if(xvidenc_cartoon) { | |
881 frame->vop_flags |= XVID_VOP_CARTOON; | |
882 frame->motion |= XVID_ME_DETECT_STATIC_MOTION; | |
883 } | |
884 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
885 // MPEG quantisation is only supported in ASP and unrestricted profiles |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
886 if((selected_profile->flags & PROFILE_MPEGQUANT) && |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
887 (xvidenc_quant_method != NULL) && |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
888 !strcasecmp(xvidenc_quant_method, "mpeg")) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
889 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
890 frame->vol_flags |= XVID_VOL_MPEGQUANT; |
11437 | 891 if(xvidenc_intra_matrix_file != NULL) { |
892 frame->quant_intra_matrix = (unsigned char*)read_matrix(xvidenc_intra_matrix_file); | |
893 if(frame->quant_intra_matrix != NULL) { | |
13610 | 894 mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: Loaded Intra matrix (switching to mpeg quantization type)\n"); |
11437 | 895 if(xvidenc_quant_method) free(xvidenc_quant_method); |
896 xvidenc_quant_method = strdup("mpeg"); | |
897 } | |
898 } | |
899 if(xvidenc_inter_matrix_file != NULL) { | |
900 frame->quant_inter_matrix = read_matrix(xvidenc_inter_matrix_file); | |
901 if(frame->quant_inter_matrix) { | |
13610 | 902 mp_msg(MSGT_MENCODER, MSGL_INFO, "\nxvid: Loaded Inter matrix (switching to mpeg quantization type)\n"); |
11437 | 903 if(xvidenc_quant_method) free(xvidenc_quant_method); |
904 xvidenc_quant_method = strdup("mpeg"); | |
905 } | |
906 } | |
907 } | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
908 if(xvidenc_quarterpel && (selected_profile->flags & PROFILE_QPEL)) { |
11437 | 909 frame->vol_flags |= XVID_VOL_QUARTERPEL; |
910 frame->motion |= XVID_ME_QUARTERPELREFINE16; | |
911 frame->motion |= XVID_ME_QUARTERPELREFINE8; | |
912 } | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
913 if(xvidenc_gmc && (selected_profile->flags & PROFILE_GMC)) { |
11437 | 914 frame->vol_flags |= XVID_VOL_GMC; |
915 frame->motion |= XVID_ME_GME_REFINE; | |
916 } | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
917 if(xvidenc_interlaced && (selected_profile->flags & PROFILE_INTERLACE)) { |
11437 | 918 frame->vol_flags |= XVID_VOL_INTERLACING; |
919 } | |
920 if(xvidenc_trellis) { | |
921 frame->vop_flags |= XVID_VOP_TRELLISQUANT; | |
922 } | |
923 if(xvidenc_hqacpred) { | |
924 frame->vop_flags |= XVID_VOP_HQACPRED; | |
925 } | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
926 if(xvidenc_chroma_opt) { |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
927 frame->vop_flags |= XVID_VOP_CHROMAOPT; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
928 } |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
929 if((xvidenc_motion > 4) && (selected_profile->flags & PROFILE_4MV)) { |
11437 | 930 frame->vop_flags |= XVID_VOP_INTER4V; |
931 } | |
932 if(xvidenc_chromame) { | |
933 frame->motion |= XVID_ME_CHROMA_PVOP; | |
934 frame->motion |= XVID_ME_CHROMA_BVOP; | |
935 } | |
936 if(xvidenc_vhq >= 1) { | |
937 frame->vop_flags |= XVID_VOP_MODEDECISION_RD; | |
938 } | |
939 if(xvidenc_vhq >= 2) { | |
940 frame->motion |= XVID_ME_HALFPELREFINE16_RD; | |
941 frame->motion |= XVID_ME_QUARTERPELREFINE16_RD; | |
942 } | |
943 if(xvidenc_vhq >= 3) { | |
944 frame->motion |= XVID_ME_HALFPELREFINE8_RD; | |
945 frame->motion |= XVID_ME_QUARTERPELREFINE8_RD; | |
946 frame->motion |= XVID_ME_CHECKPREDICTION_RD; | |
947 } | |
948 if(xvidenc_vhq >= 4) { | |
949 frame->motion |= XVID_ME_EXTSEARCH_RD; | |
950 } | |
13610 | 951 if(xvidenc_bvhq >= 1) { |
952 #if XVID_API >= XVID_MAKE_API(4,1) | |
953 frame->vop_flags |= XVID_VOP_RD_BVOP; | |
954 #endif | |
955 } | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
956 if(xvidenc_turbo) { |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
957 frame->motion |= XVID_ME_FASTREFINE16; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
958 frame->motion |= XVID_ME_FASTREFINE8; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
959 frame->motion |= XVID_ME_SKIP_DELTASEARCH; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
960 frame->motion |= XVID_ME_FAST_MODEINTERPOLATE; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
961 frame->motion |= XVID_ME_BFRAME_EARLYSTOP; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
962 } |
11437 | 963 |
964 /* motion level == 0 means no motion search which is equivalent to | |
965 * intra coding only */ | |
966 if(xvidenc_motion == 0) { | |
967 frame->type = XVID_TYPE_IVOP; | |
968 } else { | |
969 frame->type = XVID_TYPE_AUTO; | |
970 } | |
971 | |
972 frame->bframe_threshold = xvidenc_bframe_threshold; | |
973 | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
974 /* PAR related initialization */ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
975 frame->par = XVID_PAR_11_VGA; /* Default */ |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
976 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
977 if( !(selected_profile->flags & PROFILE_DXN) ) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
978 { |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
979 if(xvidenc_dar_aspect > 0) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
980 ar = xvid_d2q(xvidenc_dar_aspect * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
981 else if(xvidenc_autoaspect) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
982 ar = xvid_d2q((float)mod->d_width / mod->d_height * mod->mux->bih->biHeight / mod->mux->bih->biWidth, 255); |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
983 else ar.num = ar.den = 0; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
984 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
985 if(ar.den != 0) { |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
986 if(ar.num == 12 && ar.den == 11) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
987 frame->par = XVID_PAR_43_PAL; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
988 else if(ar.num == 10 && ar.den == 11) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
989 frame->par = XVID_PAR_43_NTSC; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
990 else if(ar.num == 16 && ar.den == 11) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
991 frame->par = XVID_PAR_169_PAL; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
992 else if(ar.num == 40 && ar.den == 33) |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
993 frame->par = XVID_PAR_169_NTSC; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
994 else |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
995 { |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
996 frame->par = XVID_PAR_EXT; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
997 frame->par_width = ar.num; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
998 frame->par_height= ar.den; |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
999 } |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1000 |
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1001 } else if(xvidenc_par != NULL) { |
11437 | 1002 if(strcasecmp(xvidenc_par, "pal43") == 0) |
1003 frame->par = XVID_PAR_43_PAL; | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1004 else if(strcasecmp(xvidenc_par, "pal169") == 0) |
11437 | 1005 frame->par = XVID_PAR_169_PAL; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1006 else if(strcasecmp(xvidenc_par, "ntsc43") == 0) |
11437 | 1007 frame->par = XVID_PAR_43_NTSC; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1008 else if(strcasecmp(xvidenc_par, "ntsc169") == 0) |
11437 | 1009 frame->par = XVID_PAR_169_NTSC; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1010 else if(strcasecmp(xvidenc_par, "ext") == 0) |
11437 | 1011 frame->par = XVID_PAR_EXT; |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1012 |
11437 | 1013 if(frame->par == XVID_PAR_EXT) { |
1014 if(xvidenc_par_width) | |
1015 frame->par_width = xvidenc_par_width; | |
1016 else | |
1017 frame->par_width = 1; | |
1018 | |
1019 if(xvidenc_par_height) | |
1020 frame->par_height = xvidenc_par_height; | |
1021 else | |
1022 frame->par_height = 1; | |
1023 } | |
11912
8eb96d751dcd
new options - aspect,autoaspect,turbo,chroma_opt. patch by Nico <nsabbi@tiscali.it> and Edouard Gomez
iive
parents:
11586
diff
changeset
|
1024 } |
13610 | 1025 |
1026 /* Display par information */ | |
1027 mp_msg(MSGT_MENCODER, MSGL_INFO, "xvid: par=%d/%d (%s), displayed=%dx%d, sampled=%dx%d\n", | |
1028 ar.num, ar.den, par_string(frame->par), | |
1029 mod->d_width, mod->d_height, mod->mux->bih->biWidth, mod->mux->bih->biHeight); | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1030 } |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1031 else |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1032 mp_msg(MSGT_MENCODER, MSGL_INFO, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1033 "xvid: par=0/0 (vga11) forced by choosing a DXN profile\n"); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1034 return(FINE); |
11437 | 1035 } |
1036 | |
1037 static int set_create_struct(xvid_mplayer_module_t *mod) | |
1038 { | |
1039 int pass; | |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1040 int doZones = 0; |
11437 | 1041 xvid_enc_create_t *create = &mod->create; |
1042 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1043 // profile is unrestricted as default |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1044 profile_t *selected_profile = profileFromName("unrestricted"); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1045 if(xvidenc_profile) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1046 selected_profile = profileFromName(xvidenc_profile); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1047 if(!selected_profile) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1048 return(BAD); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1049 |
11437 | 1050 /* Most of the structure is initialized by dispatch settings, only a |
1051 * few things are missing */ | |
1052 create->version = XVID_VERSION; | |
1053 | |
1054 /* Width and Height */ | |
1055 create->width = mod->mux->bih->biWidth; | |
1056 create->height = mod->mux->bih->biHeight; | |
1057 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1058 /* Check resolution of video to be coded is within profile width/height |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1059 restrictions */ |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1060 if( ((selected_profile->width != 0) && |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1061 (mod->mux->bih->biWidth > selected_profile->width)) || |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1062 ((selected_profile->height != 0) && |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1063 (mod->mux->bih->biHeight > selected_profile->height)) ) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1064 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1065 mp_msg(MSGT_MENCODER,MSGL_ERR, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1066 "xvid:[ERROR] resolution must be <= %dx%d for the chosen profile\n", |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1067 selected_profile->width, selected_profile->height); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1068 return(BAD); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1069 } |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1070 |
11437 | 1071 /* FPS */ |
1072 create->fincr = mod->mux->h.dwScale; | |
1073 create->fbase = mod->mux->h.dwRate; | |
1074 | |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1075 // Check frame rate is within profile restrictions |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1076 if( ((float)mod->mux->h.dwRate/(float)mod->mux->h.dwScale > (float)selected_profile->fps) && |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1077 (selected_profile->fps != 0)) |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1078 { |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1079 mp_msg(MSGT_MENCODER,MSGL_ERR, |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1080 "xvid:[ERROR] frame rate must be <= %d for the chosen profile\n", |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1081 selected_profile->fps); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1082 return(BAD); |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1083 } |
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1084 |
11437 | 1085 /* Encodings zones */ |
1086 memset(mod->zones, 0, sizeof(mod->zones)); | |
1087 create->zones = mod->zones; | |
1088 create->num_zones = 0; | |
1089 | |
1090 /* Plugins */ | |
1091 memset(mod->plugins, 0, sizeof(mod->plugins)); | |
1092 create->plugins = mod->plugins; | |
1093 create->num_plugins = 0; | |
1094 | |
1095 /* ------------------------------------------------------------------- | |
1096 * Initialize and bind the right rate controller plugin | |
1097 * ---------------------------------------------------------------- */ | |
1098 | |
1099 /* First we try to sort out configuration conflicts */ | |
1100 if(xvidenc_quantizer != 0 && (xvidenc_bitrate || xvidenc_pass)) { | |
1101 mp_msg(MSGT_MENCODER, MSGL_ERR, | |
1102 "xvid: you can't mix Fixed Quantizer Rate Control" | |
1103 " with other Rate Control mechanisms\n"); | |
1104 return(BAD); | |
1105 } | |
1106 | |
1107 if(xvidenc_bitrate != 0 && xvidenc_pass == 1) { | |
13610 | 1108 mp_msg(MSGT_MENCODER, MSGL_WARN, |
11437 | 1109 "xvid: bitrate setting is ignored during first pass\n"); |
1110 } | |
1111 | |
1112 /* Sort out which sort of pass we are supposed to do | |
1113 * pass == 1<<0 CBR | |
1114 * pass == 1<<1 Two pass first pass | |
1115 * pass == 1<<2 Two pass second pass | |
1116 * pass == 1<<3 Constant quantizer | |
1117 */ | |
1118 #define MODE_CBR (1<<0) | |
1119 #define MODE_2PASS1 (1<<1) | |
1120 #define MODE_2PASS2 (1<<2) | |
1121 #define MODE_QUANT (1<<3) | |
1122 | |
1123 pass = 0; | |
1124 | |
1125 if(xvidenc_bitrate != 0 && xvidenc_pass == 0) | |
1126 pass |= MODE_CBR; | |
1127 | |
1128 if(xvidenc_pass == 1) | |
1129 pass |= MODE_2PASS1; | |
1130 | |
1131 if(xvidenc_bitrate != 0 && xvidenc_pass == 2) | |
1132 pass |= MODE_2PASS2; | |
1133 | |
1134 if(xvidenc_quantizer != 0 && xvidenc_pass == 0) | |
1135 pass |= MODE_QUANT; | |
1136 | |
1137 /* We must be in at least one RC mode */ | |
1138 if(pass == 0) { | |
1139 mp_msg(MSGT_MENCODER, MSGL_ERR, | |
1140 "xvid: you must specify one or a valid combination of " | |
1141 "'bitrate', 'pass', 'quantizer' settings\n"); | |
1142 return(BAD); | |
1143 } | |
1144 | |
1145 /* Sanity checking */ | |
1146 if(pass != MODE_CBR && pass != MODE_QUANT && | |
1147 pass != MODE_2PASS1 && pass != MODE_2PASS2) { | |
1148 mp_msg(MSGT_MENCODER, MSGL_ERR, | |
1149 "xvid: this code should not be reached - fill a bug " | |
1150 "report\n"); | |
1151 return(BAD); | |
1152 } | |
1153 | |
1154 /* This is a single pass encoding: either a CBR pass or a constant | |
1155 * quantizer pass */ | |
1156 if(pass == MODE_CBR || pass == MODE_QUANT) { | |
1157 xvid_plugin_single_t *onepass = &mod->onepass; | |
1158 | |
1159 /* There is not much left to initialize after dispatch settings */ | |
1160 onepass->version = XVID_VERSION; | |
13675
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
1161 if (xvidenc_bitrate > 16000) onepass->bitrate = xvidenc_bitrate; |
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
1162 else onepass->bitrate = xvidenc_bitrate*1000; |
11437 | 1163 |
1164 /* Quantizer mode uses the same plugin, we have only to define | |
1165 * a constant quantizer zone beginning at frame 0 */ | |
1166 if(pass == MODE_QUANT) { | |
11929 | 1167 XVIDRational squant; |
1168 squant = xvid_d2q(xvidenc_quantizer,128); | |
11437 | 1169 |
1170 create->zones[create->num_zones].mode = XVID_ZONE_QUANT; | |
1171 create->zones[create->num_zones].frame = 0; | |
12806 | 1172 create->zones[create->num_zones].increment = squant.num; |
1173 create->zones[create->num_zones].base = squant.den; | |
11437 | 1174 create->num_zones++; |
1175 | |
1176 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1177 "xvid: Fixed Quant Rate Control -- quantizer=%d/%d=%2.2f\n", | |
11929 | 1178 squant.num, |
1179 squant.den, | |
1180 (float)(squant.num)/(float)(squant.den)); | |
11437 | 1181 |
1182 } else { | |
1183 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1184 "xvid: CBR Rate Control -- bitrate=%dkbit/s\n", | |
13675
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
1185 xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate); |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1186 doZones = 1; |
11437 | 1187 } |
1188 | |
1189 create->plugins[create->num_plugins].func = xvid_plugin_single; | |
1190 create->plugins[create->num_plugins].param = onepass; | |
1191 create->num_plugins++; | |
1192 } | |
1193 | |
1194 /* This is the first pass of a Two pass process */ | |
1195 if(pass == MODE_2PASS1) { | |
1196 xvid_plugin_2pass1_t *pass1 = &mod->pass1; | |
1197 | |
1198 /* There is not much to initialize for this plugin */ | |
1199 pass1->version = XVID_VERSION; | |
16602 | 1200 pass1->filename = passtmpfile; |
11437 | 1201 |
1202 create->plugins[create->num_plugins].func = xvid_plugin_2pass1; | |
1203 create->plugins[create->num_plugins].param = pass1; | |
1204 create->num_plugins++; | |
1205 | |
1206 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1207 "xvid: 2Pass Rate Control -- 1st pass\n"); | |
1208 } | |
1209 | |
1210 /* This is the second pass of a Two pass process */ | |
1211 if(pass == MODE_2PASS2) { | |
1212 xvid_plugin_2pass2_t *pass2 = &mod->pass2; | |
1213 | |
1214 /* There is not much left to initialize after dispatch settings */ | |
1215 pass2->version = XVID_VERSION; | |
16602 | 1216 pass2->filename = passtmpfile; |
11437 | 1217 |
1218 /* Positive bitrate values are bitrates as usual but if the | |
1219 * value is negative it is considered as being a total size | |
1220 * to reach (in kilobytes) */ | |
1221 if(xvidenc_bitrate > 0) { | |
13675
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
1222 if(xvidenc_bitrate > 16000) pass2->bitrate = xvidenc_bitrate; |
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
1223 else pass2->bitrate = xvidenc_bitrate*1000; |
11437 | 1224 mp_msg(MSGT_MENCODER, MSGL_INFO, |
1225 "xvid: 2Pass Rate Control -- 2nd pass -- bitrate=%dkbit/s\n", | |
13675
d4cba4c4c54c
Bitrate setting option in ve_xvid4.c doesn't follow the rules described
rathann
parents:
13610
diff
changeset
|
1226 xvidenc_bitrate>16000?xvidenc_bitrate/1000:xvidenc_bitrate); |
11437 | 1227 } else { |
1228 pass2->bitrate = xvidenc_bitrate; | |
1229 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1230 "xvid: 2Pass Rate Control -- 2nd pass -- total size=%dkB\n", | |
1231 -xvidenc_bitrate); | |
1232 } | |
1233 | |
1234 create->plugins[create->num_plugins].func = xvid_plugin_2pass2; | |
1235 create->plugins[create->num_plugins].param = pass2; | |
1236 create->num_plugins++; | |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1237 doZones = 1; |
11437 | 1238 } |
15638
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
1239 |
16481
beebfccc00f1
adds Simple, Advanced Simple and DivX profile support for XviD, Patch by Robert Swain < robert POUM swain AH gmail POUM com >
gpoirier
parents:
15664
diff
changeset
|
1240 if(xvidenc_luminance_masking && (selected_profile->flags & PROFILE_ADAPTQUANT)) { |
15638
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
1241 create->plugins[create->num_plugins].func = xvid_plugin_lumimasking; |
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
1242 create->plugins[create->num_plugins].param = NULL; |
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
1243 create->num_plugins++; |
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
1244 } |
189da3c3116b
Add XviD's luminance masking (option name: lumi_mask)
gpoirier
parents:
15619
diff
changeset
|
1245 |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1246 // parse zones |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1247 if (xvidenc_zones != NULL && doZones > 0) // do not apply zones in CQ, and first pass mode (xvid vfw doesn't allow them in those modes either) |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1248 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1249 void *p; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1250 int i; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1251 p = xvidenc_zones; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1252 create->num_zones = 0; // set the number of zones back to zero, this overwrites the zone defined for CQ - desired because each zone has to be specified on the commandline even in cq mode |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1253 for(i = 0; p; i++) |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1254 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1255 int start; |
15664 | 1256 int q; |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1257 double value; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1258 char mode; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1259 int e = sscanf(p, "%d,%c,%lf", &start, &mode, &value); // start,mode(q = constant quant, w = weight),value |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1260 if(e != 3) |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1261 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1262 mp_msg(MSGT_MENCODER,MSGL_ERR, "error parsing zones\n"); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1263 return(BAD); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1264 } |
15664 | 1265 q = (int)(value * 100); |
15619
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1266 if (mode == 'q') |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1267 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1268 if (q < 200 || q > 3100) // make sure that quantizer is in allowable range |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1269 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1270 mp_msg(MSGT_MENCODER, MSGL_ERR, "zone quantizer must be between 2 and 31\n"); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1271 return(BAD); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1272 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1273 else |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1274 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1275 create->zones[create->num_zones].mode = XVID_ZONE_QUANT; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1276 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1277 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1278 if (mode == 'w') |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1279 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1280 if (q < 1 || q > 200) |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1281 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1282 mp_msg(MSGT_MENCODER, MSGL_ERR, "zone weight must be between 1 and 200\n"); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1283 return(BAD); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1284 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1285 else |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1286 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1287 create->zones[create->num_zones].mode = XVID_ZONE_WEIGHT; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1288 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1289 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1290 create->zones[create->num_zones].frame = start; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1291 create->zones[create->num_zones].increment = q; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1292 create->zones[create->num_zones].base = 100; // increment is 100 times the actual value |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1293 create->num_zones++; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1294 if (create->num_zones > MAX_ZONES) // show warning if we have too many zones |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1295 { |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1296 mp_msg(MSGT_MENCODER, MSGL_ERR, "too many zones, zones will be ignored\n"); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1297 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1298 p = strchr(p, '/'); |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1299 if(p) p++; |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1300 } |
ccf2c61afacd
XviD zones support. Patch by Doom9: < feedback123 GROOVY doom9 STEADY org >
gpoirier
parents:
15070
diff
changeset
|
1301 } |
11437 | 1302 return(FINE); |
1303 } | |
1304 | |
1305 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi) | |
1306 { | |
1307 xvid_enc_frame_t *frame = &mod->frame; | |
1308 | |
1309 /* Most of the initialization is done during dispatch_settings */ | |
1310 frame->version = XVID_VERSION; | |
1311 | |
1312 /* Bind output buffer */ | |
1313 frame->bitstream = mod->mux->buffer; | |
1314 frame->length = -1; | |
1315 | |
1316 /* Frame format */ | |
1317 switch(mpi->imgfmt) { | |
1318 case IMGFMT_YV12: | |
1319 case IMGFMT_IYUV: | |
1320 case IMGFMT_I420: | |
1321 frame->input.csp = XVID_CSP_USER; | |
1322 break; | |
1323 case IMGFMT_YUY2: | |
1324 frame->input.csp = XVID_CSP_YUY2; | |
1325 break; | |
1326 case IMGFMT_UYVY: | |
1327 frame->input.csp = XVID_CSP_UYVY; | |
1328 break; | |
1329 default: | |
1330 mp_msg(MSGT_MENCODER, MSGL_ERR, | |
1331 "xvid: unsupported picture format (%s)!\n", | |
1332 vo_format_name(mpi->imgfmt)); | |
1333 return(BAD); | |
1334 } | |
1335 | |
1336 /* Bind source frame */ | |
1337 frame->input.plane[0] = mpi->planes[0]; | |
1338 frame->input.plane[1] = mpi->planes[1]; | |
1339 frame->input.plane[2] = mpi->planes[2]; | |
1340 frame->input.stride[0] = mpi->stride[0]; | |
1341 frame->input.stride[1] = mpi->stride[1]; | |
1342 frame->input.stride[2] = mpi->stride[2]; | |
1343 | |
1344 /* Force the right quantizer -- It is internally managed by RC | |
1345 * plugins */ | |
1346 frame->quant = 0; | |
1347 | |
1348 return(FINE); | |
1349 } | |
1350 | |
13610 | 1351 static void |
1352 flush_internal_buffers(xvid_mplayer_module_t *mod) | |
1353 { | |
1354 int size; | |
1355 xvid_enc_frame_t *frame = &mod->frame; | |
1356 | |
1357 if (mod->instance == NULL) | |
1358 return;/*encoder not inited*/ | |
1359 | |
1360 /* Init a fake frame to force flushing */ | |
1361 frame->version = XVID_VERSION; | |
1362 frame->bitstream = mod->mux->buffer; | |
1363 frame->length = -1; | |
1364 frame->input.csp = XVID_CSP_NULL; | |
1365 frame->input.plane[0] = NULL; | |
1366 frame->input.plane[1] = NULL; | |
1367 frame->input.plane[2] = NULL; | |
1368 frame->input.stride[0] = 0; | |
1369 frame->input.stride[1] = 0; | |
1370 frame->input.stride[2] = 0; | |
1371 frame->quant = 0; | |
1372 | |
1373 /* Flush encoder buffers caused by bframes usage */ | |
1374 do { | |
1375 xvid_enc_stats_t stats; | |
1376 memset(&stats, 0, sizeof(xvid_enc_stats_t)); | |
1377 stats.version = XVID_VERSION; | |
1378 | |
1379 /* Encode internal buffer */ | |
1380 size = xvid_encore(mod->instance, XVID_ENC_ENCODE, &mod->frame, &stats); | |
1381 | |
1382 if (size>0) { | |
1383 /* Update stats */ | |
1384 update_stats(mod, &stats); | |
1385 | |
1386 /* xvidcore outputed bitstream -- mux it */ | |
1387 muxer_write_chunk(mod->mux, size, | |
17487
fa17424b4c7b
change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer
michael
parents:
17012
diff
changeset
|
1388 (mod->frame.out_flags & XVID_KEYFRAME)?0x10:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE); |
13610 | 1389 } |
1390 } while (size>0); | |
1391 } | |
1392 | |
1393 #define SSE2PSNR(sse, nbpixels) \ | |
1394 ((!(sse)) ? 99.99f : 48.131f - 10*(double)log10((double)(sse)/(double)((nbpixels)))) | |
1395 static void | |
1396 update_stats(xvid_mplayer_module_t *mod, xvid_enc_stats_t *stats) | |
1397 { | |
1398 if(xvidenc_stats && stats->type > 0) { | |
1399 mod->sse_y += stats->sse_y; | |
1400 mod->sse_u += stats->sse_u; | |
1401 mod->sse_v += stats->sse_v; | |
1402 | |
1403 if(mod->min_sse_y > stats->sse_y) { | |
1404 mod->min_sse_y = stats->sse_y; | |
1405 mod->min_sse_u = stats->sse_u; | |
1406 mod->min_sse_v = stats->sse_v; | |
1407 mod->min_framenum = mod->frames; | |
1408 } | |
1409 | |
1410 if(mod->max_sse_y < stats->sse_y) { | |
1411 mod->max_sse_y = stats->sse_y; | |
1412 mod->max_sse_u = stats->sse_u; | |
1413 mod->max_sse_v = stats->sse_v; | |
1414 mod->max_framenum = mod->frames; | |
1415 } | |
1416 | |
1417 if (xvidenc_psnr) { | |
1418 if (!mod->fvstats) { | |
1419 char filename[20]; | |
1420 time_t today2; | |
1421 struct tm *today; | |
1422 today2 = time (NULL); | |
1423 today = localtime (&today2); | |
1424 sprintf (filename, "psnr_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); | |
1425 mod->fvstats = fopen (filename,"w"); | |
1426 if (!mod->fvstats) { | |
1427 perror ("fopen"); | |
1428 /* Disable PSNR file output so we don't get here again */ | |
1429 xvidenc_psnr = 0; | |
1430 } | |
1431 } | |
1432 fprintf (mod->fvstats, "%6d, %2d, %6d, %2.2f, %2.2f, %2.2f, %2.2f %c\n", | |
1433 mod->frames, | |
1434 stats->quant, | |
1435 stats->length, | |
1436 SSE2PSNR (stats->sse_y, mod->pixels), | |
1437 SSE2PSNR (stats->sse_u, mod->pixels / 4), | |
1438 SSE2PSNR (stats->sse_v, mod->pixels / 4), | |
1439 SSE2PSNR (stats->sse_y + stats->sse_u + stats->sse_v,(double)mod->pixels * 1.5), | |
1440 stats->type==1?'I':stats->type==2?'P':stats->type==3?'B':stats->type?'S':'?' | |
1441 ); | |
1442 } | |
1443 mod->frames++; | |
1444 } | |
1445 } | |
1446 | |
1447 static void | |
1448 print_stats(xvid_mplayer_module_t *mod) | |
1449 { | |
1450 if (mod->frames) { | |
1451 mod->sse_y /= mod->frames; | |
1452 mod->sse_u /= mod->frames; | |
1453 mod->sse_v /= mod->frames; | |
1454 | |
1455 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1456 "The value 99.99dB is a special value and represents " | |
1457 "the upper range limit\n"); | |
1458 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1459 "xvid: Min PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, in frame %d\n", | |
1460 SSE2PSNR(mod->max_sse_y, mod->pixels), | |
1461 SSE2PSNR(mod->max_sse_u, mod->pixels/4), | |
1462 SSE2PSNR(mod->max_sse_v, mod->pixels/4), | |
1463 mod->max_framenum); | |
1464 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1465 "xvid: Average PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, for %d frames\n", | |
1466 SSE2PSNR(mod->sse_y, mod->pixels), | |
1467 SSE2PSNR(mod->sse_u, mod->pixels/4), | |
1468 SSE2PSNR(mod->sse_v, mod->pixels/4), | |
1469 mod->frames); | |
1470 mp_msg(MSGT_MENCODER, MSGL_INFO, | |
1471 "xvid: Max PSNR y : %.2f dB, u : %.2f dB, v : %.2f dB, in frame %d\n", | |
1472 SSE2PSNR(mod->min_sse_y, mod->pixels), | |
1473 SSE2PSNR(mod->min_sse_u, mod->pixels/4), | |
1474 SSE2PSNR(mod->min_sse_v, mod->pixels/4), | |
1475 mod->min_framenum); | |
1476 } | |
1477 } | |
1478 #undef SSE2PSNR | |
1479 | |
11437 | 1480 static void *read_matrix(unsigned char *filename) |
1481 { | |
1482 int i; | |
1483 unsigned char *matrix; | |
1484 FILE *input; | |
1485 | |
1486 /* Allocate matrix space */ | |
1487 if((matrix = malloc(64*sizeof(unsigned char))) == NULL) | |
1488 return(NULL); | |
1489 | |
1490 /* Open the matrix file */ | |
1491 if((input = fopen(filename, "rb")) == NULL) { | |
13610 | 1492 mp_msg(MSGT_MENCODER, MSGL_ERR, |
11437 | 1493 "xvid: Error opening the matrix file %s\n", |
1494 filename); | |
1495 free(matrix); | |
1496 return(NULL); | |
1497 } | |
1498 | |
1499 /* Read the matrix */ | |
1500 for(i=0; i<64; i++) { | |
1501 | |
1502 int value; | |
1503 | |
1504 /* If fscanf fails then get out of the loop */ | |
1505 if(fscanf(input, "%d", &value) != 1) { | |
13610 | 1506 mp_msg(MSGT_MENCODER, MSGL_ERR, |
11437 | 1507 "xvid: Error reading the matrix file %s\n", |
1508 filename); | |
1509 free(matrix); | |
1510 fclose(input); | |
1511 return(NULL); | |
1512 } | |
1513 | |
1514 /* Clamp the value to safe range */ | |
1515 value = (value< 1)?1 :value; | |
1516 value = (value>255)?255:value; | |
1517 matrix[i] = value; | |
1518 } | |
1519 | |
1520 /* Fills the rest with 1 */ | |
1521 while(i<64) matrix[i++] = 1; | |
1522 | |
1523 /* We're done */ | |
1524 fclose(input); | |
1525 | |
1526 return(matrix); | |
1527 | |
1528 } | |
1529 | |
13610 | 1530 |
1531 static const char * | |
1532 par_string(int parcode) | |
1533 { | |
1534 const char *par_string; | |
1535 switch (parcode) { | |
1536 case XVID_PAR_11_VGA: | |
1537 par_string = "vga11"; | |
1538 break; | |
1539 case XVID_PAR_43_PAL: | |
1540 par_string = "pal43"; | |
1541 break; | |
1542 case XVID_PAR_43_NTSC: | |
1543 par_string = "ntsc43"; | |
1544 break; | |
1545 case XVID_PAR_169_PAL: | |
1546 par_string = "pal169"; | |
1547 break; | |
1548 case XVID_PAR_169_NTSC: | |
1549 par_string = "ntsc69"; | |
1550 break; | |
1551 case XVID_PAR_EXT: | |
1552 par_string = "ext"; | |
1553 break; | |
1554 default: | |
1555 par_string = "unknown"; | |
1556 break; | |
1557 } | |
1558 return (par_string); | |
1559 } | |
1560 | |
11437 | 1561 static const char *errorstring(int err) |
1562 { | |
13610 | 1563 const char *error; |
11437 | 1564 switch(err) { |
1565 case XVID_ERR_FAIL: | |
1566 error = "General fault"; | |
1567 break; | |
1568 case XVID_ERR_MEMORY: | |
1569 error = "Memory allocation error"; | |
1570 break; | |
1571 case XVID_ERR_FORMAT: | |
1572 error = "File format error"; | |
1573 break; | |
1574 case XVID_ERR_VERSION: | |
1575 error = "Structure version not supported"; | |
1576 break; | |
1577 case XVID_ERR_END: | |
1578 error = "End of stream reached"; | |
1579 break; | |
1580 default: | |
1581 error = "Unknown"; | |
1582 } | |
1583 | |
13610 | 1584 return(error); |
11437 | 1585 } |
1586 | |
1587 /***************************************************************************** | |
1588 * Module structure definition | |
1589 ****************************************************************************/ | |
1590 | |
1591 vf_info_t ve_info_xvid = { | |
1592 "XviD 1.0 encoder", | |
1593 "xvid", | |
1594 "Marco Belli <elcabesa@inwind.it>, Edouard Gomez <ed.gomez@free.fr>", | |
1595 "No comment", | |
1596 vf_open | |
1597 }; | |
1598 | |
1599 | |
1600 #endif /* HAVE_XVID4 */ | |
1601 | |
1602 /* Please do not change that tag comment. | |
1603 * arch-tag: 42ccc257-0548-4a3e-9617-2876c4e8ac88 mplayer xvid encoder module */ |