static int video_inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
static int me_method = ME_EPZS;
static int video_disable = 0;
+static int video_discard = 0;
static int video_codec_id = CODEC_ID_NONE;
static int video_codec_tag = 0;
static int same_quality = 0;
audio_channels = enc->channels;
audio_sample_rate = enc->sample_rate;
if(audio_disable)
- ic->streams[i]->discard= 1;
+ ic->streams[i]->discard= AVDISCARD_ALL;
break;
case CODEC_TYPE_VIDEO:
frame_height = enc->height;
enc->rate_emu = rate_emu;
if(video_disable)
- ic->streams[i]->discard= 1;
+ ic->streams[i]->discard= AVDISCARD_ALL;
+ else if(video_discard)
+ ic->streams[i]->discard= video_discard;
break;
case CODEC_TYPE_DATA:
break;
{ "g", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_gop_size}, "set the group of picture size", "gop_size" },
{ "intra", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&intra_only}, "use only intra frames"},
{ "vn", OPT_BOOL | OPT_VIDEO, {(void*)&video_disable}, "disable video" },
+ { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold" },
{ "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantiser scale (VBR)", "q" },
{ "qmin", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qmin}, "min video quantiser scale (VBR)", "q" },
{ "qmax", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qmax}, "max video quantiser scale (VBR)", "q" },
asf->packet_size_left -= rsize;
//printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
- if (asf->stream_index < 0 || s->streams[asf->stream_index]->discard) {
+ if (asf->stream_index < 0
+ || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
+ || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
+ ) {
asf->packet_time_start = 0;
/* unhandled packet (should not happen) */
url_fskip(pb, asf->packet_frag_size);
extern "C" {
#endif
-#define LIBAVFORMAT_BUILD 4622
+#define LIBAVFORMAT_BUILD 4623
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVFORMAT_VERSION FFMPEG_VERSION
int min_distance; /* min distance between this and the previous keyframe, used to avoid unneeded searching */
} AVIndexEntry;
+enum AVDiscard{
+//we leave some space between them for extensions (drop some keyframes for intra only or drop just some bidir frames)
+ AVDISCARD_NONE =-16, ///< discard nothing
+ AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi
+ AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
+ AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
+ AVDISCARD_ALL = 48, ///< discard all
+};
+
typedef struct AVStream {
int index; /* stream index in AVFormatContext */
int id; /* format specific stream id */
int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
/* ffmpeg.c private use */
int stream_copy; /* if TRUE, just copy stream */
- int discard; ///< if 1, packets can be discarded at will and dont need to be demuxed
+ enum AVDiscard discard; ///< selects which packets can be discarded at will and dont need to be demuxed
//FIXME move stuff to a flags field?
/* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
* MN:dunno if thats the right place, for it */
#endif
#endif /* AVFORMAT_H */
+
st = s->streams[n];
ast = st->priv_data;
- if(st->discard){
+ if( (st->discard >= AVDISCARD_DEFAULT && size==0)
+ /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & PKT_FLAG_KEY))*/ //FIXME needs a little reordering
+ || st->discard >= AVDISCARD_ALL){
+ if(ast->sample_size) ast->frame_offset += pkt->size;
+ else ast->frame_offset++;
url_fskip(pb, size);
goto resync;
}
ast->packet_size= size + 8;
ast->remaining= size;
goto resync;
-
}
}
/* palette changed chunk */
st->codec.frame_rate_base= 1;
st->codec.frame_rate= 1000;
}
- if(st->discard){
+// av_log(NULL, AV_LOG_DEBUG, "%d %X %d \n", is_audio, flags, st->discard);
+ if( (st->discard >= AVDISCARD_NONKEY && !((flags >> 4)==1 || is_audio))
+ ||(st->discard >= AVDISCARD_BIDIR && ((flags >> 4)==3 && !is_audio))
+ || st->discard >= AVDISCARD_ALL
+ ){
url_fskip(&s->pb, size);
continue;
}
pkt->pts = pts;
pkt->stream_index = st->index;
- if (!is_audio && ((flags >> 4)==1))
+ if (is_audio || ((flags >> 4)==1))
pkt->flags |= PKT_FLAG_KEY;
return ret;
av_free(origdata);
break;
}
- if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard){
+ if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard >= AVDISCARD_ALL){
av_free(origdata);
break;
}
}
//av_log(NULL, AV_LOG_DEBUG, "chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
- if(!sc->is_ff_stream || s->streams[sc->ffindex]->discard) {
+ if(!sc->is_ff_stream || (s->streams[sc->ffindex]->discard >= AVDISCARD_ALL)) {
url_fskip(&s->pb, (offset - mov->next_chunk_offset));
mov->next_chunk_offset = offset;
offset = 0x0FFFFFFFFFFFFFFFLL;
if (codec_id != CODEC_ID_PCM_S16BE)
st->need_parsing = 1;
found:
- if(st->discard)
+ if(st->discard >= AVDISCARD_ALL)
goto skip;
if (startcode >= 0xa0 && startcode <= 0xbf) {
int b1, freq;
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code, int frame_type, int64_t frame_start){
AVFormatContext *s= nut->avf;
ByteIOContext *bc = &s->pb;
- int size, stream_id, key_frame;
- int64_t pts;
+ int size, stream_id, key_frame, discard;
+ int64_t pts, last_IP_pts;
size= decode_frame_header(nut, &key_frame, &pts, &stream_id, frame_code, frame_type, frame_start);
if(size < 0)
return -1;
- if(s->streams[ stream_id ]->discard){
+ discard= s->streams[ stream_id ]->discard;
+ last_IP_pts= s->streams[ stream_id ]->last_IP_pts;
+ if( (discard >= AVDISCARD_NONKEY && !key_frame)
+ ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts)
+ || discard >= AVDISCARD_ALL){
url_fskip(bc, size);
return 1;
}
rm->remaining_len-= len;
}
- if(st->discard){
+ if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
+ || st->discard >= AVDISCARD_ALL){
url_fskip(pb, len);
goto resync;
}
compute_pkt_fields(s, st, NULL, pkt);
s->cur_st = NULL;
return 0;
- } else if (s->cur_len > 0 && !st->discard) {
+ } else if (s->cur_len > 0 && st->discard < AVDISCARD_ALL) {
len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size,
s->cur_ptr, s->cur_len,
s->cur_pkt.pts, s->cur_pkt.dts);