mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
add MPEG-2 intra vlc support
Originally committed as revision 5372 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
d634aa2095
commit
307eb24879
@ -341,6 +341,7 @@ extern int motion_estimation_method;
|
||||
#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
|
||||
#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
|
||||
#define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization
|
||||
#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< use MPEG-2 intra VLC table
|
||||
|
||||
/* Unsupported options :
|
||||
* Syntax Arithmetic coding (SAC)
|
||||
|
@ -95,6 +95,7 @@ static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL;
|
||||
static uint8_t fcode_tab[MAX_MV*2+1];
|
||||
|
||||
static uint8_t uni_mpeg1_ac_vlc_len [64*64*2];
|
||||
static uint8_t uni_mpeg2_ac_vlc_len [64*64*2];
|
||||
|
||||
/* simple include everything table for dc, first byte is bits number next 3 are code*/
|
||||
static uint32_t mpeg1_lum_dc_uni[512];
|
||||
@ -166,11 +167,11 @@ static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){
|
||||
|
||||
if (code < 111 /* rl->n */) {
|
||||
/* store the vlc & sign at once */
|
||||
len= mpeg1_vlc[code][1]+1;
|
||||
bits= (mpeg1_vlc[code][0]<<1) + sign;
|
||||
len= rl->table_vlc[code][1]+1;
|
||||
bits= (rl->table_vlc[code][0]<<1) + sign;
|
||||
} else {
|
||||
len= mpeg1_vlc[111/*rl->n*/][1]+6;
|
||||
bits= mpeg1_vlc[111/*rl->n*/][0]<<6;
|
||||
len= rl->table_vlc[111/*rl->n*/][1]+6;
|
||||
bits= rl->table_vlc[111/*rl->n*/][0]<<6;
|
||||
|
||||
bits|= run;
|
||||
if (alevel < 128) {
|
||||
@ -766,6 +767,8 @@ void ff_mpeg1_encode_init(MpegEncContext *s)
|
||||
|
||||
done=1;
|
||||
init_rl(&rl_mpeg1, 1);
|
||||
if(s->intra_vlc_format)
|
||||
init_rl(&rl_mpeg2, 1);
|
||||
|
||||
for(i=0; i<64; i++)
|
||||
{
|
||||
@ -774,6 +777,8 @@ void ff_mpeg1_encode_init(MpegEncContext *s)
|
||||
}
|
||||
|
||||
init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_len);
|
||||
if(s->intra_vlc_format)
|
||||
init_uni_ac_vlc(&rl_mpeg2, uni_mpeg2_ac_vlc_len);
|
||||
|
||||
/* build unified dc encoding tables */
|
||||
for(i=-255; i<256; i++)
|
||||
@ -840,9 +845,14 @@ void ff_mpeg1_encode_init(MpegEncContext *s)
|
||||
s->min_qcoeff=-2047;
|
||||
s->max_qcoeff= 2047;
|
||||
}
|
||||
if (s->intra_vlc_format) {
|
||||
s->intra_ac_vlc_length=
|
||||
s->intra_ac_vlc_last_length= uni_mpeg2_ac_vlc_len;
|
||||
} else {
|
||||
s->intra_ac_vlc_length=
|
||||
s->intra_ac_vlc_last_length= uni_mpeg1_ac_vlc_len;
|
||||
}
|
||||
s->inter_ac_vlc_length=
|
||||
s->intra_ac_vlc_last_length=
|
||||
s->inter_ac_vlc_last_length= uni_mpeg1_ac_vlc_len;
|
||||
}
|
||||
|
||||
@ -889,7 +899,7 @@ static void mpeg1_encode_block(MpegEncContext *s,
|
||||
{
|
||||
int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
|
||||
int code, component;
|
||||
// RLTable *rl = &rl_mpeg1;
|
||||
const uint16_t (*table_vlc)[2] = rl_mpeg1.table_vlc;
|
||||
|
||||
last_index = s->block_last_index[n];
|
||||
|
||||
@ -901,12 +911,8 @@ static void mpeg1_encode_block(MpegEncContext *s,
|
||||
encode_dc(s, diff, component);
|
||||
s->last_dc[component] = dc;
|
||||
i = 1;
|
||||
/*
|
||||
if (s->intra_vlc_format)
|
||||
rl = &rl_mpeg2;
|
||||
else
|
||||
rl = &rl_mpeg1;
|
||||
*/
|
||||
table_vlc = rl_mpeg2.table_vlc;
|
||||
} else {
|
||||
/* encode the first coefficient : needs to be done here because
|
||||
it is handled slightly differently */
|
||||
@ -941,14 +947,13 @@ static void mpeg1_encode_block(MpegEncContext *s,
|
||||
MASK_ABS(sign, alevel)
|
||||
sign&=1;
|
||||
|
||||
// code = get_rl_index(rl, 0, run, alevel);
|
||||
if (alevel <= mpeg1_max_level[0][run]){
|
||||
code= mpeg1_index_run[0][run] + alevel - 1;
|
||||
/* store the vlc & sign at once */
|
||||
put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign);
|
||||
put_bits(&s->pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign);
|
||||
} else {
|
||||
/* escape seems to be pretty rare <5% so i dont optimize it */
|
||||
put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]);
|
||||
put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]);
|
||||
/* escape: only clip in this case */
|
||||
put_bits(&s->pb, 6, run);
|
||||
if(s->codec_id == CODEC_ID_MPEG1VIDEO){
|
||||
@ -969,7 +974,7 @@ static void mpeg1_encode_block(MpegEncContext *s,
|
||||
}
|
||||
}
|
||||
/* end of block */
|
||||
put_bits(&s->pb, 2, 0x2);
|
||||
put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]);
|
||||
}
|
||||
#endif //CONFIG_ENCODERS
|
||||
|
||||
|
@ -991,6 +991,7 @@ int MPV_encode_init(AVCodecContext *avctx)
|
||||
s->obmc= !!(s->flags & CODEC_FLAG_OBMC);
|
||||
s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
|
||||
s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
|
||||
s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
|
||||
|
||||
if(avctx->rc_max_rate && !avctx->rc_buffer_size){
|
||||
av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
|
||||
@ -1075,6 +1076,11 @@ int MPV_encode_init(AVCodecContext *avctx)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){
|
||||
av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
|
||||
&& s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
|
||||
&& (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
|
||||
|
@ -740,6 +740,7 @@ static AVOption options[]={
|
||||
{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
|
||||
{"sc_factor", NULL, OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E},
|
||||
{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E},
|
||||
{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
|
@ -7,6 +7,10 @@ a60d3fb60982786b9761a07c24664e9c *./data/a-mpeg2.mpg
|
||||
747312 ./data/a-mpeg2.mpg
|
||||
f5b8b9c2a5e162b6c01d6b299d03b117 *./data/out.yuv
|
||||
stddev: 7.69 PSNR:30.39 bytes:7602176
|
||||
218ef56c1909d66e77c87cd98c9868e8 *./data/a-mpeg2ivlc.mpg
|
||||
737935 ./data/a-mpeg2ivlc.mpg
|
||||
f5b8b9c2a5e162b6c01d6b299d03b117 *./data/out.yuv
|
||||
stddev: 7.69 PSNR:30.39 bytes:7602176
|
||||
a34af358ee5b5dab19d37ee29f1927b2 *./data/a-mpeg2.mpg
|
||||
748099 ./data/a-mpeg2.mpg
|
||||
555f76a5df78088411b83f5faf334762 *./data/out.yuv
|
||||
@ -19,6 +23,10 @@ stddev: 7.69 PSNR:30.39 bytes:7602176
|
||||
820348 ./data/a-mpeg2thread.mpg
|
||||
6b820ffc74de50cc863b41d51f72c22b *./data/out.yuv
|
||||
stddev: 7.64 PSNR:30.45 bytes:7602176
|
||||
a88c3fc28a6e62351c1b71235e7916a7 *./data/a-mpeg2threadivlc.mpg
|
||||
810646 ./data/a-mpeg2threadivlc.mpg
|
||||
6b820ffc74de50cc863b41d51f72c22b *./data/out.yuv
|
||||
stddev: 7.64 PSNR:30.45 bytes:7602176
|
||||
edb3e58ea66de2e9b32713daf9b5c3f1 *./data/a-mpeg2reuse.mpg
|
||||
2119706 ./data/a-mpeg2reuse.mpg
|
||||
1dab2eaca5320fe01afbe9596b2bd6cc *./data/out.yuv
|
||||
|
@ -179,6 +179,13 @@ do_ffmpeg $file -y -qscale 10 -f pgmyuv -i $raw_src -vcodec mpeg2video -f mpeg1v
|
||||
# mpeg2 decoding
|
||||
do_ffmpeg $raw_dst -y -i $file -f rawvideo $raw_dst
|
||||
|
||||
# mpeg2 encoding using intra vlc
|
||||
file=${outfile}mpeg2ivlc.mpg
|
||||
do_ffmpeg $file -y -qscale 10 -f pgmyuv -i $raw_src -vcodec mpeg2video -f mpeg1video -flags2 +ivlc $file
|
||||
|
||||
# mpeg2 decoding
|
||||
do_ffmpeg $raw_dst -y -i $file -f rawvideo $raw_dst
|
||||
|
||||
# mpeg2 encoding
|
||||
file=${outfile}mpeg2.mpg
|
||||
do_ffmpeg $file -y -qscale 10 -f pgmyuv -i $raw_src -vcodec mpeg2video -idct int -dct int -f mpeg1video $file
|
||||
@ -203,6 +210,13 @@ do_ffmpeg $file -y -qscale 10 -f pgmyuv -i $raw_src -vcodec mpeg2video -f mpeg1v
|
||||
# mpeg2 decoding
|
||||
do_ffmpeg $raw_dst -y -i $file -f rawvideo $raw_dst
|
||||
|
||||
# mpeg2 encoding interlaced using intra vlc
|
||||
file=${outfile}mpeg2threadivlc.mpg
|
||||
do_ffmpeg $file -y -qscale 10 -f pgmyuv -i $raw_src -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2 $file
|
||||
|
||||
# mpeg2 decoding
|
||||
do_ffmpeg $raw_dst -y -i $file -f rawvideo $raw_dst
|
||||
|
||||
# mpeg2 encoding interlaced
|
||||
file=${outfile}mpeg2reuse.mpg
|
||||
do_ffmpeg $file -y -sameq -me_threshold 256 -mb_threshold 1024 -i ${outfile}mpeg2thread.mpg -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4 $file
|
||||
|
@ -7,6 +7,10 @@ f0310ea9b9a4f37c1a4dd0d4985a3f81 *./data/a-mpeg2.mpg
|
||||
199396 ./data/a-mpeg2.mpg
|
||||
94581e9516461557b194aeefaaba3835 *./data/out.yuv
|
||||
stddev: 4.97 PSNR:34.18 bytes:7602176
|
||||
356a07f0872b371acb2eebd9b0225786 *./data/a-mpeg2ivlc.mpg
|
||||
198603 ./data/a-mpeg2ivlc.mpg
|
||||
94581e9516461557b194aeefaaba3835 *./data/out.yuv
|
||||
stddev: 4.97 PSNR:34.18 bytes:7602176
|
||||
374bd257b96328935926b350b0c5cada *./data/a-mpeg2.mpg
|
||||
198338 ./data/a-mpeg2.mpg
|
||||
f464b420ae24c1e453df8d3e5ef9140d *./data/out.yuv
|
||||
@ -19,6 +23,10 @@ stddev: 4.98 PSNR:34.16 bytes:7602176
|
||||
183955 ./data/a-mpeg2thread.mpg
|
||||
38441603e2201ddb01632ba3411a6bb8 *./data/out.yuv
|
||||
stddev: 4.76 PSNR:34.56 bytes:7602176
|
||||
0c414c53b9418e6566680ed1d85d5a3b *./data/a-mpeg2threadivlc.mpg
|
||||
183095 ./data/a-mpeg2threadivlc.mpg
|
||||
38441603e2201ddb01632ba3411a6bb8 *./data/out.yuv
|
||||
stddev: 4.76 PSNR:34.56 bytes:7602176
|
||||
c9f6617461caee57ccb6d438761527c8 *./data/a-mpeg2reuse.mpg
|
||||
396729 ./data/a-mpeg2reuse.mpg
|
||||
b10aec71132301cad001070e8ad46b7d *./data/out.yuv
|
||||
|
Loading…
Reference in New Issue
Block a user