summaryrefslogtreecommitdiffstats
path: root/libavcodec/decode.c
diff options
context:
space:
mode:
authorGyan Doshi <ffmpeg@gyani.pro>2019-04-14 22:12:25 +0530
committerGyan Doshi <ffmpeg@gyani.pro>2019-04-20 10:38:01 +0530
commit3153a6502a28b20a0da822daf32bcd8f7c90d721 (patch)
treef3673539f54af82ab363d813eb42cd72048105e8 /libavcodec/decode.c
parentd93e44332f1bd2be90eb637268385a5acd8f6c10 (diff)
downloadffmpeg-streaming-3153a6502a28b20a0da822daf32bcd8f7c90d721.zip
ffmpeg-streaming-3153a6502a28b20a0da822daf32bcd8f7c90d721.tar.gz
avcodec: add AV_CODEC_FLAG_DROPCHANGED to flags
Discard decoded frames which differ from first decoded frame in stream.
Diffstat (limited to 'libavcodec/decode.c')
-rw-r--r--libavcodec/decode.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index a32ff2f..6c31166 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -740,7 +740,7 @@ static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
{
AVCodecInternal *avci = avctx->internal;
- int ret;
+ int ret, changed;
av_frame_unref(frame);
@@ -765,6 +765,51 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr
avctx->frame_number++;
+ if (avctx->flags & AV_CODEC_FLAG_DROPCHANGED) {
+
+ if (avctx->frame_number == 1) {
+ avci->initial_format = frame->format;
+ switch(avctx->codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ avci->initial_width = frame->width;
+ avci->initial_height = frame->height;
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ avci->initial_sample_rate = frame->sample_rate ? frame->sample_rate :
+ avctx->sample_rate;
+ avci->initial_channels = frame->channels;
+ avci->initial_channel_layout = frame->channel_layout;
+ break;
+ }
+ }
+
+ if (avctx->frame_number > 1) {
+ changed = avci->initial_format != frame->format;
+
+ switch(avctx->codec_type) {
+ case AVMEDIA_TYPE_VIDEO:
+ changed |= avci->initial_width != frame->width ||
+ avci->initial_height != frame->height;
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ changed |= avci->initial_sample_rate != frame->sample_rate ||
+ avci->initial_sample_rate != avctx->sample_rate ||
+ avci->initial_channels != frame->channels ||
+ avci->initial_channel_layout != frame->channel_layout;
+ break;
+ }
+
+ if (changed) {
+ avci->changed_frames_dropped++;
+ av_log(avctx, AV_LOG_INFO, "dropped changed frame #%d pts %"PRId64
+ " drop count: %d \n",
+ avctx->frame_number, frame->pts,
+ avci->changed_frames_dropped);
+ av_frame_unref(frame);
+ return AVERROR_INPUT_CHANGED;
+ }
+ }
+ }
return 0;
}
OpenPOWER on IntegriCloud