You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1326 lines
40KB

  1. /*
  2. * The simplest mpeg encoder (well, it was the simplest!)
  3. * Copyright (c) 2000,2001 Gerard Lantau.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include <string.h>
  23. #include "avcodec.h"
  24. #include "dsputil.h"
  25. #include "mpegvideo.h"
  26. #include "../config.h"
  27. #ifdef ARCH_X86
  28. #include "i386/mpegvideo.c"
  29. #endif
  30. #ifndef DCT_UNQUANTIZE
  31. #define DCT_UNQUANTIZE(a,b,c,d) dct_unquantize(a,b,c,d)
  32. #endif
  33. #define EDGE_WIDTH 16
  34. /* enable all paranoid tests for rounding, overflows, etc... */
  35. //#define PARANOID
  36. //#define DEBUG
  37. /* for jpeg fast DCT */
  38. #define CONST_BITS 14
  39. static const unsigned short aanscales[64] = {
  40. /* precomputed values scaled up by 14 bits */
  41. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  42. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  43. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  44. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  45. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  46. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  47. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  48. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  49. };
  50. static UINT8 h263_chroma_roundtab[16] = {
  51. 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
  52. };
  53. static void encode_picture(MpegEncContext *s, int picture_number);
  54. static void rate_control_init(MpegEncContext *s);
  55. static int rate_estimate_qscale(MpegEncContext *s);
  56. /* default motion estimation */
  57. int motion_estimation_method = ME_LOG;
  58. /* XXX: should use variable shift ? */
  59. #define QMAT_SHIFT_MMX 19
  60. #define QMAT_SHIFT 25
  61. static void convert_matrix(int *qmat, const UINT16 *quant_matrix, int qscale)
  62. {
  63. int i;
  64. if (av_fdct == jpeg_fdct_ifast) {
  65. for(i=0;i<64;i++) {
  66. /* 16 <= qscale * quant_matrix[i] <= 7905 */
  67. /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
  68. qmat[i] = (int)((1ULL << (QMAT_SHIFT + 11)) / (aanscales[i] * qscale * quant_matrix[i]));
  69. }
  70. } else {
  71. for(i=0;i<64;i++) {
  72. /* We can safely suppose that 16 <= quant_matrix[i] <= 255
  73. So 16 <= qscale * quant_matrix[i] <= 7905
  74. so (1 << QMAT_SHIFT) / 16 >= qmat[i] >= (1 << QMAT_SHIFT) / 7905
  75. */
  76. qmat[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
  77. }
  78. }
  79. }
  80. /* init common structure for both encoder and decoder */
  81. int MPV_common_init(MpegEncContext *s)
  82. {
  83. int c_size, i;
  84. UINT8 *pict;
  85. #if defined ( HAVE_MMX ) && defined ( BIN_PORTABILITY )
  86. MPV_common_init_mmx();
  87. #endif
  88. s->mb_width = (s->width + 15) / 16;
  89. s->mb_height = (s->height + 15) / 16;
  90. s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH;
  91. for(i=0;i<3;i++) {
  92. int w, h, shift, pict_start;
  93. w = s->linesize;
  94. h = s->mb_height * 16 + 2 * EDGE_WIDTH;
  95. shift = (i == 0) ? 0 : 1;
  96. c_size = (w >> shift) * (h >> shift);
  97. pict_start = (w >> shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift);
  98. pict = av_mallocz(c_size);
  99. if (pict == NULL)
  100. goto fail;
  101. s->last_picture_base[i] = pict;
  102. s->last_picture[i] = pict + pict_start;
  103. pict = av_mallocz(c_size);
  104. if (pict == NULL)
  105. goto fail;
  106. s->next_picture_base[i] = pict;
  107. s->next_picture[i] = pict + pict_start;
  108. if (s->has_b_frames) {
  109. pict = av_mallocz(c_size);
  110. if (pict == NULL)
  111. goto fail;
  112. s->aux_picture_base[i] = pict;
  113. s->aux_picture[i] = pict + pict_start;
  114. }
  115. }
  116. if (s->out_format == FMT_H263) {
  117. int size;
  118. /* MV prediction */
  119. size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
  120. s->motion_val = malloc(size * 2 * sizeof(INT16));
  121. if (s->motion_val == NULL)
  122. goto fail;
  123. memset(s->motion_val, 0, size * 2 * sizeof(INT16));
  124. }
  125. if (s->h263_pred) {
  126. int y_size, c_size, i, size;
  127. /* dc values */
  128. y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
  129. c_size = (s->mb_width + 2) * (s->mb_height + 2);
  130. size = y_size + 2 * c_size;
  131. s->dc_val[0] = malloc(size * sizeof(INT16));
  132. if (s->dc_val[0] == NULL)
  133. goto fail;
  134. s->dc_val[1] = s->dc_val[0] + y_size;
  135. s->dc_val[2] = s->dc_val[1] + c_size;
  136. for(i=0;i<size;i++)
  137. s->dc_val[0][i] = 1024;
  138. /* ac values */
  139. s->ac_val[0] = av_mallocz(size * sizeof(INT16) * 16);
  140. if (s->ac_val[0] == NULL)
  141. goto fail;
  142. s->ac_val[1] = s->ac_val[0] + y_size;
  143. s->ac_val[2] = s->ac_val[1] + c_size;
  144. /* cbp values */
  145. s->coded_block = av_mallocz(y_size);
  146. if (!s->coded_block)
  147. goto fail;
  148. }
  149. /* default structure is frame */
  150. s->picture_structure = PICT_FRAME;
  151. /* init default q matrix (only for mpeg and mjpeg) */
  152. for(i=0;i<64;i++) {
  153. s->intra_matrix[i] = default_intra_matrix[i];
  154. s->chroma_intra_matrix[i] = default_intra_matrix[i];
  155. s->non_intra_matrix[i] = default_non_intra_matrix[i];
  156. s->chroma_non_intra_matrix[i] = default_non_intra_matrix[i];
  157. }
  158. /* init macroblock skip table */
  159. if (!s->encoding) {
  160. s->mbskip_table = av_mallocz(s->mb_width * s->mb_height);
  161. if (!s->mbskip_table)
  162. goto fail;
  163. }
  164. s->context_initialized = 1;
  165. return 0;
  166. fail:
  167. if (s->motion_val)
  168. free(s->motion_val);
  169. if (s->dc_val[0])
  170. free(s->dc_val[0]);
  171. if (s->ac_val[0])
  172. free(s->ac_val[0]);
  173. if (s->coded_block)
  174. free(s->coded_block);
  175. if (s->mbskip_table)
  176. free(s->mbskip_table);
  177. for(i=0;i<3;i++) {
  178. if (s->last_picture_base[i])
  179. free(s->last_picture_base[i]);
  180. if (s->next_picture_base[i])
  181. free(s->next_picture_base[i]);
  182. if (s->aux_picture_base[i])
  183. free(s->aux_picture_base[i]);
  184. }
  185. return -1;
  186. }
  187. /* init common structure for both encoder and decoder */
  188. void MPV_common_end(MpegEncContext *s)
  189. {
  190. int i;
  191. if (s->motion_val)
  192. free(s->motion_val);
  193. if (s->h263_pred) {
  194. free(s->dc_val[0]);
  195. free(s->ac_val[0]);
  196. free(s->coded_block);
  197. }
  198. if (s->mbskip_table)
  199. free(s->mbskip_table);
  200. for(i=0;i<3;i++) {
  201. free(s->last_picture_base[i]);
  202. free(s->next_picture_base[i]);
  203. if (s->has_b_frames)
  204. free(s->aux_picture_base[i]);
  205. }
  206. s->context_initialized = 0;
  207. }
  208. /* init video encoder */
  209. int MPV_encode_init(AVCodecContext *avctx)
  210. {
  211. MpegEncContext *s = avctx->priv_data;
  212. s->bit_rate = avctx->bit_rate;
  213. s->frame_rate = avctx->frame_rate;
  214. s->width = avctx->width;
  215. s->height = avctx->height;
  216. s->gop_size = avctx->gop_size;
  217. if (s->gop_size <= 1) {
  218. s->intra_only = 1;
  219. s->gop_size = 12;
  220. } else {
  221. s->intra_only = 0;
  222. }
  223. s->full_search = motion_estimation_method;
  224. s->fixed_qscale = (avctx->flags & CODEC_FLAG_QSCALE);
  225. switch(avctx->codec->id) {
  226. case CODEC_ID_MPEG1VIDEO:
  227. s->out_format = FMT_MPEG1;
  228. break;
  229. case CODEC_ID_MJPEG:
  230. s->out_format = FMT_MJPEG;
  231. s->intra_only = 1; /* force intra only for jpeg */
  232. if (mjpeg_init(s) < 0)
  233. return -1;
  234. break;
  235. case CODEC_ID_H263:
  236. if (h263_get_picture_format(s->width, s->height) == 7)
  237. return -1;
  238. s->out_format = FMT_H263;
  239. break;
  240. case CODEC_ID_H263P:
  241. s->out_format = FMT_H263;
  242. s->h263_plus = 1;
  243. /* XXX: not unrectricted mv yet */
  244. break;
  245. case CODEC_ID_RV10:
  246. s->out_format = FMT_H263;
  247. s->h263_rv10 = 1;
  248. break;
  249. case CODEC_ID_OPENDIVX:
  250. s->out_format = FMT_H263;
  251. s->h263_pred = 1;
  252. s->unrestricted_mv = 1;
  253. break;
  254. case CODEC_ID_MSMPEG4:
  255. s->out_format = FMT_H263;
  256. s->h263_msmpeg4 = 1;
  257. s->h263_pred = 1;
  258. s->unrestricted_mv = 1;
  259. break;
  260. default:
  261. return -1;
  262. }
  263. if (s->out_format == FMT_H263)
  264. h263_encode_init_vlc(s);
  265. s->encoding = 1;
  266. /* init */
  267. if (MPV_common_init(s) < 0)
  268. return -1;
  269. /* rate control init */
  270. rate_control_init(s);
  271. s->picture_number = 0;
  272. s->fake_picture_number = 0;
  273. /* motion detector init */
  274. s->f_code = 1;
  275. return 0;
  276. }
  277. int MPV_encode_end(AVCodecContext *avctx)
  278. {
  279. MpegEncContext *s = avctx->priv_data;
  280. #ifdef STATS
  281. print_stats();
  282. #endif
  283. MPV_common_end(s);
  284. if (s->out_format == FMT_MJPEG)
  285. mjpeg_close(s);
  286. return 0;
  287. }
  288. /* draw the edges of width 'w' of an image of size width, height */
  289. static void draw_edges(UINT8 *buf, int wrap, int width, int height, int w)
  290. {
  291. UINT8 *ptr, *last_line;
  292. int i;
  293. last_line = buf + (height - 1) * wrap;
  294. for(i=0;i<w;i++) {
  295. /* top and bottom */
  296. memcpy(buf - (i + 1) * wrap, buf, width);
  297. memcpy(last_line + (i + 1) * wrap, last_line, width);
  298. }
  299. /* left and right */
  300. ptr = buf;
  301. for(i=0;i<height;i++) {
  302. memset(ptr - w, ptr[0], w);
  303. memset(ptr + width, ptr[width-1], w);
  304. ptr += wrap;
  305. }
  306. /* corners */
  307. for(i=0;i<w;i++) {
  308. memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
  309. memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
  310. memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
  311. memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
  312. }
  313. }
  314. /* generic function for encode/decode called before a frame is coded/decoded */
  315. #ifndef ARCH_X86
  316. void MPV_frame_start(MpegEncContext *s)
  317. {
  318. int i;
  319. UINT8 *tmp;
  320. if (s->pict_type == B_TYPE) {
  321. for(i=0;i<3;i++) {
  322. s->current_picture[i] = s->aux_picture[i];
  323. }
  324. } else {
  325. for(i=0;i<3;i++) {
  326. /* swap next and last */
  327. tmp = s->last_picture[i];
  328. s->last_picture[i] = s->next_picture[i];
  329. s->next_picture[i] = tmp;
  330. s->current_picture[i] = tmp;
  331. }
  332. }
  333. }
  334. #endif
  335. /* generic function for encode/decode called after a frame has been coded/decoded */
  336. void MPV_frame_end(MpegEncContext *s)
  337. {
  338. /* draw edge for correct motion prediction if outside */
  339. if (s->pict_type != B_TYPE) {
  340. draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH);
  341. draw_edges(s->current_picture[1], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2);
  342. draw_edges(s->current_picture[2], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2);
  343. }
  344. }
  345. int MPV_encode_picture(AVCodecContext *avctx,
  346. unsigned char *buf, int buf_size, void *data)
  347. {
  348. MpegEncContext *s = avctx->priv_data;
  349. AVPicture *pict = data;
  350. int i, j;
  351. if (s->fixed_qscale)
  352. s->qscale = avctx->quality;
  353. init_put_bits(&s->pb, buf, buf_size, NULL, NULL);
  354. if (!s->intra_only) {
  355. /* first picture of GOP is intra */
  356. if ((s->picture_number % s->gop_size) == 0)
  357. s->pict_type = I_TYPE;
  358. else
  359. s->pict_type = P_TYPE;
  360. } else {
  361. s->pict_type = I_TYPE;
  362. }
  363. avctx->key_frame = (s->pict_type == I_TYPE);
  364. MPV_frame_start(s);
  365. for(i=0;i<3;i++) {
  366. UINT8 *src = pict->data[i];
  367. UINT8 *dest = s->current_picture[i];
  368. int src_wrap = pict->linesize[i];
  369. int dest_wrap = s->linesize;
  370. int w = s->width;
  371. int h = s->height;
  372. if (i >= 1) {
  373. dest_wrap >>= 1;
  374. w >>= 1;
  375. h >>= 1;
  376. }
  377. for(j=0;j<h;j++) {
  378. memcpy(dest, src, w);
  379. dest += dest_wrap;
  380. src += src_wrap;
  381. }
  382. s->new_picture[i] = s->current_picture[i];
  383. }
  384. encode_picture(s, s->picture_number);
  385. MPV_frame_end(s);
  386. s->picture_number++;
  387. if (s->out_format == FMT_MJPEG)
  388. mjpeg_picture_trailer(s);
  389. flush_put_bits(&s->pb);
  390. s->total_bits += (s->pb.buf_ptr - s->pb.buf) * 8;
  391. avctx->quality = s->qscale;
  392. return s->pb.buf_ptr - s->pb.buf;
  393. }
  394. static inline int clip(int a, int amin, int amax)
  395. {
  396. if (a < amin)
  397. return amin;
  398. else if (a > amax)
  399. return amax;
  400. else
  401. return a;
  402. }
  403. static int dct_quantize(MpegEncContext *s, DCTELEM *block, int n, int qscale);
  404. static int dct_quantize_mmx(MpegEncContext *s,
  405. DCTELEM *block, int n,
  406. int qscale);
  407. static void dct_unquantize(MpegEncContext *s, DCTELEM *block, int n, int qscale);
  408. /* apply one mpeg motion vector to the three components */
  409. static inline void mpeg_motion(MpegEncContext *s,
  410. UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
  411. int dest_offset,
  412. UINT8 **ref_picture, int src_offset,
  413. int field_based, op_pixels_func *pix_op,
  414. int motion_x, int motion_y, int h)
  415. {
  416. UINT8 *ptr;
  417. int dxy, offset, mx, my, src_x, src_y, height, linesize;
  418. dxy = ((motion_y & 1) << 1) | (motion_x & 1);
  419. src_x = s->mb_x * 16 + (motion_x >> 1);
  420. src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1);
  421. /* WARNING: do no forget half pels */
  422. height = s->height >> field_based;
  423. src_x = clip(src_x, -16, s->width);
  424. if (src_x == s->width)
  425. dxy &= ~1;
  426. src_y = clip(src_y, -16, height);
  427. if (src_y == height)
  428. dxy &= ~2;
  429. linesize = s->linesize << field_based;
  430. ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset;
  431. dest_y += dest_offset;
  432. pix_op[dxy](dest_y, ptr, linesize, h);
  433. pix_op[dxy](dest_y + 8, ptr + 8, linesize, h);
  434. if (s->out_format == FMT_H263) {
  435. dxy = 0;
  436. if ((motion_x & 3) != 0)
  437. dxy |= 1;
  438. if ((motion_y & 3) != 0)
  439. dxy |= 2;
  440. mx = motion_x >> 2;
  441. my = motion_y >> 2;
  442. } else {
  443. mx = motion_x / 2;
  444. my = motion_y / 2;
  445. dxy = ((my & 1) << 1) | (mx & 1);
  446. mx >>= 1;
  447. my >>= 1;
  448. }
  449. src_x = s->mb_x * 8 + mx;
  450. src_y = s->mb_y * (8 >> field_based) + my;
  451. src_x = clip(src_x, -8, s->width >> 1);
  452. if (src_x == (s->width >> 1))
  453. dxy &= ~1;
  454. src_y = clip(src_y, -8, height >> 1);
  455. if (src_y == (height >> 1))
  456. dxy &= ~2;
  457. offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1);
  458. ptr = ref_picture[1] + offset;
  459. pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1);
  460. ptr = ref_picture[2] + offset;
  461. pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1);
  462. }
  463. static inline void MPV_motion(MpegEncContext *s,
  464. UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
  465. int dir, UINT8 **ref_picture,
  466. op_pixels_func *pix_op)
  467. {
  468. int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y;
  469. int mb_x, mb_y, i;
  470. UINT8 *ptr, *dest;
  471. mb_x = s->mb_x;
  472. mb_y = s->mb_y;
  473. switch(s->mv_type) {
  474. case MV_TYPE_16X16:
  475. mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
  476. ref_picture, 0,
  477. 0, pix_op,
  478. s->mv[dir][0][0], s->mv[dir][0][1], 16);
  479. break;
  480. case MV_TYPE_8X8:
  481. for(i=0;i<4;i++) {
  482. motion_x = s->mv[dir][i][0];
  483. motion_y = s->mv[dir][i][1];
  484. dxy = ((motion_y & 1) << 1) | (motion_x & 1);
  485. src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8;
  486. src_y = mb_y * 16 + (motion_y >> 1) + ((i >> 1) & 1) * 8;
  487. /* WARNING: do no forget half pels */
  488. src_x = clip(src_x, -16, s->width);
  489. if (src_x == s->width)
  490. dxy &= ~1;
  491. src_y = clip(src_y, -16, s->height);
  492. if (src_y == s->height)
  493. dxy &= ~2;
  494. ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
  495. dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
  496. pix_op[dxy](dest, ptr, s->linesize, 8);
  497. }
  498. /* In case of 8X8, we construct a single chroma motion vector
  499. with a special rounding */
  500. mx = 0;
  501. my = 0;
  502. for(i=0;i<4;i++) {
  503. mx += s->mv[dir][i][0];
  504. my += s->mv[dir][i][1];
  505. }
  506. if (mx >= 0)
  507. mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1));
  508. else {
  509. mx = -mx;
  510. mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1));
  511. }
  512. if (my >= 0)
  513. my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1));
  514. else {
  515. my = -my;
  516. my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1));
  517. }
  518. dxy = ((my & 1) << 1) | (mx & 1);
  519. mx >>= 1;
  520. my >>= 1;
  521. src_x = mb_x * 8 + mx;
  522. src_y = mb_y * 8 + my;
  523. src_x = clip(src_x, -8, s->width/2);
  524. if (src_x == s->width/2)
  525. dxy &= ~1;
  526. src_y = clip(src_y, -8, s->height/2);
  527. if (src_y == s->height/2)
  528. dxy &= ~2;
  529. offset = (src_y * (s->linesize >> 1)) + src_x;
  530. ptr = ref_picture[1] + offset;
  531. pix_op[dxy](dest_cb, ptr, s->linesize >> 1, 8);
  532. ptr = ref_picture[2] + offset;
  533. pix_op[dxy](dest_cr, ptr, s->linesize >> 1, 8);
  534. break;
  535. case MV_TYPE_FIELD:
  536. if (s->picture_structure == PICT_FRAME) {
  537. /* top field */
  538. mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
  539. ref_picture, s->field_select[dir][0] ? s->linesize : 0,
  540. 1, pix_op,
  541. s->mv[dir][0][0], s->mv[dir][0][1], 8);
  542. /* bottom field */
  543. mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize,
  544. ref_picture, s->field_select[dir][1] ? s->linesize : 0,
  545. 1, pix_op,
  546. s->mv[dir][1][0], s->mv[dir][1][1], 8);
  547. } else {
  548. }
  549. break;
  550. }
  551. }
  552. /* put block[] to dest[] */
  553. static inline void put_dct(MpegEncContext *s,
  554. DCTELEM *block, int i, UINT8 *dest, int line_size)
  555. {
  556. if (!s->mpeg2)
  557. DCT_UNQUANTIZE(s, block, i, s->qscale);
  558. j_rev_dct (block);
  559. put_pixels_clamped(block, dest, line_size);
  560. }
  561. /* add block[] to dest[] */
  562. static inline void add_dct(MpegEncContext *s,
  563. DCTELEM *block, int i, UINT8 *dest, int line_size)
  564. {
  565. if (s->block_last_index[i] >= 0) {
  566. if (!s->mpeg2)
  567. DCT_UNQUANTIZE(s, block, i, s->qscale);
  568. j_rev_dct (block);
  569. add_pixels_clamped(block, dest, line_size);
  570. }
  571. }
  572. /* generic function called after a macroblock has been parsed by the
  573. decoder or after it has been encoded by the encoder.
  574. Important variables used:
  575. s->mb_intra : true if intra macroblock
  576. s->mv_dir : motion vector direction
  577. s->mv_type : motion vector type
  578. s->mv : motion vector
  579. s->interlaced_dct : true if interlaced dct used (mpeg2)
  580. */
  581. void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
  582. {
  583. int mb_x, mb_y, motion_x, motion_y;
  584. int dct_linesize, dct_offset;
  585. op_pixels_func *op_pix;
  586. mb_x = s->mb_x;
  587. mb_y = s->mb_y;
  588. /* update DC predictors for P macroblocks */
  589. if (!s->mb_intra) {
  590. if (s->h263_pred) {
  591. int wrap, x, y, v;
  592. wrap = 2 * s->mb_width + 2;
  593. v = 1024;
  594. x = 2 * mb_x + 1;
  595. y = 2 * mb_y + 1;
  596. s->dc_val[0][(x) + (y) * wrap] = v;
  597. s->dc_val[0][(x + 1) + (y) * wrap] = v;
  598. s->dc_val[0][(x) + (y + 1) * wrap] = v;
  599. s->dc_val[0][(x + 1) + (y + 1) * wrap] = v;
  600. /* ac pred */
  601. memset(s->ac_val[0][(x) + (y) * wrap], 0, 16 * sizeof(INT16));
  602. memset(s->ac_val[0][(x + 1) + (y) * wrap], 0, 16 * sizeof(INT16));
  603. memset(s->ac_val[0][(x) + (y + 1) * wrap], 0, 16 * sizeof(INT16));
  604. memset(s->ac_val[0][(x + 1) + (y + 1) * wrap], 0, 16 * sizeof(INT16));
  605. if (s->h263_msmpeg4) {
  606. s->coded_block[(x) + (y) * wrap] = 0;
  607. s->coded_block[(x + 1) + (y) * wrap] = 0;
  608. s->coded_block[(x) + (y + 1) * wrap] = 0;
  609. s->coded_block[(x + 1) + (y + 1) * wrap] = 0;
  610. }
  611. /* chroma */
  612. wrap = s->mb_width + 2;
  613. x = mb_x + 1;
  614. y = mb_y + 1;
  615. s->dc_val[1][(x) + (y) * wrap] = v;
  616. s->dc_val[2][(x) + (y) * wrap] = v;
  617. /* ac pred */
  618. memset(s->ac_val[1][(x) + (y) * wrap], 0, 16 * sizeof(INT16));
  619. memset(s->ac_val[2][(x) + (y) * wrap], 0, 16 * sizeof(INT16));
  620. } else {
  621. s->last_dc[0] = 128 << s->intra_dc_precision;
  622. s->last_dc[1] = 128 << s->intra_dc_precision;
  623. s->last_dc[2] = 128 << s->intra_dc_precision;
  624. }
  625. }
  626. /* update motion predictor */
  627. if (s->out_format == FMT_H263) {
  628. int x, y, wrap;
  629. x = 2 * mb_x + 1;
  630. y = 2 * mb_y + 1;
  631. wrap = 2 * s->mb_width + 2;
  632. if (s->mb_intra) {
  633. motion_x = 0;
  634. motion_y = 0;
  635. goto motion_init;
  636. } else if (s->mv_type == MV_TYPE_16X16) {
  637. motion_x = s->mv[0][0][0];
  638. motion_y = s->mv[0][0][1];
  639. motion_init:
  640. /* no update if 8X8 because it has been done during parsing */
  641. s->motion_val[(x) + (y) * wrap][0] = motion_x;
  642. s->motion_val[(x) + (y) * wrap][1] = motion_y;
  643. s->motion_val[(x + 1) + (y) * wrap][0] = motion_x;
  644. s->motion_val[(x + 1) + (y) * wrap][1] = motion_y;
  645. s->motion_val[(x) + (y + 1) * wrap][0] = motion_x;
  646. s->motion_val[(x) + (y + 1) * wrap][1] = motion_y;
  647. s->motion_val[(x + 1) + (y + 1) * wrap][0] = motion_x;
  648. s->motion_val[(x + 1) + (y + 1) * wrap][1] = motion_y;
  649. }
  650. }
  651. if (!s->intra_only) {
  652. UINT8 *dest_y, *dest_cb, *dest_cr;
  653. UINT8 *mbskip_ptr;
  654. /* avoid copy if macroblock skipped in last frame too */
  655. if (!s->encoding) {
  656. mbskip_ptr = &s->mbskip_table[s->mb_y * s->mb_width + s->mb_x];
  657. if (s->mb_skiped) {
  658. s->mb_skiped = 0;
  659. /* if previous was skipped too, then nothing to do ! */
  660. if (*mbskip_ptr != 0)
  661. goto the_end;
  662. *mbskip_ptr = 1; /* indicate that this time we skiped it */
  663. } else {
  664. *mbskip_ptr = 0; /* not skipped */
  665. }
  666. }
  667. dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize) + mb_x * 16;
  668. dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8;
  669. dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8;
  670. if (s->interlaced_dct) {
  671. dct_linesize = s->linesize * 2;
  672. dct_offset = s->linesize;
  673. } else {
  674. dct_linesize = s->linesize;
  675. dct_offset = s->linesize * 8;
  676. }
  677. if (!s->mb_intra) {
  678. /* motion handling */
  679. if (!s->no_rounding)
  680. op_pix = put_pixels_tab;
  681. else
  682. op_pix = put_no_rnd_pixels_tab;
  683. if (s->mv_dir & MV_DIR_FORWARD) {
  684. MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix);
  685. if (!s->no_rounding)
  686. op_pix = avg_pixels_tab;
  687. else
  688. op_pix = avg_no_rnd_pixels_tab;
  689. }
  690. if (s->mv_dir & MV_DIR_BACKWARD) {
  691. MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix);
  692. }
  693. /* add dct residue */
  694. add_dct(s, block[0], 0, dest_y, dct_linesize);
  695. add_dct(s, block[1], 1, dest_y + 8, dct_linesize);
  696. add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
  697. add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize);
  698. add_dct(s, block[4], 4, dest_cb, dct_linesize >> 1);
  699. add_dct(s, block[5], 5, dest_cr, dct_linesize >> 1);
  700. } else {
  701. /* dct only in intra block */
  702. put_dct(s, block[0], 0, dest_y, dct_linesize);
  703. put_dct(s, block[1], 1, dest_y + 8, dct_linesize);
  704. put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
  705. put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize);
  706. put_dct(s, block[4], 4, dest_cb, dct_linesize >> 1);
  707. put_dct(s, block[5], 5, dest_cr, dct_linesize >> 1);
  708. }
  709. }
  710. the_end:
  711. emms_c();
  712. }
  713. static void encode_picture(MpegEncContext *s, int picture_number)
  714. {
  715. int mb_x, mb_y, wrap;
  716. UINT8 *ptr;
  717. DCTELEM block[6][64];
  718. int i, motion_x, motion_y;
  719. s->picture_number = picture_number;
  720. if (!s->fixed_qscale)
  721. s->qscale = rate_estimate_qscale(s);
  722. /* precompute matrix */
  723. if (s->out_format == FMT_MJPEG) {
  724. /* for mjpeg, we do include qscale in the matrix */
  725. s->intra_matrix[0] = default_intra_matrix[0];
  726. for(i=1;i<64;i++)
  727. s->intra_matrix[i] = (default_intra_matrix[i] * s->qscale) >> 3;
  728. convert_matrix(s->q_intra_matrix, s->intra_matrix, 8);
  729. } else {
  730. convert_matrix(s->q_intra_matrix, s->intra_matrix, s->qscale);
  731. convert_matrix(s->q_non_intra_matrix, s->non_intra_matrix, s->qscale);
  732. }
  733. switch(s->out_format) {
  734. case FMT_MJPEG:
  735. mjpeg_picture_header(s);
  736. break;
  737. case FMT_H263:
  738. if (s->h263_msmpeg4)
  739. msmpeg4_encode_picture_header(s, picture_number);
  740. else if (s->h263_pred)
  741. mpeg4_encode_picture_header(s, picture_number);
  742. else if (s->h263_rv10)
  743. rv10_encode_picture_header(s, picture_number);
  744. else
  745. h263_encode_picture_header(s, picture_number);
  746. break;
  747. case FMT_MPEG1:
  748. mpeg1_encode_picture_header(s, picture_number);
  749. break;
  750. }
  751. /* init last dc values */
  752. /* note: quant matrix value (8) is implied here */
  753. s->last_dc[0] = 128;
  754. s->last_dc[1] = 128;
  755. s->last_dc[2] = 128;
  756. s->mb_incr = 1;
  757. s->last_mv[0][0][0] = 0;
  758. s->last_mv[0][0][1] = 0;
  759. s->mv_type = MV_TYPE_16X16;
  760. s->mv_dir = MV_DIR_FORWARD;
  761. for(mb_y=0; mb_y < s->mb_height; mb_y++) {
  762. for(mb_x=0; mb_x < s->mb_width; mb_x++) {
  763. s->mb_x = mb_x;
  764. s->mb_y = mb_y;
  765. /* compute motion vector and macro block type (intra or non intra) */
  766. motion_x = 0;
  767. motion_y = 0;
  768. if (s->pict_type == P_TYPE) {
  769. s->mb_intra = estimate_motion(s, mb_x, mb_y,
  770. &motion_x,
  771. &motion_y);
  772. } else {
  773. s->mb_intra = 1;
  774. }
  775. /* get the pixels */
  776. wrap = s->linesize;
  777. ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16;
  778. get_pixels(block[0], ptr, wrap);
  779. get_pixels(block[1], ptr + 8, wrap);
  780. get_pixels(block[2], ptr + 8 * wrap, wrap);
  781. get_pixels(block[3], ptr + 8 * wrap + 8, wrap);
  782. wrap = s->linesize >> 1;
  783. ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8;
  784. get_pixels(block[4], ptr, wrap);
  785. wrap = s->linesize >> 1;
  786. ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8;
  787. get_pixels(block[5], ptr, wrap);
  788. /* subtract previous frame if non intra */
  789. if (!s->mb_intra) {
  790. int dxy, offset, mx, my;
  791. dxy = ((motion_y & 1) << 1) | (motion_x & 1);
  792. ptr = s->last_picture[0] +
  793. ((mb_y * 16 + (motion_y >> 1)) * s->linesize) +
  794. (mb_x * 16 + (motion_x >> 1));
  795. sub_pixels_2(block[0], ptr, s->linesize, dxy);
  796. sub_pixels_2(block[1], ptr + 8, s->linesize, dxy);
  797. sub_pixels_2(block[2], ptr + s->linesize * 8, s->linesize, dxy);
  798. sub_pixels_2(block[3], ptr + 8 + s->linesize * 8, s->linesize ,dxy);
  799. if (s->out_format == FMT_H263) {
  800. /* special rounding for h263 */
  801. dxy = 0;
  802. if ((motion_x & 3) != 0)
  803. dxy |= 1;
  804. if ((motion_y & 3) != 0)
  805. dxy |= 2;
  806. mx = motion_x >> 2;
  807. my = motion_y >> 2;
  808. } else {
  809. mx = motion_x / 2;
  810. my = motion_y / 2;
  811. dxy = ((my & 1) << 1) | (mx & 1);
  812. mx >>= 1;
  813. my >>= 1;
  814. }
  815. offset = ((mb_y * 8 + my) * (s->linesize >> 1)) + (mb_x * 8 + mx);
  816. ptr = s->last_picture[1] + offset;
  817. sub_pixels_2(block[4], ptr, s->linesize >> 1, dxy);
  818. ptr = s->last_picture[2] + offset;
  819. sub_pixels_2(block[5], ptr, s->linesize >> 1, dxy);
  820. }
  821. emms_c();
  822. /* DCT & quantize */
  823. if (s->h263_msmpeg4) {
  824. msmpeg4_dc_scale(s);
  825. } else if (s->h263_pred) {
  826. h263_dc_scale(s);
  827. } else {
  828. /* default quantization values */
  829. s->y_dc_scale = 8;
  830. s->c_dc_scale = 8;
  831. }
  832. for(i=0;i<6;i++) {
  833. int last_index;
  834. if (av_fdct == jpeg_fdct_ifast)
  835. last_index = dct_quantize(s, block[i], i, s->qscale);
  836. else
  837. last_index = dct_quantize_mmx(s, block[i], i, s->qscale);
  838. s->block_last_index[i] = last_index;
  839. }
  840. /* huffman encode */
  841. switch(s->out_format) {
  842. case FMT_MPEG1:
  843. mpeg1_encode_mb(s, block, motion_x, motion_y);
  844. break;
  845. case FMT_H263:
  846. if (s->h263_msmpeg4)
  847. msmpeg4_encode_mb(s, block, motion_x, motion_y);
  848. else
  849. h263_encode_mb(s, block, motion_x, motion_y);
  850. break;
  851. case FMT_MJPEG:
  852. mjpeg_encode_mb(s, block);
  853. break;
  854. }
  855. /* decompress blocks so that we keep the state of the decoder */
  856. s->mv[0][0][0] = motion_x;
  857. s->mv[0][0][1] = motion_y;
  858. MPV_decode_mb(s, block);
  859. }
  860. }
  861. }
  862. static int dct_quantize(MpegEncContext *s,
  863. DCTELEM *block, int n,
  864. int qscale)
  865. {
  866. int i, j, level, last_non_zero, q;
  867. const int *qmat;
  868. av_fdct (block);
  869. if (s->mb_intra) {
  870. if (n < 4)
  871. q = s->y_dc_scale;
  872. else
  873. q = s->c_dc_scale;
  874. q = q << 3;
  875. /* note: block[0] is assumed to be positive */
  876. block[0] = (block[0] + (q >> 1)) / q;
  877. i = 1;
  878. last_non_zero = 0;
  879. if (s->out_format == FMT_H263) {
  880. qmat = s->q_non_intra_matrix;
  881. } else {
  882. qmat = s->q_intra_matrix;
  883. }
  884. } else {
  885. i = 0;
  886. last_non_zero = -1;
  887. qmat = s->q_non_intra_matrix;
  888. }
  889. for(;i<64;i++) {
  890. j = zigzag_direct[i];
  891. level = block[j];
  892. level = level * qmat[j];
  893. #ifdef PARANOID
  894. {
  895. static int count = 0;
  896. int level1, level2, qmat1;
  897. double val;
  898. if (qmat == s->q_non_intra_matrix) {
  899. qmat1 = default_non_intra_matrix[j] * s->qscale;
  900. } else {
  901. qmat1 = default_intra_matrix[j] * s->qscale;
  902. }
  903. if (av_fdct != jpeg_fdct_ifast)
  904. val = ((double)block[j] * 8.0) / (double)qmat1;
  905. else
  906. val = ((double)block[j] * 8.0 * 2048.0) /
  907. ((double)qmat1 * aanscales[j]);
  908. level1 = (int)val;
  909. level2 = level / (1 << (QMAT_SHIFT - 3));
  910. if (level1 != level2) {
  911. fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n",
  912. count, level2, level1, block[j], qmat1, qmat[j],
  913. val);
  914. count++;
  915. }
  916. }
  917. #endif
  918. /* XXX: slight error for the low range. Test should be equivalent to
  919. (level <= -(1 << (QMAT_SHIFT - 3)) || level >= (1 <<
  920. (QMAT_SHIFT - 3)))
  921. */
  922. if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) !=
  923. level) {
  924. level = level / (1 << (QMAT_SHIFT - 3));
  925. /* XXX: currently, this code is not optimal. the range should be:
  926. mpeg1: -255..255
  927. mpeg2: -2048..2047
  928. h263: -128..127
  929. mpeg4: -2048..2047
  930. */
  931. if (level > 127)
  932. level = 127;
  933. else if (level < -128)
  934. level = -128;
  935. block[j] = level;
  936. last_non_zero = i;
  937. } else {
  938. block[j] = 0;
  939. }
  940. }
  941. return last_non_zero;
  942. }
  943. static int dct_quantize_mmx(MpegEncContext *s,
  944. DCTELEM *block, int n,
  945. int qscale)
  946. {
  947. int i, j, level, last_non_zero, q;
  948. const int *qmat;
  949. av_fdct (block);
  950. if (s->mb_intra) {
  951. if (n < 4)
  952. q = s->y_dc_scale;
  953. else
  954. q = s->c_dc_scale;
  955. /* note: block[0] is assumed to be positive */
  956. block[0] = (block[0] + (q >> 1)) / q;
  957. i = 1;
  958. last_non_zero = 0;
  959. if (s->out_format == FMT_H263) {
  960. qmat = s->q_non_intra_matrix;
  961. } else {
  962. qmat = s->q_intra_matrix;
  963. }
  964. } else {
  965. i = 0;
  966. last_non_zero = -1;
  967. qmat = s->q_non_intra_matrix;
  968. }
  969. for(;i<64;i++) {
  970. j = zigzag_direct[i];
  971. level = block[j];
  972. level = level * qmat[j];
  973. /* XXX: slight error for the low range. Test should be equivalent to
  974. (level <= -(1 << (QMAT_SHIFT_MMX - 3)) || level >= (1 <<
  975. (QMAT_SHIFT_MMX - 3)))
  976. */
  977. if (((level << (31 - (QMAT_SHIFT_MMX - 3))) >> (31 - (QMAT_SHIFT_MMX - 3))) !=
  978. level) {
  979. level = level / (1 << (QMAT_SHIFT_MMX - 3));
  980. /* XXX: currently, this code is not optimal. the range should be:
  981. mpeg1: -255..255
  982. mpeg2: -2048..2047
  983. h263: -128..127
  984. mpeg4: -2048..2047
  985. */
  986. if (level > 127)
  987. level = 127;
  988. else if (level < -128)
  989. level = -128;
  990. block[j] = level;
  991. last_non_zero = i;
  992. } else {
  993. block[j] = 0;
  994. }
  995. }
  996. return last_non_zero;
  997. }
  998. #ifndef HAVE_DCT_UNQUANTIZE
  999. static void dct_unquantize(MpegEncContext *s,
  1000. DCTELEM *block, int n, int qscale)
  1001. {
  1002. int i, level;
  1003. const UINT16 *quant_matrix;
  1004. if (s->mb_intra) {
  1005. if (n < 4)
  1006. block[0] = block[0] * s->y_dc_scale;
  1007. else
  1008. block[0] = block[0] * s->c_dc_scale;
  1009. if (s->out_format == FMT_H263) {
  1010. i = 1;
  1011. goto unquant_even;
  1012. }
  1013. /* XXX: only mpeg1 */
  1014. quant_matrix = s->intra_matrix;
  1015. for(i=1;i<64;i++) {
  1016. level = block[i];
  1017. if (level) {
  1018. if (level < 0) {
  1019. level = -level;
  1020. level = (int)(level * qscale * quant_matrix[i]) >> 3;
  1021. level = (level - 1) | 1;
  1022. level = -level;
  1023. } else {
  1024. level = (int)(level * qscale * quant_matrix[i]) >> 3;
  1025. level = (level - 1) | 1;
  1026. }
  1027. #ifdef PARANOID
  1028. if (level < -2048 || level > 2047)
  1029. fprintf(stderr, "unquant error %d %d\n", i, level);
  1030. #endif
  1031. block[i] = level;
  1032. }
  1033. }
  1034. } else {
  1035. i = 0;
  1036. unquant_even:
  1037. quant_matrix = s->non_intra_matrix;
  1038. for(;i<64;i++) {
  1039. level = block[i];
  1040. if (level) {
  1041. if (level < 0) {
  1042. level = -level;
  1043. level = (((level << 1) + 1) * qscale *
  1044. ((int) (quant_matrix[i]))) >> 4;
  1045. level = (level - 1) | 1;
  1046. level = -level;
  1047. } else {
  1048. level = (((level << 1) + 1) * qscale *
  1049. ((int) (quant_matrix[i]))) >> 4;
  1050. level = (level - 1) | 1;
  1051. }
  1052. #ifdef PARANOID
  1053. if (level < -2048 || level > 2047)
  1054. fprintf(stderr, "unquant error %d %d\n", i, level);
  1055. #endif
  1056. block[i] = level;
  1057. }
  1058. }
  1059. }
  1060. }
  1061. #endif
  1062. /* rate control */
  1063. /* an I frame is I_FRAME_SIZE_RATIO bigger than a P frame */
  1064. #define I_FRAME_SIZE_RATIO 3.0
  1065. #define QSCALE_K 20
  1066. static void rate_control_init(MpegEncContext *s)
  1067. {
  1068. s->wanted_bits = 0;
  1069. if (s->intra_only) {
  1070. s->I_frame_bits = ((INT64)s->bit_rate * FRAME_RATE_BASE) / s->frame_rate;
  1071. s->P_frame_bits = s->I_frame_bits;
  1072. } else {
  1073. s->P_frame_bits = (int) ((float)(s->gop_size * s->bit_rate) /
  1074. (float)((float)s->frame_rate / FRAME_RATE_BASE * (I_FRAME_SIZE_RATIO + s->gop_size - 1)));
  1075. s->I_frame_bits = (int)(s->P_frame_bits * I_FRAME_SIZE_RATIO);
  1076. }
  1077. #if defined(DEBUG)
  1078. printf("I_frame_size=%d P_frame_size=%d\n",
  1079. s->I_frame_bits, s->P_frame_bits);
  1080. #endif
  1081. }
  1082. /*
  1083. * This heuristic is rather poor, but at least we do not have to
  1084. * change the qscale at every macroblock.
  1085. */
  1086. static int rate_estimate_qscale(MpegEncContext *s)
  1087. {
  1088. long long total_bits = s->total_bits;
  1089. float q;
  1090. int qscale, diff, qmin;
  1091. if (s->pict_type == I_TYPE) {
  1092. s->wanted_bits += s->I_frame_bits;
  1093. } else {
  1094. s->wanted_bits += s->P_frame_bits;
  1095. }
  1096. diff = s->wanted_bits - total_bits;
  1097. q = 31.0 - (float)diff / (QSCALE_K * s->mb_height * s->mb_width);
  1098. /* adjust for I frame */
  1099. if (s->pict_type == I_TYPE && !s->intra_only) {
  1100. q /= I_FRAME_SIZE_RATIO;
  1101. }
  1102. /* using a too small Q scale leeds to problems in mpeg1 and h263
  1103. because AC coefficients are clamped to 255 or 127 */
  1104. qmin = 3;
  1105. if (q < qmin)
  1106. q = qmin;
  1107. else if (q > 31)
  1108. q = 31;
  1109. qscale = (int)(q + 0.5);
  1110. #if defined(DEBUG)
  1111. printf("%d: total=%Ld br=%0.1f diff=%d qest=%0.1f\n",
  1112. s->picture_number,
  1113. total_bits,
  1114. (float)s->frame_rate / FRAME_RATE_BASE *
  1115. total_bits / s->picture_number,
  1116. diff, q);
  1117. #endif
  1118. return qscale;
  1119. }
  1120. AVCodec mpeg1video_encoder = {
  1121. "mpeg1video",
  1122. CODEC_TYPE_VIDEO,
  1123. CODEC_ID_MPEG1VIDEO,
  1124. sizeof(MpegEncContext),
  1125. MPV_encode_init,
  1126. MPV_encode_picture,
  1127. MPV_encode_end,
  1128. };
  1129. AVCodec h263_encoder = {
  1130. "h263",
  1131. CODEC_TYPE_VIDEO,
  1132. CODEC_ID_H263,
  1133. sizeof(MpegEncContext),
  1134. MPV_encode_init,
  1135. MPV_encode_picture,
  1136. MPV_encode_end,
  1137. };
  1138. AVCodec h263p_encoder = {
  1139. "h263p",
  1140. CODEC_TYPE_VIDEO,
  1141. CODEC_ID_H263P,
  1142. sizeof(MpegEncContext),
  1143. MPV_encode_init,
  1144. MPV_encode_picture,
  1145. MPV_encode_end,
  1146. };
  1147. AVCodec rv10_encoder = {
  1148. "rv10",
  1149. CODEC_TYPE_VIDEO,
  1150. CODEC_ID_RV10,
  1151. sizeof(MpegEncContext),
  1152. MPV_encode_init,
  1153. MPV_encode_picture,
  1154. MPV_encode_end,
  1155. };
  1156. AVCodec mjpeg_encoder = {
  1157. "mjpeg",
  1158. CODEC_TYPE_VIDEO,
  1159. CODEC_ID_MJPEG,
  1160. sizeof(MpegEncContext),
  1161. MPV_encode_init,
  1162. MPV_encode_picture,
  1163. MPV_encode_end,
  1164. };
  1165. AVCodec opendivx_encoder = {
  1166. "opendivx",
  1167. CODEC_TYPE_VIDEO,
  1168. CODEC_ID_OPENDIVX,
  1169. sizeof(MpegEncContext),
  1170. MPV_encode_init,
  1171. MPV_encode_picture,
  1172. MPV_encode_end,
  1173. };
  1174. AVCodec msmpeg4_encoder = {
  1175. "msmpeg4",
  1176. CODEC_TYPE_VIDEO,
  1177. CODEC_ID_MSMPEG4,
  1178. sizeof(MpegEncContext),
  1179. MPV_encode_init,
  1180. MPV_encode_picture,
  1181. MPV_encode_end,
  1182. };