Mercurial > libavcodec.hg
annotate libxvidff.c @ 7439:deea146537af libavcodec
Cosmetics: align comments
author | vitor |
---|---|
date | Mon, 28 Jul 2008 05:16:51 +0000 |
parents | e943e1409077 |
children | 635ed2559262 |
rev | line source |
---|---|
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
1 /* |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
2 * Interface to xvidcore for mpeg4 encoding |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
3 * Copyright (c) 2004 Adam Thayer <krevnik@comcast.net> |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3343
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3343
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3343
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3343
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3343
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
16 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3343
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
20 */ |
2967 | 21 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
22 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
23 * @file xvidmpeg4.c |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
24 * Interface to xvidcore for MPEG-4 compliant encoding. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
25 * @author Adam Thayer (krevnik@comcast.net) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
26 */ |
2967 | 27 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
28 #include <xvid.h> |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
29 #include <unistd.h> |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
30 #include "avcodec.h" |
5101
c3f2379b80db
Give all wrappers for external libraries names starting with lib.
diego
parents:
4962
diff
changeset
|
31 #include "libxvid_internal.h" |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
32 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
33 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
34 * Buffer management macros. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
35 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
36 #define BUFFER_SIZE 1024 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
37 #define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x)) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
38 #define BUFFER_CAT(x) (&((x)[strlen(x)])) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
39 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
40 /* For PPC Use */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
41 extern int has_altivec(void); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
42 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
43 /** |
6908 | 44 * Structure for the private Xvid context. |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
45 * This stores all the private context for the codec. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
46 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
47 typedef struct xvid_context { |
6908 | 48 void *encoder_handle; /** Handle for Xvid encoder */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
49 int xsize, ysize; /** Frame size */ |
6908 | 50 int vop_flags; /** VOP flags for Xvid encoder */ |
51 int vol_flags; /** VOL flags for Xvid encoder */ | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
52 int me_flags; /** Motion Estimation flags */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
53 int qscale; /** Do we use constant scale? */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
54 int quicktime_format; /** Are we in a QT-based format? */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
55 AVFrame encoded_picture; /** Encoded frame information */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
56 char *twopassbuffer; /** Character buffer for two-pass */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
57 char *old_twopassbuffer; /** Old character buffer (two-pass) */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
58 char *twopassfile; /** second pass temp file name */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
59 unsigned char *intra_matrix; /** P-Frame Quant Matrix */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
60 unsigned char *inter_matrix; /** I-Frame Quant Matrix */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
61 } xvid_context_t; |
2967 | 62 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
63 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
64 * Structure for the private first-pass plugin. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
65 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
66 typedef struct xvid_ff_pass1 { |
6908 | 67 int version; /** Xvid version */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
68 xvid_context_t *context; /** Pointer to private context */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
69 } xvid_ff_pass1_t; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
70 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
71 /* Prototypes - See function implementation for details */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
72 int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned int header_len, unsigned int frame_len); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
73 int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); |
2967 | 74 void xvid_correct_framerate(AVCodecContext *avctx); |
75 | |
76 /** | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
77 * Creates the private context for the encoder. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
78 * All buffers are allocated, settings are loaded from the user, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
79 * and the encoder context created. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
80 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
81 * @param avctx AVCodecContext pointer to context |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
82 * @return Returns 0 on success, -1 on failure |
2967 | 83 */ |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6344
diff
changeset
|
84 av_cold int ff_xvid_encode_init(AVCodecContext *avctx) { |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
85 int xerr, i; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
86 int xvid_flags = avctx->flags; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
87 xvid_context_t *x = avctx->priv_data; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
88 uint16_t *intra, *inter; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
89 int fd; |
2967 | 90 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
91 xvid_plugin_single_t single; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
92 xvid_ff_pass1_t rc2pass1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
93 xvid_plugin_2pass2_t rc2pass2; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
94 xvid_gbl_init_t xvid_gbl_init; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
95 xvid_enc_create_t xvid_enc_create; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
96 xvid_enc_plugin_t plugins[7]; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
97 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
98 /* Bring in VOP flags from ffmpeg command-line */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
99 x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ |
2967 | 100 if( xvid_flags & CODEC_FLAG_4MV ) |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
101 x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */ |
7034 | 102 if( avctx->trellis |
103 #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) | |
104 || xvid_flags & CODEC_FLAG_TRELLIS_QUANT | |
105 #endif | |
106 ) | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
107 x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */ |
2967 | 108 if( xvid_flags & CODEC_FLAG_AC_PRED ) |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
109 x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
110 if( xvid_flags & CODEC_FLAG_GRAY ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
111 x->vop_flags |= XVID_VOP_GREYSCALE; |
2967 | 112 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
113 /* Decide which ME quality setting to use */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
114 x->me_flags = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
115 switch( avctx->me_method ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
116 case ME_FULL: /* Quality 6 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
117 x->me_flags |= XVID_ME_EXTSEARCH16 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
118 | XVID_ME_EXTSEARCH8; |
2967 | 119 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
120 case ME_EPZS: /* Quality 4 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
121 x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
122 | XVID_ME_HALFPELREFINE8 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
123 | XVID_ME_CHROMA_PVOP |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
124 | XVID_ME_CHROMA_BVOP; |
2967 | 125 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
126 case ME_LOG: /* Quality 2 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
127 case ME_PHODS: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
128 case ME_X1: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
129 x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
130 | XVID_ME_HALFPELREFINE16; |
2967 | 131 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
132 case ME_ZERO: /* Quality 0 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
133 default: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
134 break; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
135 } |
2967 | 136 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
137 /* Decide how we should decide blocks */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
138 switch( avctx->mb_decision ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
139 case 2: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
140 x->vop_flags |= XVID_VOP_MODEDECISION_RD; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
141 x->me_flags |= XVID_ME_HALFPELREFINE8_RD |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
142 | XVID_ME_QUARTERPELREFINE8_RD |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
143 | XVID_ME_EXTSEARCH_RD |
2967 | 144 | XVID_ME_CHECKPREDICTION_RD; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
145 case 1: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
146 if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
147 x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
148 x->me_flags |= XVID_ME_HALFPELREFINE16_RD |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
149 | XVID_ME_QUARTERPELREFINE16_RD; |
2967 | 150 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
151 default: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
152 break; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
153 } |
2967 | 154 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
155 /* Bring in VOL flags from ffmpeg command-line */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
156 x->vol_flags = 0; |
2967 | 157 if( xvid_flags & CODEC_FLAG_GMC ) { |
158 x->vol_flags |= XVID_VOL_GMC; | |
159 x->me_flags |= XVID_ME_GME_REFINE; | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
160 } |
2967 | 161 if( xvid_flags & CODEC_FLAG_QPEL ) { |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
162 x->vol_flags |= XVID_VOL_QUARTERPEL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
163 x->me_flags |= XVID_ME_QUARTERPELREFINE16; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
164 if( x->vop_flags & XVID_VOP_INTER4V ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
165 x->me_flags |= XVID_ME_QUARTERPELREFINE8; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
166 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
167 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
168 memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
169 xvid_gbl_init.version = XVID_VERSION; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
170 xvid_gbl_init.debug = 0; |
2967 | 171 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
172 #ifdef ARCH_POWERPC |
6908 | 173 /* Xvid's PPC support is borked, use libavcodec to detect */ |
6343
870714b0f293
Use HAVE_ALTIVEC preprocessor conditionals like in the rest of FFmpeg.
diego
parents:
5103
diff
changeset
|
174 #ifdef HAVE_ALTIVEC |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
175 if( has_altivec() ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
176 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
177 } else |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
178 #endif |
2967 | 179 xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
180 #else |
6908 | 181 /* Xvid can detect on x86 */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
182 xvid_gbl_init.cpu_flags = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
183 #endif |
2967 | 184 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
185 /* Initialize */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
186 xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
187 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
188 /* Create the encoder reference */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
189 memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
190 xvid_enc_create.version = XVID_VERSION; |
2967 | 191 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
192 /* Store the desired frame size */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
193 xvid_enc_create.width = x->xsize = avctx->width; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
194 xvid_enc_create.height = x->ysize = avctx->height; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
195 |
6908 | 196 /* Xvid can determine the proper profile to use */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
197 /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ |
2967 | 198 |
6665
c22932db0ebb
Make Xvid wrapper use threads (with support for newest CVS Xvid only)
superdump
parents:
6517
diff
changeset
|
199 /* We don't use zones */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
200 xvid_enc_create.zones = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
201 xvid_enc_create.num_zones = 0; |
6665
c22932db0ebb
Make Xvid wrapper use threads (with support for newest CVS Xvid only)
superdump
parents:
6517
diff
changeset
|
202 |
c22932db0ebb
Make Xvid wrapper use threads (with support for newest CVS Xvid only)
superdump
parents:
6517
diff
changeset
|
203 xvid_enc_create.num_threads = avctx->thread_count; |
2967 | 204 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
205 xvid_enc_create.plugins = plugins; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
206 xvid_enc_create.num_plugins = 0; |
2967 | 207 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
208 /* Initialize Buffers */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
209 x->twopassbuffer = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
210 x->old_twopassbuffer = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
211 x->twopassfile = NULL; |
2967 | 212 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
213 if( xvid_flags & CODEC_FLAG_PASS1 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
214 memset(&rc2pass1, 0, sizeof(xvid_ff_pass1_t)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
215 rc2pass1.version = XVID_VERSION; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
216 rc2pass1.context = x; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
217 x->twopassbuffer = av_malloc(BUFFER_SIZE); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
218 x->old_twopassbuffer = av_malloc(BUFFER_SIZE); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
219 if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
220 av_log(avctx, AV_LOG_ERROR, |
6908 | 221 "Xvid: Cannot allocate 2-pass log buffers\n"); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
222 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
223 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
224 x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; |
2967 | 225 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
226 plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
227 plugins[xvid_enc_create.num_plugins].param = &rc2pass1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
228 xvid_enc_create.num_plugins++; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
229 } else if( xvid_flags & CODEC_FLAG_PASS2 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
230 memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
231 rc2pass2.version = XVID_VERSION; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
232 rc2pass2.bitrate = avctx->bit_rate; |
2967 | 233 |
3233
18af2f7788c6
- Add new file internal.h for common internal-use-only functions.
corey
parents:
3202
diff
changeset
|
234 fd = av_tempfile("xvidff.", &(x->twopassfile)); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
235 if( fd == -1 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
236 av_log(avctx, AV_LOG_ERROR, |
6908 | 237 "Xvid: Cannot write 2-pass pipe\n"); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
238 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
239 } |
2967 | 240 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
241 if( avctx->stats_in == NULL ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
242 av_log(avctx, AV_LOG_ERROR, |
6908 | 243 "Xvid: No 2-pass information loaded for second pass\n"); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
244 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
245 } |
2967 | 246 |
247 if( strlen(avctx->stats_in) > | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
248 write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
249 close(fd); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
250 av_log(avctx, AV_LOG_ERROR, |
6908 | 251 "Xvid: Cannot write to 2-pass pipe\n"); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
252 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
253 } |
2967 | 254 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
255 close(fd); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
256 rc2pass2.filename = x->twopassfile; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
257 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
258 plugins[xvid_enc_create.num_plugins].param = &rc2pass2; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
259 xvid_enc_create.num_plugins++; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
260 } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
261 /* Single Pass Bitrate Control! */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
262 memset(&single, 0, sizeof(xvid_plugin_single_t)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
263 single.version = XVID_VERSION; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
264 single.bitrate = avctx->bit_rate; |
2967 | 265 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
266 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
267 plugins[xvid_enc_create.num_plugins].param = &single; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
268 xvid_enc_create.num_plugins++; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
269 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
270 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
271 /* Luminance Masking */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
272 if( 0.0 != avctx->lumi_masking ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
273 plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
274 plugins[xvid_enc_create.num_plugins].param = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
275 xvid_enc_create.num_plugins++; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
276 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
277 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
278 /* Frame Rate and Key Frames */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
279 xvid_correct_framerate(avctx); |
2637 | 280 xvid_enc_create.fincr = avctx->time_base.num; |
281 xvid_enc_create.fbase = avctx->time_base.den; | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
282 if( avctx->gop_size > 0 ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
283 xvid_enc_create.max_key_interval = avctx->gop_size; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
284 else |
6908 | 285 xvid_enc_create.max_key_interval = 240; /* Xvid's best default */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
286 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
287 /* Quants */ |
2967 | 288 if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
289 else x->qscale = 0; |
2967 | 290 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
291 xvid_enc_create.min_quant[0] = avctx->qmin; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
292 xvid_enc_create.min_quant[1] = avctx->qmin; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
293 xvid_enc_create.min_quant[2] = avctx->qmin; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
294 xvid_enc_create.max_quant[0] = avctx->qmax; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
295 xvid_enc_create.max_quant[1] = avctx->qmax; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
296 xvid_enc_create.max_quant[2] = avctx->qmax; |
2967 | 297 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
298 /* Quant Matrices */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
299 x->intra_matrix = x->inter_matrix = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
300 if( avctx->mpeg_quant ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
301 x->vol_flags |= XVID_VOL_MPEGQUANT; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
302 if( (avctx->intra_matrix || avctx->inter_matrix) ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
303 x->vol_flags |= XVID_VOL_MPEGQUANT; |
2967 | 304 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
305 if( avctx->intra_matrix ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
306 intra = avctx->intra_matrix; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
307 x->intra_matrix = av_malloc(sizeof(unsigned char) * 64); |
2967 | 308 } else |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
309 intra = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
310 if( avctx->inter_matrix ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
311 inter = avctx->inter_matrix; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
312 x->inter_matrix = av_malloc(sizeof(unsigned char) * 64); |
2967 | 313 } else |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
314 inter = NULL; |
2967 | 315 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
316 for( i = 0; i < 64; i++ ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
317 if( intra ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
318 x->intra_matrix[i] = (unsigned char)intra[i]; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
319 if( inter ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
320 x->inter_matrix[i] = (unsigned char)inter[i]; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
321 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
322 } |
2967 | 323 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
324 /* Misc Settings */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
325 xvid_enc_create.frame_drop_ratio = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
326 xvid_enc_create.global = 0; |
2967 | 327 if( xvid_flags & CODEC_FLAG_CLOSED_GOP ) |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
328 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
329 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
330 /* Determines which codec mode we are operating in */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
331 avctx->extradata = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
332 avctx->extradata_size = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
333 if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
334 /* In this case, we are claiming to be MPEG4 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
335 x->quicktime_format = 1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
336 avctx->codec_id = CODEC_ID_MPEG4; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
337 } else { |
6908 | 338 /* We are claiming to be Xvid */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
339 x->quicktime_format = 0; |
4023 | 340 if(!avctx->codec_tag) |
341 avctx->codec_tag = ff_get_fourcc("xvid"); | |
2967 | 342 } |
343 | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
344 /* Bframes */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
345 xvid_enc_create.max_bframes = avctx->max_b_frames; |
3202 | 346 xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
347 xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
348 if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED; |
2967 | 349 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
350 /* Create encoder context */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
351 xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
352 if( xerr ) { |
6908 | 353 av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n"); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
354 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
355 } |
2967 | 356 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
357 x->encoder_handle = xvid_enc_create.handle; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
358 avctx->coded_frame = &x->encoded_picture; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
359 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
360 return 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
361 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
362 |
2967 | 363 /** |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
364 * Encodes a single frame. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
365 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
366 * @param avctx AVCodecContext pointer to context |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
367 * @param frame Pointer to encoded frame buffer |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
368 * @param buf_size Size of encoded frame buffer |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
369 * @param data Pointer to AVFrame of unencoded frame |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
370 * @return Returns 0 on success, -1 on failure |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
371 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
372 int ff_xvid_encode_frame(AVCodecContext *avctx, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
373 unsigned char *frame, int buf_size, void *data) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
374 int xerr, i; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
375 char *tmp; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
376 xvid_context_t *x = avctx->priv_data; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
377 AVFrame *picture = data; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
378 AVFrame *p = &(x->encoded_picture); |
2967 | 379 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
380 xvid_enc_frame_t xvid_enc_frame; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
381 xvid_enc_stats_t xvid_enc_stats; |
2967 | 382 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
383 /* Start setting up the frame */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
384 memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
385 xvid_enc_frame.version = XVID_VERSION; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
386 memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
387 xvid_enc_stats.version = XVID_VERSION; |
2967 | 388 *p = *picture; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
389 |
6908 | 390 /* Let Xvid know where to put the frame. */ |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
391 xvid_enc_frame.bitstream = frame; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
392 xvid_enc_frame.length = buf_size; |
2967 | 393 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
394 /* Initialize input image fields */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
395 if( avctx->pix_fmt != PIX_FMT_YUV420P ) { |
6908 | 396 av_log(avctx, AV_LOG_ERROR, "Xvid: Color spaces other than 420p not supported\n"); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
397 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
398 } |
2967 | 399 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
400 xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
401 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
402 for( i = 0; i < 4; i++ ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
403 xvid_enc_frame.input.plane[i] = picture->data[i]; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
404 xvid_enc_frame.input.stride[i] = picture->linesize[i]; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
405 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
406 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
407 /* Encoder Flags */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
408 xvid_enc_frame.vop_flags = x->vop_flags; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
409 xvid_enc_frame.vol_flags = x->vol_flags; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
410 xvid_enc_frame.motion = x->me_flags; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
411 xvid_enc_frame.type = XVID_TYPE_AUTO; |
2967 | 412 |
6670 | 413 /* Pixel aspect ratio setting */ |
414 if (avctx->sample_aspect_ratio.num < 1 || avctx->sample_aspect_ratio.num > 255 || | |
415 avctx->sample_aspect_ratio.den < 1 || avctx->sample_aspect_ratio.den > 255) { | |
416 av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n", | |
417 avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); | |
418 return -1; | |
419 } | |
420 xvid_enc_frame.par = XVID_PAR_EXT; | |
421 xvid_enc_frame.par_width = avctx->sample_aspect_ratio.num; | |
422 xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den; | |
423 | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
424 /* Quant Setting */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
425 if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
426 else xvid_enc_frame.quant = 0; |
2967 | 427 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
428 /* Matrices */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
429 xvid_enc_frame.quant_intra_matrix = x->intra_matrix; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
430 xvid_enc_frame.quant_inter_matrix = x->inter_matrix; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
431 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
432 /* Encode */ |
2967 | 433 xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE, |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
434 &xvid_enc_frame, &xvid_enc_stats); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
435 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
436 /* Two-pass log buffer swapping */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
437 avctx->stats_out = NULL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
438 if( x->twopassbuffer ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
439 tmp = x->old_twopassbuffer; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
440 x->old_twopassbuffer = x->twopassbuffer; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
441 x->twopassbuffer = tmp; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
442 x->twopassbuffer[0] = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
443 if( x->old_twopassbuffer[0] != 0 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
444 avctx->stats_out = x->old_twopassbuffer; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
445 } |
2967 | 446 } |
447 | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
448 if( 0 <= xerr ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
449 p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
450 if( xvid_enc_stats.type == XVID_TYPE_PVOP ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
451 p->pict_type = FF_P_TYPE; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
452 else if( xvid_enc_stats.type == XVID_TYPE_BVOP ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
453 p->pict_type = FF_B_TYPE; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
454 else if( xvid_enc_stats.type == XVID_TYPE_SVOP ) |
2451 | 455 p->pict_type = FF_S_TYPE; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
456 else |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
457 p->pict_type = FF_I_TYPE; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
458 if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
459 p->key_frame = 1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
460 if( x->quicktime_format ) |
2967 | 461 return xvid_strip_vol_header(avctx, frame, |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
462 xvid_enc_stats.hlength, xerr); |
2967 | 463 } else |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
464 p->key_frame = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
465 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
466 return xerr; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
467 } else { |
6908 | 468 av_log(avctx, AV_LOG_ERROR, "Xvid: Encoding Error Occurred: %i\n", xerr); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
469 return -1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
470 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
471 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
472 |
2967 | 473 /** |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
474 * Destroys the private context for the encoder. |
6908 | 475 * All buffers are freed, and the Xvid encoder context is destroyed. |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
476 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
477 * @param avctx AVCodecContext pointer to context |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
478 * @return Returns 0, success guaranteed |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
479 */ |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6344
diff
changeset
|
480 av_cold int ff_xvid_encode_close(AVCodecContext *avctx) { |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
481 xvid_context_t *x = avctx->priv_data; |
2967 | 482 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
483 xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
484 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
485 if( avctx->extradata != NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
486 av_free(avctx->extradata); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
487 if( x->twopassbuffer != NULL ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
488 av_free(x->twopassbuffer); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
489 av_free(x->old_twopassbuffer); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
490 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
491 if( x->twopassfile != NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
492 av_free(x->twopassfile); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
493 if( x->intra_matrix != NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
494 av_free(x->intra_matrix); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
495 if( x->inter_matrix != NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
496 av_free(x->inter_matrix); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
497 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
498 return 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
499 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
500 |
2967 | 501 /** |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
502 * Routine to create a global VO/VOL header for MP4 container. |
6908 | 503 * What we do here is extract the header from the Xvid bitstream |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
504 * as it is encoded. We also strip the repeated headers from the |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
505 * bitstream when a global header is requested for MPEG-4 ISO |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
506 * compliance. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
507 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
508 * @param avctx AVCodecContext pointer to context |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
509 * @param frame Pointer to encoded frame data |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
510 * @param header_len Length of header to search |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
511 * @param frame_len Length of encoded frame data |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
512 * @return Returns new length of frame data |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
513 */ |
2967 | 514 int xvid_strip_vol_header(AVCodecContext *avctx, |
515 unsigned char *frame, | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
516 unsigned int header_len, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
517 unsigned int frame_len) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
518 int vo_len = 0, i; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
519 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
520 for( i = 0; i < header_len - 3; i++ ) { |
2967 | 521 if( frame[i] == 0x00 && |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
522 frame[i+1] == 0x00 && |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
523 frame[i+2] == 0x01 && |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
524 frame[i+3] == 0xB6 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
525 vo_len = i; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
526 break; |
2967 | 527 } |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
528 } |
2967 | 529 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
530 if( vo_len > 0 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
531 /* We need to store the header, so extract it */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
532 if( avctx->extradata == NULL ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
533 avctx->extradata = av_malloc(vo_len); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
534 memcpy(avctx->extradata, frame, vo_len); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
535 avctx->extradata_size = vo_len; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
536 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
537 /* Less dangerous now, memmove properly copies the two |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
538 chunks of overlapping data */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
539 memmove(frame, &(frame[vo_len]), frame_len - vo_len); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
540 return frame_len - vo_len; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
541 } else |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
542 return frame_len; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
543 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
544 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
545 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
546 * Routine to correct a possibly erroneous framerate being fed to us. |
6908 | 547 * Xvid currently chokes on framerates where the ticks per frame is |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
548 * extremely large. This function works to correct problems in this area |
2967 | 549 * by estimating a new framerate and taking the simpler fraction of |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
550 * the two presented. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
551 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
552 * @param avctx Context that contains the framerate to correct. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
553 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
554 void xvid_correct_framerate(AVCodecContext *avctx) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
555 int frate, fbase; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
556 int est_frate, est_fbase; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
557 int gcd; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
558 float est_fps, fps; |
2967 | 559 |
2637 | 560 frate = avctx->time_base.den; |
561 fbase = avctx->time_base.num; | |
2967 | 562 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
563 gcd = ff_gcd(frate, fbase); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
564 if( gcd > 1 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
565 frate /= gcd; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
566 fbase /= gcd; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
567 } |
2967 | 568 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
569 if( frate <= 65000 && fbase <= 65000 ) { |
2637 | 570 avctx->time_base.den = frate; |
571 avctx->time_base.num = fbase; | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
572 return; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
573 } |
2967 | 574 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
575 fps = (float)frate / (float)fbase; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
576 est_fps = roundf(fps * 1000.0) / 1000.0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
577 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
578 est_frate = (int)est_fps; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
579 if( est_fps > (int)est_fps ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
580 est_frate = (est_frate + 1) * 1000; |
2967 | 581 est_fbase = (int)roundf((float)est_frate / est_fps); |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
582 } else |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
583 est_fbase = 1; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
584 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
585 gcd = ff_gcd(est_frate, est_fbase); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
586 if( gcd > 1 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
587 est_frate /= gcd; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
588 est_fbase /= gcd; |
2967 | 589 } |
590 | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
591 if( fbase > est_fbase ) { |
2637 | 592 avctx->time_base.den = est_frate; |
593 avctx->time_base.num = est_fbase; | |
2967 | 594 av_log(avctx, AV_LOG_DEBUG, |
6908 | 595 "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n", |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
596 est_fps, (((est_fps - fps)/fps) * 100.0)); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
597 } else { |
2637 | 598 avctx->time_base.den = frate; |
599 avctx->time_base.num = fbase; | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
600 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
601 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
602 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
603 /* |
6908 | 604 * Xvid 2-Pass Kludge Section |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
605 * |
6908 | 606 * Xvid's default 2-pass doesn't allow us to create data as we need to, so |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
607 * this section spends time replacing the first pass plugin so we can write |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
608 * statistic information as libavcodec requests in. We have another kludge |
6908 | 609 * that allows us to pass data to the second pass in Xvid without a custom |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
610 * rate-control plugin. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
611 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
612 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
613 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
614 * Initializes the two-pass plugin and context. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
615 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
616 * @param param Input construction parameter structure |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
617 * @param handle Private context handle |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
618 * @return Returns XVID_ERR_xxxx on failure, or 0 on success. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
619 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
620 static int xvid_ff_2pass_create(xvid_plg_create_t * param, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
621 void ** handle) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
622 xvid_ff_pass1_t *x = (xvid_ff_pass1_t *)param->param; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
623 char *log = x->context->twopassbuffer; |
2967 | 624 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
625 /* Do a quick bounds check */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
626 if( log == NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
627 return XVID_ERR_FAIL; |
2967 | 628 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
629 /* We use snprintf() */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
630 /* This is because we can safely prevent a buffer overflow */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
631 log[0] = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
632 snprintf(log, BUFFER_REMAINING(log), |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
633 "# ffmpeg 2-pass log file, using xvid codec\n"); |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
634 snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
635 "# Do not modify. libxvidcore version: %d.%d.%d\n\n", |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
636 XVID_VERSION_MAJOR(XVID_VERSION), |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
637 XVID_VERSION_MINOR(XVID_VERSION), |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
638 XVID_VERSION_PATCH(XVID_VERSION)); |
2967 | 639 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
640 *handle = x->context; |
2967 | 641 return 0; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
642 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
643 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
644 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
645 * Destroys the two-pass plugin context. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
646 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
647 * @param ref Context pointer for the plugin |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
648 * @param param Destrooy context |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
649 * @return Returns 0, success guaranteed |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
650 */ |
2967 | 651 static int xvid_ff_2pass_destroy(xvid_context_t *ref, |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
652 xvid_plg_destroy_t *param) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
653 /* Currently cannot think of anything to do on destruction */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
654 /* Still, the framework should be here for reference/use */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
655 if( ref->twopassbuffer != NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
656 ref->twopassbuffer[0] = 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
657 return 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
658 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
659 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
660 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
661 * Enables fast encode mode during the first pass. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
662 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
663 * @param ref Context pointer for the plugin |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
664 * @param param Frame data |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
665 * @return Returns 0, success guaranteed |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
666 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
667 static int xvid_ff_2pass_before(xvid_context_t *ref, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
668 xvid_plg_data_t *param) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
669 int motion_remove; |
2967 | 670 int motion_replacements; |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
671 int vop_remove; |
2967 | 672 |
673 /* Nothing to do here, result is changed too much */ | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
674 if( param->zone && param->zone->mode == XVID_ZONE_QUANT ) |
2967 | 675 return 0; |
676 | |
677 /* We can implement a 'turbo' first pass mode here */ | |
678 param->quant = 2; | |
679 | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
680 /* Init values */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
681 motion_remove = ~XVID_ME_CHROMA_PVOP & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
682 ~XVID_ME_CHROMA_BVOP & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
683 ~XVID_ME_EXTSEARCH16 & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
684 ~XVID_ME_ADVANCEDDIAMOND16; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
685 motion_replacements = XVID_ME_FAST_MODEINTERPOLATE | |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
686 XVID_ME_SKIP_DELTASEARCH | |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
687 XVID_ME_FASTREFINE16 | |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
688 XVID_ME_BFRAME_EARLYSTOP; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
689 vop_remove = ~XVID_VOP_MODEDECISION_RD & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
690 ~XVID_VOP_FAST_MODEDECISION_RD & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
691 ~XVID_VOP_TRELLISQUANT & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
692 ~XVID_VOP_INTER4V & |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
693 ~XVID_VOP_HQACPRED; |
2967 | 694 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
695 param->vol_flags &= ~XVID_VOL_GMC; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
696 param->vop_flags &= vop_remove; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
697 param->motion_flags &= motion_remove; |
2967 | 698 param->motion_flags |= motion_replacements; |
699 | |
700 return 0; | |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
701 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
702 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
703 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
704 * Captures statistic data and writes it during first pass. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
705 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
706 * @param ref Context pointer for the plugin |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
707 * @param param Statistic data |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
708 * @return Returns XVID_ERR_xxxx on failure, or 0 on success |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
709 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
710 static int xvid_ff_2pass_after(xvid_context_t *ref, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
711 xvid_plg_data_t *param) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
712 char *log = ref->twopassbuffer; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
713 char *frame_types = " ipbs"; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
714 char frame_type; |
2967 | 715 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
716 /* Quick bounds check */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
717 if( log == NULL ) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
718 return XVID_ERR_FAIL; |
2967 | 719 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
720 /* Convert the type given to us into a character */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
721 if( param->type < 5 && param->type > 0 ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
722 frame_type = frame_types[param->type]; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
723 } else { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
724 return XVID_ERR_FAIL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
725 } |
2967 | 726 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
727 snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
728 "%c %d %d %d %d %d %d\n", |
2967 | 729 frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks, |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
730 param->stats.ublks, param->stats.length, param->stats.hlength); |
2967 | 731 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
732 return 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
733 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
734 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
735 /** |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
736 * Dispatch function for our custom plugin. |
6908 | 737 * This handles the dispatch for the Xvid plugin. It passes data |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
738 * on to other functions for actual processing. |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
739 * |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
740 * @param ref Context pointer for the plugin |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
741 * @param cmd The task given for us to complete |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
742 * @param p1 First parameter (varies) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
743 * @param p2 Second parameter (varies) |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
744 * @return Returns XVID_ERR_xxxx on failure, or 0 on success |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
745 */ |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
746 int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
747 switch( cmd ) { |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
748 case XVID_PLG_INFO: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
749 case XVID_PLG_FRAME: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
750 return 0; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
751 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
752 case XVID_PLG_BEFORE: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
753 return xvid_ff_2pass_before(ref, p1); |
2967 | 754 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
755 case XVID_PLG_CREATE: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
756 return xvid_ff_2pass_create(p1, p2); |
2967 | 757 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
758 case XVID_PLG_AFTER: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
759 return xvid_ff_2pass_after(ref, p1); |
2967 | 760 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
761 case XVID_PLG_DESTROY: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
762 return xvid_ff_2pass_destroy(ref, p1); |
2967 | 763 |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
764 default: |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
765 return XVID_ERR_FAIL; |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
766 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
767 } |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
768 |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
769 /** |
6908 | 770 * Xvid codec definition for libavcodec. |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
771 */ |
5103
1deb3e53da27
Consistent naming and lib prefixes for x264, xvid and mp3lame within the code.
diego
parents:
5101
diff
changeset
|
772 AVCodec libxvid_encoder = { |
1deb3e53da27
Consistent naming and lib prefixes for x264, xvid and mp3lame within the code.
diego
parents:
5101
diff
changeset
|
773 "libxvid", |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
774 CODEC_TYPE_VIDEO, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
775 CODEC_ID_XVID, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
776 sizeof(xvid_context_t), |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
777 ff_xvid_encode_init, |
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
778 ff_xvid_encode_frame, |
3343 | 779 ff_xvid_encode_close, |
6788 | 780 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
7034
diff
changeset
|
781 .long_name= NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"), |
2131
060053df9538
XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff
changeset
|
782 }; |