Originally committed as revision 398 to svn://svn.ffmpeg.org/ffmpeg/trunk
Juanjo authored on 2002/04/15 03:57:51... | ... |
@@ -86,7 +86,7 @@ echo " --cpu=CPU force cpu to CPU [$cpu]" |
86 | 86 |
echo " --disable-mmx disable mmx usage" |
87 | 87 |
echo " --enable-gprof enable profiling with gprof [$gprof]" |
88 | 88 |
echo " --disable-grab disable audio/video grabbing code" |
89 |
-echo " --enable-simple_idct use simple IDCT routines" |
|
89 |
+echo " --enable-simple_idct use simple IDCT routines" |
|
90 | 90 |
echo " --enable-mp3lame enable mp3 encoding via libmp3lame" |
91 | 91 |
echo " --enable-win32 enable win32 cross compile" |
92 | 92 |
echo " --enable-shared build shared libraries [default=no]" |
... | ... |
@@ -82,9 +82,11 @@ static int video_qmax = 15; |
82 | 82 |
static int video_qdiff = 3; |
83 | 83 |
static float video_qblur = 0.5; |
84 | 84 |
static float video_qcomp = 0.5; |
85 |
+static int motion_estimation_method = 0; |
|
85 | 86 |
static int video_disable = 0; |
86 | 87 |
static int video_codec_id = CODEC_ID_NONE; |
87 | 88 |
static int same_quality = 0; |
89 |
+static int use_hq = 0; |
|
88 | 90 |
static int use_4mv = 0; |
89 | 91 |
static int do_deinterlace = 0; |
90 | 92 |
|
... | ... |
@@ -1386,7 +1388,7 @@ void opt_motion_estimation(const char *arg) |
1386 | 1386 |
break; |
1387 | 1387 |
p++; |
1388 | 1388 |
} |
1389 |
- motion_estimation_method = p - motion_str; |
|
1389 |
+ motion_estimation_method = (p - motion_str) - 4; |
|
1390 | 1390 |
} |
1391 | 1391 |
|
1392 | 1392 |
void opt_video_codec(const char *arg) |
... | ... |
@@ -1763,6 +1765,10 @@ void opt_output_file(const char *filename) |
1763 | 1763 |
video_enc->quality = video_qscale; |
1764 | 1764 |
} |
1765 | 1765 |
|
1766 |
+ if (use_hq) { |
|
1767 |
+ video_enc->flags |= CODEC_FLAG_HQ; |
|
1768 |
+ } |
|
1769 |
+ |
|
1766 | 1770 |
if (use_4mv) { |
1767 | 1771 |
video_enc->flags |= CODEC_FLAG_HQ; |
1768 | 1772 |
video_enc->flags |= CODEC_FLAG_4MV; |
... | ... |
@@ -1777,6 +1783,9 @@ void opt_output_file(const char *filename) |
1777 | 1777 |
video_enc->get_psnr = 1; |
1778 | 1778 |
else |
1779 | 1779 |
video_enc->get_psnr = 0; |
1780 |
+ |
|
1781 |
+ video_enc->me_method = motion_estimation_method; |
|
1782 |
+ |
|
1780 | 1783 |
/* XXX: need to find a way to set codec parameters */ |
1781 | 1784 |
if (oc->format == &ppm_format || |
1782 | 1785 |
oc->format == &ppmpipe_format) { |
... | ... |
@@ -2029,11 +2038,11 @@ void show_formats(void) |
2029 | 2029 |
pp = motion_str; |
2030 | 2030 |
while (*pp) { |
2031 | 2031 |
printf(" %s", *pp); |
2032 |
- if ((pp - motion_str) == ME_ZERO) |
|
2032 |
+ if ((pp - motion_str - 4) == ME_ZERO) |
|
2033 | 2033 |
printf("(fastest)"); |
2034 |
- else if ((pp - motion_str) == ME_FULL) |
|
2034 |
+ else if ((pp - motion_str - 4) == ME_FULL) |
|
2035 | 2035 |
printf("(slowest)"); |
2036 |
- else if ((pp - motion_str) == ME_LOG) |
|
2036 |
+ else if ((pp - motion_str - 4) == ME_EPZS) |
|
2037 | 2037 |
printf("(default)"); |
2038 | 2038 |
pp++; |
2039 | 2039 |
} |
... | ... |
@@ -2115,6 +2124,7 @@ const OptionDef options[] = { |
2115 | 2115 |
{ "vcodec", HAS_ARG | OPT_EXPERT, {(void*)opt_video_codec}, "force video codec", "codec" }, |
2116 | 2116 |
{ "me", HAS_ARG | OPT_EXPERT, {(void*)opt_motion_estimation}, "set motion estimation method", |
2117 | 2117 |
"method" }, |
2118 |
+ { "hq", OPT_BOOL | OPT_EXPERT, {(void*)&use_hq}, "activate high quality settings" }, |
|
2118 | 2119 |
{ "4mv", OPT_BOOL | OPT_EXPERT, {(void*)&use_4mv}, "use four motion vector by macroblock (only MPEG-4)" }, |
2119 | 2120 |
{ "sameq", OPT_BOOL, {(void*)&same_quality}, |
2120 | 2121 |
"use same video quality as source (implies VBR)" }, |
... | ... |
@@ -56,14 +56,18 @@ enum SampleFormat { |
56 | 56 |
/* in bytes */ |
57 | 57 |
#define AVCODEC_MAX_AUDIO_FRAME_SIZE 18432 |
58 | 58 |
|
59 |
-/* motion estimation type */ |
|
60 |
-extern int motion_estimation_method; |
|
61 |
-#define ME_ZERO 0 |
|
62 |
-#define ME_FULL 1 |
|
63 |
-#define ME_LOG 2 |
|
64 |
-#define ME_PHODS 3 |
|
65 |
-#define ME_EPZS 4 |
|
66 |
-#define ME_X1 5 |
|
59 |
+/* motion estimation type, EPZS by default */ |
|
60 |
+enum Motion_Est_ID { |
|
61 |
+ ME_ZERO = -4, |
|
62 |
+ ME_FULL, |
|
63 |
+ ME_LOG, |
|
64 |
+ ME_PHODS, |
|
65 |
+ ME_EPZS, |
|
66 |
+ ME_X1 |
|
67 |
+}; |
|
68 |
+ |
|
69 |
+/* ME algos sorted by quality */ |
|
70 |
+static const int Motion_Est_QTab[] = { -4, -1, -2, 1, 0, -3 }; |
|
67 | 71 |
|
68 | 72 |
/* encoding support */ |
69 | 73 |
/* note not everything is supported yet */ |
... | ... |
@@ -89,6 +93,9 @@ typedef struct AVCodecContext { |
89 | 89 |
int flags; |
90 | 90 |
int sub_id; /* some codecs needs additionnal format info. It is |
91 | 91 |
stored there */ |
92 |
+ |
|
93 |
+ int me_method; /* ME algorithm used for video coding */ |
|
94 |
+ |
|
92 | 95 |
/* video only */ |
93 | 96 |
int frame_rate; /* frames per sec multiplied by FRAME_RATE_BASE */ |
94 | 97 |
int width, height; |
... | ... |
@@ -89,6 +89,8 @@ UINT8 ff_alternate_vertical_scan[64] = { |
89 | 89 |
38, 46, 54, 62, 39, 47, 55, 63, |
90 | 90 |
}; |
91 | 91 |
|
92 |
+#ifdef SIMPLE_IDCT |
|
93 |
+ |
|
92 | 94 |
/* Input permutation for the simple_idct_mmx */ |
93 | 95 |
static UINT8 simple_mmx_permutation[64]={ |
94 | 96 |
0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, |
... | ... |
@@ -100,6 +102,7 @@ static UINT8 simple_mmx_permutation[64]={ |
100 | 100 |
0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, |
101 | 101 |
0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, |
102 | 102 |
}; |
103 |
+#endif |
|
103 | 104 |
|
104 | 105 |
/* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */ |
105 | 106 |
UINT32 inverse[256]={ |
... | ... |
@@ -594,7 +594,7 @@ static int epzs_motion_search(MpegEncContext * s, |
594 | 594 |
CHECK_MV(P[0][0]>>shift, P[0][1]>>shift) |
595 | 595 |
|
596 | 596 |
//check(best[0],best[1],0, b0) |
597 |
- if(s->full_search==ME_EPZS) |
|
597 |
+ if(s->me_method==ME_EPZS) |
|
598 | 598 |
dmin= small_diamond_search(s, best, dmin, new_pic, old_pic, pic_stride, |
599 | 599 |
pred_x, pred_y, mv_penalty, quant, xmin, ymin, xmax, ymax, shift); |
600 | 600 |
else |
... | ... |
@@ -825,7 +825,7 @@ void estimate_motion(MpegEncContext * s, |
825 | 825 |
int P[6][2]; |
826 | 826 |
const int shift= 1+s->quarter_sample; |
827 | 827 |
int mb_type=0; |
828 |
- |
|
828 |
+ //static int skip=0; |
|
829 | 829 |
range = 8 * (1 << (s->f_code - 1)); |
830 | 830 |
/* XXX: temporary kludge to avoid overflow for msmpeg4 */ |
831 | 831 |
if (s->out_format == FMT_H263 && !s->h263_msmpeg4) |
... | ... |
@@ -851,7 +851,7 @@ void estimate_motion(MpegEncContext * s, |
851 | 851 |
xmax = s->mb_width*16 - 16; |
852 | 852 |
ymax = s->mb_height*16 - 16; |
853 | 853 |
} |
854 |
- switch(s->full_search) { |
|
854 |
+ switch(s->me_method) { |
|
855 | 855 |
case ME_ZERO: |
856 | 856 |
default: |
857 | 857 |
no_motion_search(s, &mx, &my); |
... | ... |
@@ -999,6 +999,7 @@ void estimate_motion(MpegEncContext * s, |
999 | 999 |
s->avg_mb_var+= varc; |
1000 | 1000 |
s->mc_mb_var += vard; |
1001 | 1001 |
|
1002 |
+ |
|
1002 | 1003 |
#if 0 |
1003 | 1004 |
printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n", |
1004 | 1005 |
varc, s->avg_mb_var, sum, vard, mx - xx, my - yy); |
... | ... |
@@ -1016,12 +1017,19 @@ void estimate_motion(MpegEncContext * s, |
1016 | 1016 |
}else{ |
1017 | 1017 |
if (vard <= 64 || vard < varc) { |
1018 | 1018 |
mb_type|= MB_TYPE_INTER; |
1019 |
- if (s->full_search != ME_ZERO) { |
|
1019 |
+ if (s->me_method != ME_ZERO) { |
|
1020 | 1020 |
halfpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax, pred_x, pred_y); |
1021 | 1021 |
} else { |
1022 | 1022 |
mx -= 16 * mb_x; |
1023 | 1023 |
my -= 16 * mb_y; |
1024 | 1024 |
} |
1025 |
+#if 0 |
|
1026 |
+ if (vard < 10) { |
|
1027 |
+ skip++; |
|
1028 |
+ fprintf(stderr,"\nEarly skip: %d vard: %2d varc: %5d dmin: %d", |
|
1029 |
+ skip, vard, varc, dmin); |
|
1030 |
+ } |
|
1031 |
+#endif |
|
1025 | 1032 |
}else{ |
1026 | 1033 |
mb_type|= MB_TYPE_INTRA; |
1027 | 1034 |
mx = 0;//mx*2 - 32 * mb_x; |
... | ... |
@@ -313,8 +313,10 @@ int MPV_encode_init(AVCodecContext *avctx) |
313 | 313 |
} else { |
314 | 314 |
s->intra_only = 0; |
315 | 315 |
} |
316 |
- s->full_search = motion_estimation_method; |
|
317 |
- |
|
316 |
+ |
|
317 |
+ /* ME algorithm */ |
|
318 |
+ s->me_method = avctx->me_method; |
|
319 |
+ /* Fixed QSCALE */ |
|
318 | 320 |
s->fixed_qscale = (avctx->flags & CODEC_FLAG_QSCALE); |
319 | 321 |
|
320 | 322 |
switch(avctx->codec->id) { |
... | ... |
@@ -413,7 +415,7 @@ int MPV_encode_init(AVCodecContext *avctx) |
413 | 413 |
mpeg1_encode_init(s); |
414 | 414 |
|
415 | 415 |
/* dont use mv_penalty table for crap MV as it would be confused */ |
416 |
- if(s->full_search<4) s->mv_penalty= default_mv_penalty; |
|
416 |
+ if (s->me_method < 0) s->mv_penalty = default_mv_penalty; |
|
417 | 417 |
|
418 | 418 |
s->encoding = 1; |
419 | 419 |
|
... | ... |
@@ -1344,7 +1346,7 @@ static void encode_picture(MpegEncContext *s, int picture_number) |
1344 | 1344 |
} |
1345 | 1345 |
|
1346 | 1346 |
/* find best f_code for ME which do unlimited searches */ |
1347 |
- if(s->pict_type==P_TYPE && s->full_search>3){ |
|
1347 |
+ if(s->pict_type == P_TYPE && s->me_method >= 0){ |
|
1348 | 1348 |
int mv_num[8]; |
1349 | 1349 |
int i; |
1350 | 1350 |
int loose=0; |
... | ... |
@@ -113,7 +113,7 @@ typedef struct MpegEncContext { |
113 | 113 |
int b_code; /* backward resolution for B Frames (mpeg4) */ |
114 | 114 |
INT16 *mv_table[2]; /* MV table (1MV per MB)*/ |
115 | 115 |
INT16 (*motion_val)[2]; /* used for MV prediction (4MV per MB)*/ |
116 |
- int full_search; |
|
116 |
+ int me_method; /* ME algorithm */ |
|
117 | 117 |
int mv_dir; |
118 | 118 |
#define MV_DIR_BACKWARD 1 |
119 | 119 |
#define MV_DIR_FORWARD 2 |