annotate libxvidff.c @ 12180:b24153464669 libavcodec

Attempt to fix x86-64 testsuite on fate.
author rbultje
date Fri, 16 Jul 2010 21:35:30 +0000
parents dc6039ad4c7e
children a08f20066719
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
21
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
23 * @file
2131
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
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
27
12097
e8a29b278ebf Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
mru
parents: 12024
diff changeset
28 /* needed for mkstemp() */
e8a29b278ebf Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
mru
parents: 12024
diff changeset
29 #define _XOPEN_SOURCE 600
e8a29b278ebf Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
mru
parents: 12024
diff changeset
30
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
31 #include <xvid.h>
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
32 #include <unistd.h>
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
33 #include "avcodec.h"
8613
e75610c5da69 Fix compilation with --enable-libxvid.
cehoyos
parents: 8612
diff changeset
34 #include "libavutil/intreadwrite.h"
5101
c3f2379b80db Give all wrappers for external libraries names starting with lib.
diego
parents: 4962
diff changeset
35 #include "libxvid_internal.h"
12097
e8a29b278ebf Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
mru
parents: 12024
diff changeset
36 #if !HAVE_MKSTEMP
e8a29b278ebf Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
mru
parents: 12024
diff changeset
37 #include <fcntl.h>
e8a29b278ebf Move av_tempfile() to libxvidff.c as only the xvid wrapper needs it
mru
parents: 12024
diff changeset
38 #endif
2131
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 /**
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
41 * Buffer management macros.
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 #define BUFFER_SIZE 1024
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
44 #define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x))
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
45 #define BUFFER_CAT(x) (&((x)[strlen(x)]))
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 /* For PPC Use */
8250
cf4d575b1982 Delete unnecessary 'extern' keywords.
diego
parents: 7824
diff changeset
48 int has_altivec(void);
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
49
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
50 /**
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
51 * Structure for the private Xvid context.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
52 * 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
53 */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
54 struct xvid_context {
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
55 void *encoder_handle; /** Handle for Xvid encoder */
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
56 int xsize, ysize; /** Frame size */
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
57 int vop_flags; /** VOP flags for Xvid encoder */
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
58 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
59 int me_flags; /** Motion Estimation flags */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
60 int qscale; /** Do we use constant scale? */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
61 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
62 AVFrame encoded_picture; /** Encoded frame information */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
63 char *twopassbuffer; /** Character buffer for two-pass */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
64 char *old_twopassbuffer; /** Old character buffer (two-pass) */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
65 char *twopassfile; /** second pass temp file name */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
66 unsigned char *intra_matrix; /** P-Frame Quant Matrix */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
67 unsigned char *inter_matrix; /** I-Frame Quant Matrix */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
68 };
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
69
2131
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 * Structure for the private first-pass plugin.
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
72 */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
73 struct xvid_ff_pass1 {
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
74 int version; /** Xvid version */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
75 struct xvid_context *context; /** Pointer to private context */
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
76 };
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
77
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
78 /* Prototypes - See function implementation for details */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
79 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
80 int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
81 void xvid_correct_framerate(AVCodecContext *avctx);
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
82
12122
dc6039ad4c7e Current Cygwin has mkstemp().
victor
parents: 12119
diff changeset
83 /* Wrapper to work around the lack of mkstemp() on mingw.
12118
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
84 * Also, tries to create file in /tmp first, if possible.
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
85 * *prefix can be a character constant; *filename will be allocated internally.
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
86 * @return file descriptor of opened file (or -1 on error)
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
87 * and opened file name in **filename. */
12119
4530b6b4d931 libxvid: add some const fixing a warning
mru
parents: 12118
diff changeset
88 int ff_tempfile(const char *prefix, char **filename) {
12118
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
89 int fd=-1;
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
90 #if !HAVE_MKSTEMP
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
91 *filename = tempnam(".", prefix);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
92 #else
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
93 size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
94 *filename = av_malloc(len);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
95 #endif
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
96 /* -----common section-----*/
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
97 if (*filename == NULL) {
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
98 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
99 return -1;
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
100 }
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
101 #if !HAVE_MKSTEMP
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
102 fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
103 #else
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
104 snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
105 fd = mkstemp(*filename);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
106 if (fd < 0) {
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
107 snprintf(*filename, len, "./%sXXXXXX", prefix);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
108 fd = mkstemp(*filename);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
109 }
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
110 #endif
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
111 /* -----common section-----*/
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
112 if (fd < 0) {
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
113 av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
114 return -1;
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
115 }
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
116 return fd; /* success */
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
117 }
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
118
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
119 #if CONFIG_LIBXVID_ENCODER
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
120
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
121 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
122 * Create the private context for the encoder.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
123 * 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
124 * and the encoder context created.
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
125 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
126 * @param avctx AVCodecContext pointer to context
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
127 * @return Returns 0 on success, -1 on failure
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
128 */
11321
e0feb5fa4e97 Make the following functions static (and remove ff_), they are only used
cehoyos
parents: 10146
diff changeset
129 static av_cold int xvid_encode_init(AVCodecContext *avctx) {
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
130 int xerr, i;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
131 int xvid_flags = avctx->flags;
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
132 struct xvid_context *x = avctx->priv_data;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
133 uint16_t *intra, *inter;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
134 int fd;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
135
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
136 xvid_plugin_single_t single;
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
137 struct xvid_ff_pass1 rc2pass1;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
138 xvid_plugin_2pass2_t rc2pass2;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
139 xvid_gbl_init_t xvid_gbl_init;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
140 xvid_enc_create_t xvid_enc_create;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
141 xvid_enc_plugin_t plugins[7];
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
142
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
143 /* Bring in VOP flags from ffmpeg command-line */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
144 x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
145 if( xvid_flags & CODEC_FLAG_4MV )
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
146 x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */
7034
130784da5595 uniformize trellis quant option
bcoudurier
parents: 6908
diff changeset
147 if( avctx->trellis
130784da5595 uniformize trellis quant option
bcoudurier
parents: 6908
diff changeset
148 )
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
149 x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
150 if( xvid_flags & CODEC_FLAG_AC_PRED )
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
151 x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
152 if( xvid_flags & CODEC_FLAG_GRAY )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
153 x->vop_flags |= XVID_VOP_GREYSCALE;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
154
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
155 /* Decide which ME quality setting to use */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
156 x->me_flags = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
157 switch( avctx->me_method ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
158 case ME_FULL: /* Quality 6 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
159 x->me_flags |= XVID_ME_EXTSEARCH16
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
160 | XVID_ME_EXTSEARCH8;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
161
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
162 case ME_EPZS: /* Quality 4 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
163 x->me_flags |= XVID_ME_ADVANCEDDIAMOND8
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
164 | XVID_ME_HALFPELREFINE8
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
165 | XVID_ME_CHROMA_PVOP
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
166 | XVID_ME_CHROMA_BVOP;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
167
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
168 case ME_LOG: /* Quality 2 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
169 case ME_PHODS:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
170 case ME_X1:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
171 x->me_flags |= XVID_ME_ADVANCEDDIAMOND16
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
172 | XVID_ME_HALFPELREFINE16;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
173
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
174 case ME_ZERO: /* Quality 0 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
175 default:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
176 break;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
177 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
178
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
179 /* Decide how we should decide blocks */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
180 switch( avctx->mb_decision ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
181 case 2:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
182 x->vop_flags |= XVID_VOP_MODEDECISION_RD;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
183 x->me_flags |= XVID_ME_HALFPELREFINE8_RD
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
184 | XVID_ME_QUARTERPELREFINE8_RD
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
185 | XVID_ME_EXTSEARCH_RD
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
186 | XVID_ME_CHECKPREDICTION_RD;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
187 case 1:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
188 if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
189 x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
190 x->me_flags |= XVID_ME_HALFPELREFINE16_RD
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
191 | XVID_ME_QUARTERPELREFINE16_RD;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
192
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
193 default:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
194 break;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
195 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
196
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
197 /* Bring in VOL flags from ffmpeg command-line */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
198 x->vol_flags = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
199 if( xvid_flags & CODEC_FLAG_GMC ) {
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
200 x->vol_flags |= XVID_VOL_GMC;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
201 x->me_flags |= XVID_ME_GME_REFINE;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
202 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
203 if( xvid_flags & CODEC_FLAG_QPEL ) {
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
204 x->vol_flags |= XVID_VOL_QUARTERPEL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
205 x->me_flags |= XVID_ME_QUARTERPELREFINE16;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
206 if( x->vop_flags & XVID_VOP_INTER4V )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
207 x->me_flags |= XVID_ME_QUARTERPELREFINE8;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
208 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
209
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
210 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
211 xvid_gbl_init.version = XVID_VERSION;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
212 xvid_gbl_init.debug = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
213
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 8496
diff changeset
214 #if ARCH_PPC
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
215 /* Xvid's PPC support is borked, use libavcodec to detect */
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 8496
diff changeset
216 #if HAVE_ALTIVEC
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
217 if( has_altivec() ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
218 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
219 } else
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
220 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
221 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
222 #else
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
223 /* Xvid can detect on x86 */
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
224 xvid_gbl_init.cpu_flags = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
225 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
226
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
227 /* Initialize */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
228 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
229
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
230 /* Create the encoder reference */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
231 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
232 xvid_enc_create.version = XVID_VERSION;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
233
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
234 /* Store the desired frame size */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
235 xvid_enc_create.width = x->xsize = avctx->width;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
236 xvid_enc_create.height = x->ysize = avctx->height;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
237
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
238 /* 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
239 /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
240
6665
c22932db0ebb Make Xvid wrapper use threads (with support for newest CVS Xvid only)
superdump
parents: 6517
diff changeset
241 /* We don't use zones */
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
242 xvid_enc_create.zones = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
243 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
244
c22932db0ebb Make Xvid wrapper use threads (with support for newest CVS Xvid only)
superdump
parents: 6517
diff changeset
245 xvid_enc_create.num_threads = avctx->thread_count;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
246
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
247 xvid_enc_create.plugins = plugins;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
248 xvid_enc_create.num_plugins = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
249
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
250 /* Initialize Buffers */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
251 x->twopassbuffer = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
252 x->old_twopassbuffer = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
253 x->twopassfile = NULL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
254
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
255 if( xvid_flags & CODEC_FLAG_PASS1 ) {
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
256 memset(&rc2pass1, 0, sizeof(struct xvid_ff_pass1));
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
257 rc2pass1.version = XVID_VERSION;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
258 rc2pass1.context = x;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
259 x->twopassbuffer = av_malloc(BUFFER_SIZE);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
260 x->old_twopassbuffer = av_malloc(BUFFER_SIZE);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
261 if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
262 av_log(avctx, AV_LOG_ERROR,
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
263 "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
264 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
265 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
266 x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
267
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
268 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
269 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
270 xvid_enc_create.num_plugins++;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
271 } else if( xvid_flags & CODEC_FLAG_PASS2 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
272 memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t));
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
273 rc2pass2.version = XVID_VERSION;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
274 rc2pass2.bitrate = avctx->bit_rate;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
275
12098
95f57b61c9b3 Rename av_tempfile() to ff_tempfile()
mru
parents: 12097
diff changeset
276 fd = ff_tempfile("xvidff.", &(x->twopassfile));
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
277 if( fd == -1 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
278 av_log(avctx, AV_LOG_ERROR,
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
279 "Xvid: Cannot write 2-pass pipe\n");
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
280 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
281 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
282
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
283 if( avctx->stats_in == NULL ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
284 av_log(avctx, AV_LOG_ERROR,
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
285 "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
286 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
287 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
288
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
289 if( strlen(avctx->stats_in) >
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
290 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
291 close(fd);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
292 av_log(avctx, AV_LOG_ERROR,
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
293 "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
294 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
295 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
296
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
297 close(fd);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
298 rc2pass2.filename = x->twopassfile;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
299 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
300 plugins[xvid_enc_create.num_plugins].param = &rc2pass2;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
301 xvid_enc_create.num_plugins++;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
302 } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
303 /* Single Pass Bitrate Control! */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
304 memset(&single, 0, sizeof(xvid_plugin_single_t));
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
305 single.version = XVID_VERSION;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
306 single.bitrate = avctx->bit_rate;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
307
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
308 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
309 plugins[xvid_enc_create.num_plugins].param = &single;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
310 xvid_enc_create.num_plugins++;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
311 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
312
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
313 /* Luminance Masking */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
314 if( 0.0 != avctx->lumi_masking ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
315 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
316 plugins[xvid_enc_create.num_plugins].param = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
317 xvid_enc_create.num_plugins++;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
318 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
319
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
320 /* Frame Rate and Key Frames */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
321 xvid_correct_framerate(avctx);
2637
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
322 xvid_enc_create.fincr = avctx->time_base.num;
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
323 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
324 if( avctx->gop_size > 0 )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
325 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
326 else
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
327 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
328
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
329 /* Quants */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
330 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
331 else x->qscale = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
332
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
333 xvid_enc_create.min_quant[0] = avctx->qmin;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
334 xvid_enc_create.min_quant[1] = avctx->qmin;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
335 xvid_enc_create.min_quant[2] = avctx->qmin;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
336 xvid_enc_create.max_quant[0] = avctx->qmax;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
337 xvid_enc_create.max_quant[1] = avctx->qmax;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
338 xvid_enc_create.max_quant[2] = avctx->qmax;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
339
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
340 /* Quant Matrices */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
341 x->intra_matrix = x->inter_matrix = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
342 if( avctx->mpeg_quant )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
343 x->vol_flags |= XVID_VOL_MPEGQUANT;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
344 if( (avctx->intra_matrix || avctx->inter_matrix) ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
345 x->vol_flags |= XVID_VOL_MPEGQUANT;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
346
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
347 if( avctx->intra_matrix ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
348 intra = avctx->intra_matrix;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
349 x->intra_matrix = av_malloc(sizeof(unsigned char) * 64);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
350 } else
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
351 intra = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
352 if( avctx->inter_matrix ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
353 inter = avctx->inter_matrix;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
354 x->inter_matrix = av_malloc(sizeof(unsigned char) * 64);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
355 } else
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
356 inter = NULL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
357
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
358 for( i = 0; i < 64; i++ ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
359 if( intra )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
360 x->intra_matrix[i] = (unsigned char)intra[i];
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
361 if( inter )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
362 x->inter_matrix[i] = (unsigned char)inter[i];
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
363 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
364 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
365
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
366 /* Misc Settings */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
367 xvid_enc_create.frame_drop_ratio = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
368 xvid_enc_create.global = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
369 if( xvid_flags & CODEC_FLAG_CLOSED_GOP )
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
370 xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP;
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 /* Determines which codec mode we are operating in */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
373 avctx->extradata = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
374 avctx->extradata_size = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
375 if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
376 /* 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
377 x->quicktime_format = 1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
378 avctx->codec_id = CODEC_ID_MPEG4;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
379 } else {
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
380 /* We are claiming to be Xvid */
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
381 x->quicktime_format = 0;
4023
508f089d0b28 Have xvid encoder wrapper honnor -vtag option
gpoirier
parents: 4004
diff changeset
382 if(!avctx->codec_tag)
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8611
diff changeset
383 avctx->codec_tag = AV_RL32("xvid");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
384 }
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
385
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
386 /* Bframes */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
387 xvid_enc_create.max_bframes = avctx->max_b_frames;
3202
89348aaf566e fixing bquant_offset
michael
parents: 3036
diff changeset
388 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
389 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
390 if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
391
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
392 /* Create encoder context */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
393 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
394 if( xerr ) {
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
395 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
396 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
397 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
398
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
399 x->encoder_handle = xvid_enc_create.handle;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
400 avctx->coded_frame = &x->encoded_picture;
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 return 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
403 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
404
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
405 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
406 * Encode a single frame.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
407 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
408 * @param avctx AVCodecContext pointer to context
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
409 * @param frame Pointer to encoded frame buffer
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
410 * @param buf_size Size of encoded frame buffer
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
411 * @param data Pointer to AVFrame of unencoded frame
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
412 * @return Returns 0 on success, -1 on failure
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
413 */
11321
e0feb5fa4e97 Make the following functions static (and remove ff_), they are only used
cehoyos
parents: 10146
diff changeset
414 static int xvid_encode_frame(AVCodecContext *avctx,
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
415 unsigned char *frame, int buf_size, void *data) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
416 int xerr, i;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
417 char *tmp;
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
418 struct xvid_context *x = avctx->priv_data;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
419 AVFrame *picture = data;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
420 AVFrame *p = &(x->encoded_picture);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
421
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
422 xvid_enc_frame_t xvid_enc_frame;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
423 xvid_enc_stats_t xvid_enc_stats;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
424
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
425 /* Start setting up the frame */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
426 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
427 xvid_enc_frame.version = XVID_VERSION;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
428 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
429 xvid_enc_stats.version = XVID_VERSION;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
430 *p = *picture;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
431
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
432 /* 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
433 xvid_enc_frame.bitstream = frame;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
434 xvid_enc_frame.length = buf_size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
435
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
436 /* Initialize input image fields */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
437 if( avctx->pix_fmt != PIX_FMT_YUV420P ) {
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
438 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
439 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
440 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
441
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
442 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
443
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
444 for( i = 0; i < 4; i++ ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
445 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
446 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
447 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
448
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
449 /* Encoder Flags */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
450 xvid_enc_frame.vop_flags = x->vop_flags;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
451 xvid_enc_frame.vol_flags = x->vol_flags;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
452 xvid_enc_frame.motion = x->me_flags;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
453 xvid_enc_frame.type = XVID_TYPE_AUTO;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
454
6670
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
455 /* Pixel aspect ratio setting */
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
456 if (avctx->sample_aspect_ratio.num < 1 || avctx->sample_aspect_ratio.num > 255 ||
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
457 avctx->sample_aspect_ratio.den < 1 || avctx->sample_aspect_ratio.den > 255) {
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
458 av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n",
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
459 avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
460 return -1;
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
461 }
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
462 xvid_enc_frame.par = XVID_PAR_EXT;
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
463 xvid_enc_frame.par_width = avctx->sample_aspect_ratio.num;
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
464 xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;
33d3c14d5a57 Set pixel aspect ratio for libxvid wrapper.
benoit
parents: 6665
diff changeset
465
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
466 /* Quant Setting */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
467 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
468 else xvid_enc_frame.quant = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
469
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
470 /* Matrices */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
471 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
472 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
473
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
474 /* Encode */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
475 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
476 &xvid_enc_frame, &xvid_enc_stats);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
477
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
478 /* Two-pass log buffer swapping */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
479 avctx->stats_out = NULL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
480 if( x->twopassbuffer ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
481 tmp = x->old_twopassbuffer;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
482 x->old_twopassbuffer = x->twopassbuffer;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
483 x->twopassbuffer = tmp;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
484 x->twopassbuffer[0] = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
485 if( x->old_twopassbuffer[0] != 0 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
486 avctx->stats_out = x->old_twopassbuffer;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
487 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
488 }
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
489
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
490 if( 0 <= xerr ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
491 p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
492 if( xvid_enc_stats.type == XVID_TYPE_PVOP )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
493 p->pict_type = FF_P_TYPE;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
494 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
495 p->pict_type = FF_B_TYPE;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
496 else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
2451
michael
parents: 2131
diff changeset
497 p->pict_type = FF_S_TYPE;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
498 else
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
499 p->pict_type = FF_I_TYPE;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
500 if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
501 p->key_frame = 1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
502 if( x->quicktime_format )
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
503 return xvid_strip_vol_header(avctx, frame,
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
504 xvid_enc_stats.hlength, xerr);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
505 } else
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
506 p->key_frame = 0;
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 return xerr;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
509 } else {
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
510 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
511 return -1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
512 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
513 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
514
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
515 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
516 * Destroy the private context for the encoder.
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
517 * 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
518 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
519 * @param avctx AVCodecContext pointer to context
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
520 * @return Returns 0, success guaranteed
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
521 */
11321
e0feb5fa4e97 Make the following functions static (and remove ff_), they are only used
cehoyos
parents: 10146
diff changeset
522 static av_cold int xvid_encode_close(AVCodecContext *avctx) {
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
523 struct xvid_context *x = avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
524
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
525 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
526
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
527 if( avctx->extradata != NULL )
11543
965eca23972e libxvid: Clear extradata pointer when freeing it.
ramiro
parents: 11468
diff changeset
528 av_freep(&avctx->extradata);
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
529 if( x->twopassbuffer != NULL ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
530 av_free(x->twopassbuffer);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
531 av_free(x->old_twopassbuffer);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
532 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
533 if( x->twopassfile != NULL )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
534 av_free(x->twopassfile);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
535 if( x->intra_matrix != NULL )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
536 av_free(x->intra_matrix);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
537 if( x->inter_matrix != NULL )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
538 av_free(x->inter_matrix);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
539
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
540 return 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
541 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
542
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
543 /**
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
544 * Routine to create a global VO/VOL header for MP4 container.
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
545 * 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
546 * 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
547 * 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
548 * compliance.
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
549 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
550 * @param avctx AVCodecContext pointer to context
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
551 * @param frame Pointer to encoded frame data
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
552 * @param header_len Length of header to search
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
553 * @param frame_len Length of encoded frame data
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
554 * @return Returns new length of frame data
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
555 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
556 int xvid_strip_vol_header(AVCodecContext *avctx,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
557 unsigned char *frame,
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
558 unsigned int header_len,
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
559 unsigned int frame_len) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
560 int vo_len = 0, i;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
561
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
562 for( i = 0; i < header_len - 3; i++ ) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
563 if( frame[i] == 0x00 &&
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
564 frame[i+1] == 0x00 &&
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
565 frame[i+2] == 0x01 &&
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
566 frame[i+3] == 0xB6 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
567 vo_len = i;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
568 break;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
569 }
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
570 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
571
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
572 if( vo_len > 0 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
573 /* 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
574 if( avctx->extradata == NULL ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
575 avctx->extradata = av_malloc(vo_len);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
576 memcpy(avctx->extradata, frame, vo_len);
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
577 avctx->extradata_size = vo_len;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
578 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
579 /* Less dangerous now, memmove properly copies the two
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
580 chunks of overlapping data */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
581 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
582 return frame_len - vo_len;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
583 } else
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
584 return frame_len;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
585 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
586
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
587 /**
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
588 * Routine to correct a possibly erroneous framerate being fed to us.
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
589 * 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
590 * extremely large. This function works to correct problems in this area
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
591 * 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
592 * the two presented.
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
593 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
594 * @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
595 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
596 void xvid_correct_framerate(AVCodecContext *avctx) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
597 int frate, fbase;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
598 int est_frate, est_fbase;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
599 int gcd;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
600 float est_fps, fps;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
601
2637
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
602 frate = avctx->time_base.den;
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
603 fbase = avctx->time_base.num;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
604
8611
a637db9f59b1 export gcd function as av_gcd()
aurel
parents: 8590
diff changeset
605 gcd = av_gcd(frate, fbase);
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
606 if( gcd > 1 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
607 frate /= gcd;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
608 fbase /= gcd;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
609 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
610
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
611 if( frate <= 65000 && fbase <= 65000 ) {
2637
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
612 avctx->time_base.den = frate;
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
613 avctx->time_base.num = fbase;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
614 return;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
615 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
616
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
617 fps = (float)frate / (float)fbase;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
618 est_fps = roundf(fps * 1000.0) / 1000.0;
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 est_frate = (int)est_fps;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
621 if( est_fps > (int)est_fps ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
622 est_frate = (est_frate + 1) * 1000;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
623 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
624 } else
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
625 est_fbase = 1;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
626
8611
a637db9f59b1 export gcd function as av_gcd()
aurel
parents: 8590
diff changeset
627 gcd = av_gcd(est_frate, est_fbase);
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
628 if( gcd > 1 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
629 est_frate /= gcd;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
630 est_fbase /= gcd;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
631 }
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
632
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
633 if( fbase > est_fbase ) {
2637
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
634 avctx->time_base.den = est_frate;
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
635 avctx->time_base.num = est_fbase;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
636 av_log(avctx, AV_LOG_DEBUG,
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
637 "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
638 est_fps, (((est_fps - fps)/fps) * 100.0));
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
639 } else {
2637
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
640 avctx->time_base.den = frate;
ef44d24680d1 switch to native time bases
michael
parents: 2574
diff changeset
641 avctx->time_base.num = fbase;
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 /*
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
646 * Xvid 2-Pass Kludge Section
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
647 *
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
648 * 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
649 * 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
650 * statistic information as libavcodec requests in. We have another kludge
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
651 * 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
652 * rate-control plugin.
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
653 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
654
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
655 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
656 * Initialize the two-pass plugin and context.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
657 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
658 * @param param Input construction parameter structure
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
659 * @param handle Private context handle
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
660 * @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
661 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
662 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
663 void ** handle) {
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
664 struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *)param->param;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
665 char *log = x->context->twopassbuffer;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
666
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
667 /* Do a quick bounds check */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
668 if( log == NULL )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
669 return XVID_ERR_FAIL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
670
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
671 /* We use snprintf() */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
672 /* 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
673 log[0] = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
674 snprintf(log, BUFFER_REMAINING(log),
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
675 "# 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
676 snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
677 "# 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
678 XVID_VERSION_MAJOR(XVID_VERSION),
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
679 XVID_VERSION_MINOR(XVID_VERSION),
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
680 XVID_VERSION_PATCH(XVID_VERSION));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
681
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
682 *handle = x->context;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
683 return 0;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
684 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
685
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
686 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
687 * Destroy the two-pass plugin context.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
688 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
689 * @param ref Context pointer for the plugin
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
690 * @param param Destrooy context
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
691 * @return Returns 0, success guaranteed
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
692 */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
693 static int xvid_ff_2pass_destroy(struct xvid_context *ref,
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
694 xvid_plg_destroy_t *param) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
695 /* 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
696 /* 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
697 if( ref->twopassbuffer != NULL )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
698 ref->twopassbuffer[0] = 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
699 return 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
700 }
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 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
703 * Enable fast encode mode during the first pass.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
704 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
705 * @param ref Context pointer for the plugin
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
706 * @param param Frame data
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
707 * @return Returns 0, success guaranteed
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
708 */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
709 static int xvid_ff_2pass_before(struct xvid_context *ref,
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
710 xvid_plg_data_t *param) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
711 int motion_remove;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
712 int motion_replacements;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
713 int vop_remove;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
714
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
715 /* 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
716 if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
717 return 0;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
718
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
719 /* We can implement a 'turbo' first pass mode here */
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
720 param->quant = 2;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
721
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
722 /* Init values */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
723 motion_remove = ~XVID_ME_CHROMA_PVOP &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
724 ~XVID_ME_CHROMA_BVOP &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
725 ~XVID_ME_EXTSEARCH16 &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
726 ~XVID_ME_ADVANCEDDIAMOND16;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
727 motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
728 XVID_ME_SKIP_DELTASEARCH |
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
729 XVID_ME_FASTREFINE16 |
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
730 XVID_ME_BFRAME_EARLYSTOP;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
731 vop_remove = ~XVID_VOP_MODEDECISION_RD &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
732 ~XVID_VOP_FAST_MODEDECISION_RD &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
733 ~XVID_VOP_TRELLISQUANT &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
734 ~XVID_VOP_INTER4V &
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
735 ~XVID_VOP_HQACPRED;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
736
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
737 param->vol_flags &= ~XVID_VOL_GMC;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
738 param->vop_flags &= vop_remove;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
739 param->motion_flags &= motion_remove;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
740 param->motion_flags |= motion_replacements;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
741
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
742 return 0;
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
743 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
744
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
745 /**
12024
fdafbcef52f5 Fix grammar errors in documentation
mru
parents: 11644
diff changeset
746 * Capture statistic data and write it during first pass.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
747 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
748 * @param ref Context pointer for the plugin
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
749 * @param param Statistic data
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
750 * @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
751 */
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
752 static int xvid_ff_2pass_after(struct xvid_context *ref,
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
753 xvid_plg_data_t *param) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
754 char *log = ref->twopassbuffer;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
755 char *frame_types = " ipbs";
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
756 char frame_type;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
757
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
758 /* Quick bounds check */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
759 if( log == NULL )
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
760 return XVID_ERR_FAIL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
761
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
762 /* 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
763 if( param->type < 5 && param->type > 0 ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
764 frame_type = frame_types[param->type];
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
765 } else {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
766 return XVID_ERR_FAIL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
767 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
768
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
769 snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
770 "%c %d %d %d %d %d %d\n",
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
771 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
772 param->stats.ublks, param->stats.length, param->stats.hlength);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
773
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
774 return 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
775 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
776
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
777 /**
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
778 * Dispatch function for our custom plugin.
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
779 * 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
780 * on to other functions for actual processing.
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
781 *
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
782 * @param ref Context pointer for the plugin
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
783 * @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
784 * @param p1 First parameter (varies)
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
785 * @param p2 Second parameter (varies)
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
786 * @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
787 */
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
788 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
789 switch( cmd ) {
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
790 case XVID_PLG_INFO:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
791 case XVID_PLG_FRAME:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
792 return 0;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
793
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
794 case XVID_PLG_BEFORE:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
795 return xvid_ff_2pass_before(ref, p1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
796
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
797 case XVID_PLG_CREATE:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
798 return xvid_ff_2pass_create(p1, p2);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
799
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
800 case XVID_PLG_AFTER:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
801 return xvid_ff_2pass_after(ref, p1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
802
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
803 case XVID_PLG_DESTROY:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
804 return xvid_ff_2pass_destroy(ref, p1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2821
diff changeset
805
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
806 default:
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
807 return XVID_ERR_FAIL;
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
808 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
809 }
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
810
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
811 /**
6908
25dcd46b8160 cosmetics: XviD is now called Xvid.
diego
parents: 6788
diff changeset
812 * Xvid codec definition for libavcodec.
2131
060053df9538 XviD Support patch by (Adam Thayer <krevnik at comcast dot net>)
michael
parents:
diff changeset
813 */
5103
1deb3e53da27 Consistent naming and lib prefixes for x264, xvid and mp3lame within the code.
diego
parents: 5101
diff changeset
814 AVCodec libxvid_encoder = {
1deb3e53da27 Consistent naming and lib prefixes for x264, xvid and mp3lame within the code.
diego
parents: 5101
diff changeset
815 "libxvid",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11543
diff changeset
816 AVMEDIA_TYPE_VIDEO,
11468
67786aecf351 libxvid is producing standard mpeg4 so it don't need its own codec id
aurel
parents: 11321
diff changeset
817 CODEC_ID_MPEG4,
8315
7ccdcc976edd Do not invade _t POSIX namespace.
diego
parents: 8250
diff changeset
818 sizeof(struct xvid_context),
11321
e0feb5fa4e97 Make the following functions static (and remove ff_), they are only used
cehoyos
parents: 10146
diff changeset
819 xvid_encode_init,
e0feb5fa4e97 Make the following functions static (and remove ff_), they are only used
cehoyos
parents: 10146
diff changeset
820 xvid_encode_frame,
e0feb5fa4e97 Make the following functions static (and remove ff_), they are only used
cehoyos
parents: 10146
diff changeset
821 xvid_encode_close,
10146
38cfe222e1a4 Mark all pix_fmts and supported_framerates compound literals as const.
reimar
parents: 8718
diff changeset
822 .pix_fmts= (const 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
823 .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
824 };
12118
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
825
14f1cfd2f1f2 Allow using libxvid RC without enabling encoding wrapper
mru
parents: 12098
diff changeset
826 #endif /* CONFIG_LIBXVID_ENCODER */