~ubuntu-branches/ubuntu/oneiric/avidemux/oneiric-proposed

« back to all changes in this revision

Viewing changes to avidemux/ADM_encoder/adm_encXvid4.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-08-20 08:42:44 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090820084244-bhh15xxd7x2vbcuh
Tags: 1:2.5.1+repack-0ubuntu1
* New upstream bugfix release (LP: #416066):
  - Re-enabled several video and audio encoders (regression introduced
    in 2.5.0)
  - Updated the FFmpeg libraries
  - More video encoders are now plugins
  - DV video encoder now supports more profiles
  - Fixed loading and saving issues with LAME, x264 and Xvid options
    (regression introduced in 2.5.0)
  - Fraps video decoding support
  - Lowpass-5 mode added to libavcodec deinterlacer filter plugin
  - Fixed formatting of parameters for various filters on 64-bit platforms
  - Updated libass
  - Fixed sizing of the bitrate control on various video encoder configure
    windows (regression introduced in 2.5.0)
  - Improved filter dialog for GTK+ interface
  - New navigation icons for GTK+ interface
  - Fixed the behaviour of several GTK+ open/save dialogs (regression
    introduced in 2.5.0)
  - asharp filter's Block Adaptive mode can now be disabled using the Qt
    interface
  - Re-enabled the colour chooser dialog using the Qt interface (regression
    introduced in 2.5.0)
  - GCC 4.4 support
  - Fixed issues with CMake build scripts when using multiple make jobs
    (regression introduced in 2.5.0)
* Remove debian/patches dir and drop all patches, now applied by upstream.
* Drop quilt support.
* debian/libavidemux0.install: Also install missing libraries.
* Move debian/install to debian/avidemux.install.
* debian/rules:
  - Build the internal ffmpeg version properly (thanks to Christian Marillat).
  - A bit of cleanup.
* debian/control:
  - Bump Standards-Version.
  - Update Homepage field.
  - Adjust libavidemux0 short description.
  - gtk -> GTK, qt -> QT.
  - Set myself as Maintainer.
* Repack the tarball to remove the debian/ dir provided by upstream:
  - Create debian/README.source.
  - Update debian/watch.
  - Add get-orig-source target to debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          adm_encxvid.cpp  -  description
3
 
                             -------------------
4
 
                             Encoder for Xvid 1.0x (dev-api4)
5
 
    begin                : Sun Jul 14 2002
6
 
    copyright            : (C) 2002/2003 by mean
7
 
    email                : fixounet@free.fr
8
 
 ***************************************************************************/
9
 
 
10
 
/***************************************************************************
11
 
 *                                                                         *
12
 
 *   This program is free software; you can redistribute it and/or modify  *
13
 
 *   it under the terms of the GNU General Public License as published by  *
14
 
 *   the Free Software Foundation; either version 2 of the License, or     *
15
 
 *   (at your option) any later version.                                   *
16
 
 *                                                                         *
17
 
 ***************************************************************************/
18
 
#include "config.h"
19
 
 
20
 
#define __STDC_LIMIT_MACROS
21
 
 
22
 
#ifdef USE_XVID_4
23
 
#include "xvid.h"
24
 
 
25
 
#include "fourcc.h"
26
 
#include "avi_vars.h"
27
 
 
28
 
#include "ADM_default.h"
29
 
 
30
 
#include "ADM_encoder/ADM_vidEncode.hxx"
31
 
 
32
 
#include "ADM_videoFilter.h"
33
 
#include "ADM_codecs/ADM_xvid4.h"
34
 
#include "ADM_encoder/adm_encoder.h"
35
 
#include "ADM_encoder/adm_encXvid4.h"
36
 
 
37
 
 
38
 
#define aprintf printf
39
 
 
40
 
 
41
 
 
42
 
/*_________________________________________________*/
43
 
EncoderXvid4::EncoderXvid4 (COMPRES_PARAMS * codecconfig)
44
 
{
45
 
 
46
 
  _codec = NULL;
47
 
  strcpy (_logname, "");
48
 
  _frametogo = 0;
49
 
  _pass1Done = 0;
50
 
 
51
 
  memcpy (&_param, codecconfig, sizeof (_param));
52
 
  ADM_assert (codecconfig->extraSettingsLen == sizeof (encparam));
53
 
  memcpy (&encparam, codecconfig->extraSettings, sizeof (encparam));
54
 
 
55
 
 
56
 
};
57
 
EncoderXvid4::~EncoderXvid4 ()
58
 
{
59
 
 
60
 
  stop ();
61
 
 
62
 
};
63
 
//--------------------------------
64
 
uint8_t
65
 
EncoderXvid4::configure (AVDMGenericVideoStream * instream, int useExistingLogFile)
66
 
{
67
 
  ADM_assert (instream);
68
 
  ADV_Info *info;
69
 
 
70
 
  //uint32_t flag1,flag2,flag3;
71
 
  if(encparam.par_as_input)
72
 
  {
73
 
    encparam.par_width=instream->getPARWidth();
74
 
    encparam.par_height=instream->getPARHeight();
75
 
  }else
76
 
  {
77
 
      printf("[xvid] Using %u x %u aspect ratio\n",encparam.par_width,encparam.par_height);
78
 
  }
79
 
  
80
 
  //
81
 
  info = instream->getInfo ();
82
 
  _w = info->width;
83
 
  _h = info->height;
84
 
//  _vbuffer = new uint8_t[_w * _h * 2];
85
 
  _vbuffer = new ADMImage (_w, _h);
86
 
  ADM_assert (_vbuffer);
87
 
  _in = instream;
88
 
  _fps1000 = info->fps1000;
89
 
  switch (_param.mode)
90
 
    {
91
 
    case COMPRESS_SAME:
92
 
      printf ("[xvid] Follow quant mode\n");
93
 
      _state = enc_Same;
94
 
      _codec = new xvid4EncoderVBRExternal (_w, _h);
95
 
      if (!_codec->init (2, info->fps1000, &encparam))
96
 
        {
97
 
          printf ("[xvid] Error init Follow mode\n");
98
 
          return 0;
99
 
        }
100
 
      break;
101
 
    case COMPRESS_CQ:
102
 
      printf ("[xvid] CQ mode: %ld\n", _param.qz);
103
 
      _state = enc_CQ;
104
 
      _codec = new xvid4EncoderCQ (_w, _h);
105
 
 
106
 
      if (!_codec->init (_param.qz, info->fps1000, &encparam))
107
 
        {
108
 
          printf ("[xvid] Error init CQ mode\n");
109
 
          return 0;
110
 
        }
111
 
      break;
112
 
    case COMPRESS_CBR:
113
 
      printf ("[xvid] CBR mode: %lu\n", _param.bitrate);
114
 
      _state = enc_CBR;
115
 
 
116
 
      _codec = new xvid4EncoderCBR (_w, _h);
117
 
      if (!_codec->init (_param.bitrate, info->fps1000, &encparam))
118
 
        {
119
 
          printf ("[xvid] Error init CBR mode\n");
120
 
          return 0;
121
 
        }
122
 
      break;
123
 
    case COMPRESS_2PASS:
124
 
    case COMPRESS_2PASS_BITRATE:
125
 
      if(_param.mode==COMPRESS_2PASS)
126
 
          printf ("[xvid] Dual size: %lu (%s)\n", _param.finalsize, _logname);
127
 
      else
128
 
          printf ("[xvid] Dual avg br: %u kb/s (%s)\n", _param.avg_bitrate, _logname);
129
 
      _state = enc_Pass1;
130
 
      _codec = new xvid4EncoderPass1 (_w, _h);
131
 
      strcpy (encparam.logName, _logname);
132
 
      printf ("[xvid] Using %s as stat file\n", encparam.logName);
133
 
 
134
 
      break;
135
 
    default:
136
 
      ADM_assert (0);
137
 
    }
138
 
  printf ("[xvid] Encoder ready, w: %lu h: %lu mode: %d\n", _w, _h, _state);
139
 
  return 1;
140
 
 
141
 
}
142
 
 
143
 
 
144
 
 
145
 
uint8_t EncoderXvid4::startPass1 (void)
146
 
{
147
 
  ADV_Info *
148
 
    info;
149
 
  ADM_assert (_state == enc_Pass1);
150
 
  info = _in->getInfo ();
151
 
  if (!_codec->init (_param.bitrate, info->fps1000, &encparam))
152
 
    {
153
 
      printf ("[xvid] Error init pass 1 mode\n");
154
 
      return 0;
155
 
    }
156
 
  return 1;
157
 
}
158
 
 
159
 
int EncoderXvid4::getRequirements (void) { return ADM_ENC_REQ_NULL_FLUSH; }
160
 
 
161
 
uint8_t EncoderXvid4::isDualPass (void)
162
 
{
163
 
  if ((_state == enc_Pass1) || (_state == enc_Pass2))
164
 
    {
165
 
      return 1;
166
 
    }
167
 
  return 0;
168
 
 
169
 
}
170
 
 
171
 
uint8_t EncoderXvid4::setLogFile (const char *lofile, uint32_t nbframe)
172
 
{
173
 
  strcpy (_logname, lofile);
174
 
  _frametogo = nbframe;
175
 
  _totalframe = nbframe;
176
 
  return 1;
177
 
 
178
 
}
179
 
 
180
 
//______________________________
181
 
uint8_t
182
 
  EncoderXvid4::encode (uint32_t frame, ADMBitstream *out)
183
 
{
184
 
  uint32_t l, f;
185
 
 
186
 
  ADM_assert (_codec);
187
 
  ADM_assert (_in);
188
 
 
189
 
  if (frame != UINT32_MAX)
190
 
  {
191
 
          if (!_in->getFrameNumberNoAlloc (frame, &l, _vbuffer, &f))
192
 
          {
193
 
                  printf ("[xvid] Error: Cannot read incoming frame!\n");
194
 
                  return 0;
195
 
          }
196
 
  }
197
 
 
198
 
  switch (_state)
199
 
    {
200
 
    case enc_Same:
201
 
        {
202
 
                if (frame != UINT32_MAX)
203
 
                {
204
 
                        out->flags = 0;
205
 
 
206
 
                        if (frame < (encparam.bframes + 1))
207
 
                        {
208
 
                                out->flags = AVI_KEY_FRAME;
209
 
                                printf ("[xvid] Forcing keyframe for B frame\n");
210
 
                        }
211
 
 
212
 
                        int q = _vbuffer->_Qp;
213
 
 
214
 
                        if (q < 2 || q > 31)
215
 
                        {
216
 
                                printf ("[xvid] Out of bound incoming q: %d\n", q);
217
 
 
218
 
                                if (q < 2)
219
 
                                        q = 2;
220
 
                                if (q > 31)
221
 
                                        q = 31;
222
 
                        }
223
 
 
224
 
                        out->in_quantizer = q;
225
 
                }
226
 
        }
227
 
    case enc_CBR:
228
 
    case enc_CQ:
229
 
    case enc_Pass1:
230
 
    case enc_Pass2:
231
 
                return _codec->encode (frame == UINT32_MAX ? NULL : _vbuffer, out);
232
 
      break;
233
 
 
234
 
    default:
235
 
      ADM_assert (0);
236
 
    }
237
 
 
238
 
  return 0;
239
 
}
240
 
 
241
 
//_______________________________
242
 
uint8_t EncoderXvid4::stop (void)
243
 
{
244
 
  if (_codec)
245
 
    delete
246
 
      _codec;
247
 
  _codec = NULL;
248
 
 
249
 
 
250
 
  return 1;
251
 
 
252
 
}
253
 
extern uint32_t ADM_computeBitrate(uint32_t fps1000, uint32_t nbFrame, uint32_t sizeInMB);
254
 
uint8_t EncoderXvid4::startPass2 (void)
255
 
{
256
 
  uint32_t     finalSize;
257
 
  uint32_t         br;
258
 
 
259
 
  ADM_assert (_state == enc_Pass1);
260
 
  printf ("[xvid] Starting pass 2 (%d x %d)\n", _w, _h);
261
 
 
262
 
  if(_param.mode==COMPRESS_2PASS)
263
 
  {
264
 
    
265
 
    br=ADM_computeBitrate( _fps1000,_totalframe,_param.finalsize);
266
 
    printf("[xvid] Final Size: %u MB, avg bitrate %u kb/s\n",_param.finalsize,br/1000);
267
 
  }else if(_param.mode==COMPRESS_2PASS_BITRATE)
268
 
  {
269
 
    br=_param.avg_bitrate*1000;
270
 
    printf("[xvid] 2 pass avg bitrate %u kb/s\n",br/1000);
271
 
  }else ADM_assert(0);
272
 
 
273
 
  _state = enc_Pass2;
274
 
  // Delete codec and start new one
275
 
  if (_codec)
276
 
    {
277
 
      delete
278
 
        _codec;
279
 
      _codec = NULL;
280
 
    }
281
 
 
282
 
  _codec = new xvid4EncoderPass2 (_w, _h);
283
 
  strcpy (encparam.logName, _logname);
284
 
  printf ("[xvid] Using %s as stat file, average bitrate %d kbps\n", _logname,    br / 1000);
285
 
  if (!_codec->init (br, _fps1000, &encparam))
286
 
    {
287
 
      printf ("[xvid] Error initializing pass1 mode\n");
288
 
      return 0;
289
 
    }
290
 
  _frametogo = 0;
291
 
  return 1;
292
 
}
293
 
 
294
 
#endif