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