Commit bf266e19 authored by Michael Niedermayer's avatar Michael Niedermayer

intra_dc_precission>0 encoding support

Originally committed as revision 3093 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 26d4f26b
...@@ -164,6 +164,7 @@ static int debug = 0; ...@@ -164,6 +164,7 @@ static int debug = 0;
static int debug_mv = 0; static int debug_mv = 0;
static int me_threshold = 0; static int me_threshold = 0;
static int mb_threshold = 0; static int mb_threshold = 0;
static int intra_dc_precision = 0;
extern int loop_input; /* currently a hack */ extern int loop_input; /* currently a hack */
static int gop_size = 12; static int gop_size = 12;
...@@ -2893,6 +2894,7 @@ static void opt_output_file(const char *filename) ...@@ -2893,6 +2894,7 @@ static void opt_output_file(const char *filename)
video_enc->idct_algo = idct_algo; video_enc->idct_algo = idct_algo;
video_enc->me_threshold= me_threshold; video_enc->me_threshold= me_threshold;
video_enc->mb_threshold= mb_threshold; video_enc->mb_threshold= mb_threshold;
video_enc->intra_dc_precision= intra_dc_precision;
video_enc->strict_std_compliance = strict; video_enc->strict_std_compliance = strict;
video_enc->error_rate = error_rate; video_enc->error_rate = error_rate;
video_enc->noise_reduction= noise_reduction; video_enc->noise_reduction= noise_reduction;
...@@ -3580,6 +3582,7 @@ const OptionDef options[] = { ...@@ -3580,6 +3582,7 @@ const OptionDef options[] = {
{ "qns", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qns}, "quantization noise shaping", "" }, { "qns", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qns}, "quantization noise shaping", "" },
{ "sc_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_sc_threshold}, "scene change threshold", "threshold" }, { "sc_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_sc_threshold}, "scene change threshold", "threshold" },
{ "me_range", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_range}, "limit motion vectors range (1023 for DivX player)", "range" }, { "me_range", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_range}, "limit motion vectors range (1023 for DivX player)", "range" },
{ "dc", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_dc_precision}, "intra_dc_precision", "precision" },
/* audio options */ /* audio options */
{ "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", }, { "ab", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_bitrate}, "set audio bitrate (in kbit/s)", "bitrate", },
......
...@@ -17,7 +17,7 @@ extern "C" { ...@@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION_INT 0x000408
#define FFMPEG_VERSION "0.4.8" #define FFMPEG_VERSION "0.4.8"
#define LIBAVCODEC_BUILD 4710 #define LIBAVCODEC_BUILD 4711
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION #define LIBAVCODEC_VERSION FFMPEG_VERSION
...@@ -1584,6 +1584,13 @@ typedef struct AVCodecContext { ...@@ -1584,6 +1584,13 @@ typedef struct AVCodecContext {
* - decoding: unused * - decoding: unused
*/ */
int mb_threshold; int mb_threshold;
/**
*
* - encoding: set by user
* - decoding: unused
*/
int intra_dc_precision;
} AVCodecContext; } AVCodecContext;
......
...@@ -360,7 +360,7 @@ static void common_init(MpegEncContext *s) ...@@ -360,7 +360,7 @@ static void common_init(MpegEncContext *s)
{ {
s->y_dc_scale_table= s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table; s->c_dc_scale_table= mpeg2_dc_scale_table[s->intra_dc_precision];
} }
...@@ -837,6 +837,27 @@ void ff_mpeg1_encode_init(MpegEncContext *s) ...@@ -837,6 +837,27 @@ void ff_mpeg1_encode_init(MpegEncContext *s)
static inline void encode_dc(MpegEncContext *s, int diff, int component) static inline void encode_dc(MpegEncContext *s, int diff, int component)
{ {
if(((unsigned) (diff+255)) >= 511){
int index;
if(diff<0){
index= av_log2_16bit(-2*diff);
diff--;
}else{
index= av_log2_16bit(2*diff);
}
if (component == 0) {
put_bits(
&s->pb,
vlc_dc_lum_bits[index] + index,
(vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)));
}else{
put_bits(
&s->pb,
vlc_dc_chroma_bits[index] + index,
(vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)));
}
}else{
if (component == 0) { if (component == 0) {
put_bits( put_bits(
&s->pb, &s->pb,
...@@ -848,6 +869,7 @@ static inline void encode_dc(MpegEncContext *s, int diff, int component) ...@@ -848,6 +869,7 @@ static inline void encode_dc(MpegEncContext *s, int diff, int component)
mpeg1_chr_dc_uni[diff+255]&0xFF, mpeg1_chr_dc_uni[diff+255]&0xFF,
mpeg1_chr_dc_uni[diff+255]>>8); mpeg1_chr_dc_uni[diff+255]>>8);
} }
}
} }
static void mpeg1_encode_block(MpegEncContext *s, static void mpeg1_encode_block(MpegEncContext *s,
......
...@@ -890,6 +890,7 @@ int MPV_encode_init(AVCodecContext *avctx) ...@@ -890,6 +890,7 @@ int MPV_encode_init(AVCodecContext *avctx)
s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
s->mpeg_quant= avctx->mpeg_quant; s->mpeg_quant= avctx->mpeg_quant;
s->rtp_mode= !!avctx->rtp_payload_size; s->rtp_mode= !!avctx->rtp_payload_size;
s->intra_dc_precision= avctx->intra_dc_precision;
if (s->gop_size <= 1) { if (s->gop_size <= 1) {
s->intra_only = 1; s->intra_only = 1;
...@@ -4009,7 +4010,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ ...@@ -4009,7 +4010,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
for(i=0; i<3; i++){ for(i=0; i<3; i++){
/* init last dc values */ /* init last dc values */
/* note: quant matrix value (8) is implied here */ /* note: quant matrix value (8) is implied here */
s->last_dc[i] = 128; s->last_dc[i] = 128 << s->intra_dc_precision;
s->current_picture_ptr->error[i] = 0; s->current_picture_ptr->error[i] = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment