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.

1282 lines
39KB

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