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.

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