summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2005-03-17 01:25:01 +0000
committerMichael Niedermayer <michaelni@gmx.at>2005-03-17 01:25:01 +0000
commitf3356e9c9eb8dc62925aaecf2ceec84106e06c6e (patch)
treebdadaff376c4d694349c32c1b347d5e30d83fb3d
parentcc973ecbe77ee6c273e2372ad24bb3aff0be5440 (diff)
more fine grained discarding of packets
Originally committed as revision 4051 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--ffmpeg.c8
-rw-r--r--libavformat/asf.c5
-rw-r--r--libavformat/avformat.h14
-rw-r--r--libavformat/avidec.c7
-rw-r--r--libavformat/flvdec.c8
-rw-r--r--libavformat/matroska.c2
-rw-r--r--libavformat/mov.c2
-rw-r--r--libavformat/mpeg.c2
-rw-r--r--libavformat/nut.c10
-rw-r--r--libavformat/rm.c3
-rw-r--r--libavformat/utils.c2
11 files changed, 46 insertions, 17 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 6609c9671b..44a84ad3d1 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -136,6 +136,7 @@ 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 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;
@@ -2902,7 +2903,7 @@ static void opt_input_file(const char *filename)
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;
@@ -2937,7 +2938,9 @@ static void opt_input_file(const char *filename)
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;
@@ -3947,6 +3950,7 @@ const OptionDef options[] = {
{ "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" },
diff --git a/libavformat/asf.c b/libavformat/asf.c
index d90e46b943..25bed2f450 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -545,7 +545,10 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
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);
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 137b8cf108..6fe15b5b17 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -5,7 +5,7 @@
extern "C" {
#endif
-#define LIBAVFORMAT_BUILD 4622
+#define LIBAVFORMAT_BUILD 4623
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVFORMAT_VERSION FFMPEG_VERSION
@@ -211,6 +211,15 @@ typedef struct AVIndexEntry {
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 */
@@ -227,7 +236,7 @@ typedef struct AVStream {
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 */
@@ -680,3 +689,4 @@ int match_ext(const char *filename, const char *extensions);
#endif
#endif /* AVFORMAT_H */
+
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 335a2ab4d3..bba0237903 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -532,7 +532,11 @@ resync:
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;
}
@@ -554,7 +558,6 @@ resync:
ast->packet_size= size + 8;
ast->remaining= size;
goto resync;
-
}
}
/* palette changed chunk */
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index ba024aec38..379e9099ad 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -105,7 +105,11 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
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;
}
@@ -158,7 +162,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
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;
diff --git a/libavformat/matroska.c b/libavformat/matroska.c
index 70ce86a3c8..b0c62ad882 100644
--- a/libavformat/matroska.c
+++ b/libavformat/matroska.c
@@ -2420,7 +2420,7 @@ matroska_parse_blockgroup (MatroskaDemuxContext *matroska,
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;
}
diff --git a/libavformat/mov.c b/libavformat/mov.c
index cb0752bc7e..6bfa2d5048 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1855,7 +1855,7 @@ again:
}
//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;
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index e9b5e9b263..ecc8ac1edc 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -1541,7 +1541,7 @@ static int mpegps_read_packet(AVFormatContext *s,
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;
diff --git a/libavformat/nut.c b/libavformat/nut.c
index daa429c848..645ca5986c 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -1222,14 +1222,18 @@ av_log(s, AV_LOG_DEBUG, "fs:%lld fc:%d ft:%d kf:%d pts:%lld size:%d mul:%d lsb:%
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;
}
diff --git a/libavformat/rm.c b/libavformat/rm.c
index fd7e955c28..bea8c4bb2c 100644
--- a/libavformat/rm.c
+++ b/libavformat/rm.c
@@ -854,7 +854,8 @@ resync:
rm->remaining_len-= len;
}
- if(st->discard){
+ if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
+ || st->discard >= AVDISCARD_ALL){
url_fskip(pb, len);
goto resync;
}
diff --git a/libavformat/utils.c b/libavformat/utils.c
index d2b6c94bc5..b4701a0ffe 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -821,7 +821,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
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);