closed gop support & flags2 as all bits in flags are used

and a few minor things i forgot to commit ...

Originally committed as revision 2718 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2004-01-22 19:48:28 +00:00
parent d398a27e0b
commit 303e50e65b
11 changed files with 61 additions and 14 deletions

View File

@ -105,6 +105,8 @@ static float video_b_qfactor = 1.25;
static float video_b_qoffset = 1.25; static float video_b_qoffset = 1.25;
static float video_i_qfactor = -0.8; static float video_i_qfactor = -0.8;
static float video_i_qoffset = 0.0; static float video_i_qoffset = 0.0;
static int video_intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
static int video_inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
static int me_method = ME_EPZS; static int me_method = ME_EPZS;
static int video_disable = 0; static int video_disable = 0;
static int video_codec_id = CODEC_ID_NONE; static int video_codec_id = CODEC_ID_NONE;
@ -123,6 +125,7 @@ static int use_umv = 0;
static int use_alt_scan = 0; static int use_alt_scan = 0;
static int use_trell = 0; static int use_trell = 0;
static int use_scan_offset = 0; static int use_scan_offset = 0;
static int closed_gop = 0;
static int do_deinterlace = 0; static int do_deinterlace = 0;
static int do_interlace_dct = 0; static int do_interlace_dct = 0;
static int do_interlace_me = 0; static int do_interlace_me = 0;
@ -137,6 +140,7 @@ static int error_rate = 0;
static int strict = 0; static int strict = 0;
static int top_field_first = -1; static int top_field_first = -1;
static int noise_reduction = 0; static int noise_reduction = 0;
static int sc_threshold = 0;
static int debug = 0; static int debug = 0;
static int debug_mv = 0; static int debug_mv = 0;
extern int loop_input; /* currently a hack */ extern int loop_input; /* currently a hack */
@ -1458,6 +1462,7 @@ static int av_encode(AVFormatContext **output_files,
file_table[file_index].eof_reached = 1; file_table[file_index].eof_reached = 1;
continue; continue;
} }
if (!pkt.size) { if (!pkt.size) {
stream_no_data = is; stream_no_data = is;
} else { } else {
@ -1948,6 +1953,15 @@ static void opt_i_qoffset(const char *arg)
video_i_qoffset = atof(arg); video_i_qoffset = atof(arg);
} }
static void opt_ibias(const char *arg)
{
video_intra_quant_bias = atoi(arg);
}
static void opt_pbias(const char *arg)
{
video_inter_quant_bias = atoi(arg);
}
static void opt_packet_size(const char *arg) static void opt_packet_size(const char *arg)
{ {
packet_size= atoi(arg); packet_size= atoi(arg);
@ -1973,6 +1987,11 @@ static void opt_noise_reduction(const char *arg)
noise_reduction= atoi(arg); noise_reduction= atoi(arg);
} }
static void opt_sc_threshold(const char *arg)
{
sc_threshold= atoi(arg);
}
static void opt_audio_bitrate(const char *arg) static void opt_audio_bitrate(const char *arg)
{ {
audio_bit_rate = atoi(arg) * 1000; audio_bit_rate = atoi(arg) * 1000;
@ -2410,6 +2429,9 @@ static void opt_output_file(const char *filename)
if (use_scan_offset) { if (use_scan_offset) {
video_enc->flags |= CODEC_FLAG_SVCD_SCAN_OFFSET; video_enc->flags |= CODEC_FLAG_SVCD_SCAN_OFFSET;
} }
if (closed_gop) {
video_enc->flags |= CODEC_FLAG_CLOSED_GOP;
}
if (b_frames) { if (b_frames) {
video_enc->max_b_frames = b_frames; video_enc->max_b_frames = b_frames;
video_enc->b_frame_strategy = 0; video_enc->b_frame_strategy = 0;
@ -2466,11 +2488,14 @@ static void opt_output_file(const char *filename)
video_enc->b_quant_factor = video_b_qfactor; video_enc->b_quant_factor = video_b_qfactor;
video_enc->i_quant_offset = video_i_qoffset; video_enc->i_quant_offset = video_i_qoffset;
video_enc->b_quant_offset = video_b_qoffset; video_enc->b_quant_offset = video_b_qoffset;
video_enc->intra_quant_bias = video_intra_quant_bias;
video_enc->inter_quant_bias = video_inter_quant_bias;
video_enc->dct_algo = dct_algo; video_enc->dct_algo = dct_algo;
video_enc->idct_algo = idct_algo; video_enc->idct_algo = idct_algo;
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;
video_enc->scenechange_threshold= sc_threshold;
if(packet_size){ if(packet_size){
video_enc->rtp_mode= 1; video_enc->rtp_mode= 1;
video_enc->rtp_payload_size= packet_size; video_enc->rtp_payload_size= packet_size;
@ -3001,6 +3026,8 @@ const OptionDef options[] = {
{ "i_qfactor", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qfactor}, "qp factor between p and i frames", "factor" }, { "i_qfactor", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qfactor}, "qp factor between p and i frames", "factor" },
{ "b_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_qoffset}, "qp offset between p and b frames", "offset" }, { "b_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_b_qoffset}, "qp offset between p and b frames", "offset" },
{ "i_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qoffset}, "qp offset between p and i frames", "offset" }, { "i_qoffset", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_i_qoffset}, "qp offset between p and i frames", "offset" },
{ "ibias", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_ibias}, "intra quant bias", "bias" },
{ "pbias", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_pbias}, "inter quant bias", "bias" },
// { "b_strategy", HAS_ARG | OPT_EXPERT, {(void*)opt_b_strategy}, "dynamic b frame selection strategy", "strategy" }, // { "b_strategy", HAS_ARG | OPT_EXPERT, {(void*)opt_b_strategy}, "dynamic b frame selection strategy", "strategy" },
{ "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" }, { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" },
{ "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" },
@ -3047,11 +3074,13 @@ const OptionDef options[] = {
{ "umv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_umv}, "enable Unlimited Motion Vector (h263+)" }, { "umv", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_umv}, "enable Unlimited Motion Vector (h263+)" },
{ "alt", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_alt_scan}, "enable alternate scantable (mpeg2)" }, { "alt", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_alt_scan}, "enable alternate scantable (mpeg2)" },
{ "trell", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_trell}, "enable trellis quantization" }, { "trell", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_trell}, "enable trellis quantization" },
{ "cgop", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&closed_gop}, "closed gop" },
{ "scan_offset", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_scan_offset}, "enable SVCD Scan Offset placeholder" }, { "scan_offset", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&use_scan_offset}, "enable SVCD Scan Offset placeholder" },
{ "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" }, { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" },
{ "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" }, { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" },
{ "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" },
{ "nr", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_noise_reduction}, "noise reduction", "" }, { "nr", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_noise_reduction}, "noise reduction", "" },
{ "sc_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_sc_threshold}, "scene change threshold", "threshold" },
/* 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", },

View File

@ -270,6 +270,7 @@ static const __attribute__((unused)) int Motion_Est_QTab[] =
#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
#define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data #define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data
#define CODEC_FLAG_CLOSED_GOP 0x80000000
/* Unsupported options : /* Unsupported options :
* Syntax Arithmetic coding (SAC) * Syntax Arithmetic coding (SAC)
* Reference Picture Selection * Reference Picture Selection

View File

@ -393,6 +393,7 @@ uint64_t time= rdtsc();
printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
#endif #endif
s->flags= avctx->flags; s->flags= avctx->flags;
s->flags2= avctx->flags2;
*data_size = 0; *data_size = 0;

View File

@ -4131,6 +4131,7 @@ static int decode_frame(AVCodecContext *avctx,
int buf_index; int buf_index;
s->flags= avctx->flags; s->flags= avctx->flags;
s->flags2= avctx->flags2;
*data_size = 0; *data_size = 0;

View File

@ -855,7 +855,6 @@ static int mjpeg_decode_init(AVCodecContext *avctx)
/* ugly way to get the idct & scantable FIXME */ /* ugly way to get the idct & scantable FIXME */
memset(&s2, 0, sizeof(MpegEncContext)); memset(&s2, 0, sizeof(MpegEncContext));
s2.flags= avctx->flags;
s2.avctx= avctx; s2.avctx= avctx;
// s2->out_format = FMT_MJPEG; // s2->out_format = FMT_MJPEG;
s2.width = 8; s2.width = 8;

View File

@ -330,7 +330,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
put_bits(&s->pb, 1, 1); put_bits(&s->pb, 1, 1);
put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));
put_bits(&s->pb, 6, (uint32_t)((time_code % fps))); put_bits(&s->pb, 6, (uint32_t)((time_code % fps)));
put_bits(&s->pb, 1, 0); /* closed gop */ put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP));
put_bits(&s->pb, 1, 0); /* broken link */ put_bits(&s->pb, 1, 0); /* broken link */
} }
} }
@ -1706,6 +1706,7 @@ static int mpeg_decode_init(AVCodecContext *avctx)
s->mpeg_enc_ctx.avctx= avctx; s->mpeg_enc_ctx.avctx= avctx;
s->mpeg_enc_ctx.flags= avctx->flags; s->mpeg_enc_ctx.flags= avctx->flags;
s->mpeg_enc_ctx.flags2= avctx->flags2;
common_init(&s->mpeg_enc_ctx); common_init(&s->mpeg_enc_ctx);
init_vlcs(); init_vlcs();

View File

@ -408,6 +408,7 @@ int MPV_common_init(MpegEncContext *s)
DCT_common_init(s); DCT_common_init(s);
s->flags= s->avctx->flags; s->flags= s->avctx->flags;
s->flags2= s->avctx->flags2;
s->mb_width = (s->width + 15) / 16; s->mb_width = (s->width + 15) / 16;
s->mb_height = (s->height + 15) / 16; s->mb_height = (s->height + 15) / 16;
@ -700,6 +701,7 @@ int MPV_encode_init(AVCodecContext *avctx)
s->gop_size = avctx->gop_size; s->gop_size = avctx->gop_size;
s->avctx = avctx; s->avctx = avctx;
s->flags= avctx->flags; s->flags= avctx->flags;
s->flags2= avctx->flags2;
s->max_b_frames= avctx->max_b_frames; s->max_b_frames= avctx->max_b_frames;
s->codec_id= avctx->codec->id; s->codec_id= avctx->codec->id;
s->luma_elim_threshold = avctx->luma_elim_threshold; s->luma_elim_threshold = avctx->luma_elim_threshold;
@ -789,6 +791,11 @@ int MPV_encode_init(AVCodecContext *avctx)
return -1; return -1;
} }
if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){
av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet\n");
return -1;
}
if(s->codec_id==CODEC_ID_MJPEG){ if(s->codec_id==CODEC_ID_MJPEG){
s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x
s->inter_quant_bias= 0; s->inter_quant_bias= 0;
@ -1809,12 +1816,19 @@ static void select_input_picture(MpegEncContext *s){
//static int b_count=0; //static int b_count=0;
//b_count+= b_frames; //b_count+= b_frames;
//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); //av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count);
if(s->picture_in_gop_number + b_frames >= s->gop_size){
if(s->flags & CODEC_FLAG_CLOSED_GOP)
b_frames=0;
s->input_picture[b_frames]->pict_type= I_TYPE;
}
if( (s->flags & CODEC_FLAG_CLOSED_GOP)
&& b_frames
&& s->input_picture[b_frames]->pict_type== I_TYPE)
b_frames--;
s->reordered_input_picture[0]= s->input_picture[b_frames]; s->reordered_input_picture[0]= s->input_picture[b_frames];
if( s->picture_in_gop_number + b_frames >= s->gop_size if(s->reordered_input_picture[0]->pict_type != I_TYPE)
|| s->reordered_input_picture[0]->pict_type== I_TYPE)
s->reordered_input_picture[0]->pict_type= I_TYPE;
else
s->reordered_input_picture[0]->pict_type= P_TYPE; s->reordered_input_picture[0]->pict_type= P_TYPE;
s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++;
for(i=0; i<b_frames; i++){ for(i=0; i<b_frames; i++){

View File

@ -255,6 +255,7 @@ typedef struct MpegEncContext {
int fixed_qscale; ///< fixed qscale if non zero int fixed_qscale; ///< fixed qscale if non zero
int encoding; ///< true if we are encoding (vs decoding) int encoding; ///< true if we are encoding (vs decoding)
int flags; ///< AVCodecContext.flags (HQ, MV4, ...) int flags; ///< AVCodecContext.flags (HQ, MV4, ...)
int flags2; ///< AVCodecContext.flags2
int max_b_frames; ///< max number of b-frames for encoding int max_b_frames; ///< max number of b-frames for encoding
int luma_elim_threshold; int luma_elim_threshold;
int chroma_elim_threshold; int chroma_elim_threshold;
@ -469,7 +470,6 @@ typedef struct MpegEncContext {
void *opaque; ///< private data for the user void *opaque; ///< private data for the user
/* bit rate control */ /* bit rate control */
int I_frame_bits; //FIXME used in mpeg12 ...
int64_t wanted_bits; int64_t wanted_bits;
int64_t total_bits; int64_t total_bits;
int frame_bits; ///< bits used for the current frame int frame_bits; ///< bits used for the current frame
@ -619,7 +619,6 @@ typedef struct MpegEncContext {
GetBitContext gb; GetBitContext gb;
/* Mpeg1 specific */ /* Mpeg1 specific */
int fake_picture_number; ///< picture number at the bitstream frame rate
int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
int last_mv_dir; ///< last mv_dir, used for b frame encoding int last_mv_dir; ///< last mv_dir, used for b frame encoding
int broken_link; ///< no_output_of_prior_pics_flag int broken_link; ///< no_output_of_prior_pics_flag

View File

@ -474,8 +474,6 @@ static int rv10_decode_init(AVCodecContext *avctx)
av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id); av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
} }
//printf("ver:%X\n", avctx->sub_id); //printf("ver:%X\n", avctx->sub_id);
s->flags= avctx->flags;
if (MPV_common_init(s) < 0) if (MPV_common_init(s) < 0)
return -1; return -1;

View File

@ -789,7 +789,6 @@ static int svq1_decode_init(AVCodecContext *avctx)
s->codec_id= avctx->codec->id; s->codec_id= avctx->codec->id;
avctx->pix_fmt = PIX_FMT_YUV410P; avctx->pix_fmt = PIX_FMT_YUV410P;
avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames
s->flags= avctx->flags;
if (MPV_common_init(s) < 0) return -1; if (MPV_common_init(s) < 0) return -1;
init_vlc(&svq1_block_type, 2, 4, init_vlc(&svq1_block_type, 2, 4,

View File

@ -697,8 +697,10 @@ static int svq3_decode_slice_header (H264Context *h) {
h->next_slice_index = s->gb.index + 8*show_bits (&s->gb, 8*length) + 8*length; h->next_slice_index = s->gb.index + 8*show_bits (&s->gb, 8*length) + 8*length;
if (h->next_slice_index > s->gb.size_in_bits) if (h->next_slice_index > s->gb.size_in_bits){
av_log(h->s.avctx, AV_LOG_ERROR, "slice after bitstream end\n");
return -1; return -1;
}
s->gb.size_in_bits = h->next_slice_index - 8*(length - 1); s->gb.size_in_bits = h->next_slice_index - 8*(length - 1);
s->gb.index += 8; s->gb.index += 8;
@ -709,8 +711,10 @@ static int svq3_decode_slice_header (H264Context *h) {
} }
} }
if ((i = svq3_get_ue_golomb (&s->gb)) == INVALID_VLC || i >= 3) if ((i = svq3_get_ue_golomb (&s->gb)) == INVALID_VLC || i >= 3){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i);
return -1; return -1;
}
h->slice_type = golomb_to_pict_type[i]; h->slice_type = golomb_to_pict_type[i];
@ -766,6 +770,7 @@ static int svq3_decode_frame (AVCodecContext *avctx,
*data_size = 0; *data_size = 0;
s->flags = avctx->flags; s->flags = avctx->flags;
s->flags2 = avctx->flags2;
s->unrestricted_mv = 1; s->unrestricted_mv = 1;
if (!s->context_initialized) { if (!s->context_initialized) {