Commit f3356e9c authored by Michael Niedermayer's avatar Michael Niedermayer
Browse files

more fine grained discarding of packets

Originally committed as revision 4051 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent cc973ecb
......@@ -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" },
......
......@@ -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);
......
......@@ -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 */
......@@ -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 */
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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);
......
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