diff mbox series

[FFmpeg-devel,1/2] lavc: deprecate AV_CODEC_FLAG_TRUNCATED

Message ID 20210308102633.19649-1-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/2] lavc: deprecate AV_CODEC_FLAG_TRUNCATED
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Anton Khirnov March 8, 2021, 10:26 a.m. UTC
It is supported only by two decoders and is entirely redundant with
parsers.
---
 doc/APIchanges             |  3 +++
 libavcodec/avcodec.h       |  4 ++++
 libavcodec/decode.c        |  6 +++++-
 libavcodec/h263dec.c       | 10 ++++++++--
 libavcodec/mpeg12dec.c     | 12 +++++++++++-
 libavcodec/mpegvideo.c     |  6 ++++++
 libavcodec/mpegvideo.h     |  2 ++
 libavcodec/options_table.h |  2 ++
 libavcodec/pthread.c       |  2 ++
 libavcodec/version.h       |  3 +++
 10 files changed, 46 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt March 8, 2021, 12:24 p.m. UTC | #1
Anton Khirnov:
> It is supported only by two decoders and is entirely redundant with
> parsers.

Just because it is only used in two files doesn't mean it is only used
by two decoders: Six decoders have the AV_CODEC_CAP_TRUNCATED (which you
forgot to deprecate) set.

(fftools/cmdutils.c checks for AV_CODEC_CAP_TRUNCATED and informs the
user about whether it is supported by a codec or not. It should probably
be wrapped in #if LIBAVCODEC_VERSION_MAJOR < 60 checks.)

> ---
>  doc/APIchanges             |  3 +++
>  libavcodec/avcodec.h       |  4 ++++
>  libavcodec/decode.c        |  6 +++++-
>  libavcodec/h263dec.c       | 10 ++++++++--
>  libavcodec/mpeg12dec.c     | 12 +++++++++++-
>  libavcodec/mpegvideo.c     |  6 ++++++
>  libavcodec/mpegvideo.h     |  2 ++
>  libavcodec/options_table.h |  2 ++
>  libavcodec/pthread.c       |  2 ++
>  libavcodec/version.h       |  3 +++
>  10 files changed, 46 insertions(+), 4 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 4027d599e7..344f484a8b 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil:     2017-10-21
>  
>  API changes, most recent first:
>  
> +2021-03-xx - xxxxxxxxxx - avcodec.h

Missing version

> +  Deprecate AV_CODEC_FLAG_TRUNCATED, as it is redundant with parsers.
> +
>  2021-03-04 - xxxxxxxxxx - lavc 58.128.101 - avcodec.h
>    Enable err_recognition to be set for encoders.
>  
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 46d31b34ad..45929d6b05 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -310,11 +310,15 @@ typedef struct RcOverride{
>   * error[?] variables will be set during encoding.
>   */
>  #define AV_CODEC_FLAG_PSNR            (1 << 15)
> +#if FF_API_FLAG_TRUNCATED
>  /**
>   * Input bitstream might be truncated at a random location
>   * instead of only at frame boundaries.
> + *
> + * @deprecated use codec parsers for packetizing input
>   */
>  #define AV_CODEC_FLAG_TRUNCATED       (1 << 16)
> +#endif
>  /**
>   * Use interlaced DCT.
>   */
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index c976795311..c00069b8d4 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -462,7 +462,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      if (!got_frame)
>          av_frame_unref(frame);
>  
> -    if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
> +    if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO
> +#if FF_API_FLAG_TRUNCATED
> +        && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)
> +#endif
> +        )
>          ret = pkt->size;
>  
>  #if FF_API_AVCTX_TIMEBASE
> diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> index dafa54d8d4..57d4a0d4e7 100644
> --- a/libavcodec/h263dec.c
> +++ b/libavcodec/h263dec.c
> @@ -172,13 +172,17 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size)
>          /* We would have to scan through the whole buf to handle the weird
>           * reordering ... */
>          return buf_size;
> -    } else if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
> +    }
> +#if FF_API_FLAG_TRUNCATED
> +    else if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
>          pos -= s->parse_context.last_index;
>          // padding is not really read so this might be -1
>          if (pos < 0)
>              pos = 0;
>          return pos;
> -    } else {
> +    }
> +#endif
> +    else {
>          // avoid infinite loops (maybe not needed...)
>          if (pos == 0)
>              pos = 1;
> @@ -443,6 +447,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
>          return 0;
>      }
>  
> +#if FF_API_FLAG_TRUNCATED
>      if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
>          int next;
>  
> @@ -462,6 +467,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
>                               &buf_size) < 0)
>              return buf_size;
>      }
> +#endif
>  
>  retry:
>      if (s->divx_packed && s->bitstream_buffer_size) {
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 92dd6a0b24..9e1f9c4b79 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -1267,10 +1267,14 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
>          (s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
>          0) {
>          if (s1->mpeg_enc_ctx_allocated) {
> +#if FF_API_FLAG_TRUNCATED
>              ParseContext pc = s->parse_context;
>              s->parse_context.buffer = 0;
>              ff_mpv_common_end(s);
>              s->parse_context = pc;
> +#else
> +            ff_mpv_common_end(s);
> +#endif
>              s1->mpeg_enc_ctx_allocated = 0;
>          }
>  
> @@ -2506,7 +2510,11 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
>              if (avctx->err_recognition & AV_EF_EXPLODE && s2->er.error_count)
>                  return AVERROR_INVALIDDATA;
>  
> -            return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
> +            return FFMAX(0, buf_ptr - buf
> +#if FF_API_FLAG_TRUNCATED
> +                         - s2->parse_context.last_index
> +#endif
> +                        );
>          }
>  
>          input_size = buf_end - buf_ptr;
> @@ -2812,6 +2820,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
>          return buf_size;
>      }
>  
> +#if FF_API_FLAG_TRUNCATED
>      if (s2->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
>          int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf,
>                                             buf_size, NULL);
> @@ -2820,6 +2829,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
>                               (const uint8_t **) &buf, &buf_size) < 0)
>              return buf_size;
>      }
> +#endif
>  
>      s2->codec_tag = avpriv_toupper4(avctx->codec_tag);
>      if (s->mpeg_enc_ctx_allocated == 0 && (   s2->codec_tag == AV_RL32("VCR2")
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index 988dd18a33..45f42618e2 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -944,7 +944,9 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
>      if ((ret = init_context_frame(s)))
>          return AVERROR(ENOMEM);
>  
> +#if FF_API_FLAG_TRUNCATED
>      s->parse_context.state = -1;
> +#endif
>  
>      s->context_initialized = 1;
>      memset(s->thread_context, 0, sizeof(s->thread_context));
> @@ -1123,8 +1125,10 @@ void ff_mpv_common_end(MpegEncContext *s)
>          s->slice_context_count = 1;
>      } else free_duplicate_context(s);
>  
> +#if FF_API_FLAG_TRUNCATED
>      av_freep(&s->parse_context.buffer);
>      s->parse_context.buffer_size = 0;
> +#endif
>  
>      av_freep(&s->bitstream_buffer);
>      s->allocated_bitstream_buffer_size = 0;
> @@ -2320,12 +2324,14 @@ void ff_mpeg_flush(AVCodecContext *avctx){
>      s->mb_x= s->mb_y= 0;
>      s->closed_gop= 0;
>  
> +#if FF_API_FLAG_TRUNCATED
>      s->parse_context.state= -1;
>      s->parse_context.frame_start_found= 0;
>      s->parse_context.overread= 0;
>      s->parse_context.overread_index= 0;
>      s->parse_context.index= 0;
>      s->parse_context.last_index= 0;
> +#endif
>      s->bitstream_buffer_size=0;
>      s->pp_time=0;
>  }
> diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
> index 5a99c19656..0779a3d51a 100644
> --- a/libavcodec/mpegvideo.h
> +++ b/libavcodec/mpegvideo.h
> @@ -359,7 +359,9 @@ typedef struct MpegEncContext {
>      int mb_num_left;                 ///< number of MBs left in this video packet (for partitioned Slices only)
>      int next_p_frame_damaged;        ///< set if the next p frame is damaged, to avoid showing trashed B-frames
>  
> +#if FF_API_FLAG_TRUNCATED
>      ParseContext parse_context;
> +#endif

I think you can remove the inclusion of parser.h once this is removed.

>  
>      /* H.263 specific */
>      int gob_index;
> diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
> index e12159f734..3202f68cd3 100644
> --- a/libavcodec/options_table.h
> +++ b/libavcodec/options_table.h
> @@ -59,7 +59,9 @@ static const AVOption avcodec_options[] = {
>  {"pass2", "use internal 2-pass ratecontrol in second pass mode", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"},
>  {"gray", "only decode/encode grayscale", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"},
>  {"psnr", "error[?] variables will be set during encoding", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"},
> +#if FF_API_FLAG_TRUNCATED
>  {"truncated", "Input bitstream might be randomly truncated", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, V|D, "flags"},

You should add AV_OPT_FLAG_DEPRECATED (but better test in advance
whether it works with AV_OPT_TYPE_CONST at all).

> +#endif
>  {"ildct", "use interlaced DCT", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_INTERLACED_DCT }, INT_MIN, INT_MAX, V|E, "flags"},
>  {"low_delay", "force low delay", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_LOW_DELAY }, INT_MIN, INT_MAX, V|D|E, "flags"},
>  {"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
> diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
> index 572471586d..86c208e73e 100644
> --- a/libavcodec/pthread.c
> +++ b/libavcodec/pthread.c
> @@ -46,7 +46,9 @@
>  static void validate_thread_parameters(AVCodecContext *avctx)
>  {
>      int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)
> +#if FF_API_FLAG_TRUNCATED
>                                  && !(avctx->flags  & AV_CODEC_FLAG_TRUNCATED)
> +#endif
>                                  && !(avctx->flags  & AV_CODEC_FLAG_LOW_DELAY)
>                                  && !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS);
>      if (avctx->thread_count == 1) {
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 169c763e8a..d3e813428b 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -162,5 +162,8 @@

Missing minor version bump.

>  #ifndef FF_API_GET_FRAME_CLASS
>  #define FF_API_GET_FRAME_CLASS     (LIBAVCODEC_VERSION_MAJOR < 60)
>  #endif
> +#ifndef FF_API_FLAG_TRUNCATED
> +#define FF_API_FLAG_TRUNCATED      (LIBAVCODEC_VERSION_MAJOR < 60)
> +#endif
>  
>  #endif /* AVCODEC_VERSION_H */
>
James Almer March 8, 2021, 12:31 p.m. UTC | #2
On 3/8/2021 9:24 AM, Andreas Rheinhardt wrote:
> Anton Khirnov:
>> It is supported only by two decoders and is entirely redundant with
>> parsers.
> 
> Just because it is only used in two files doesn't mean it is only used
> by two decoders: Six decoders have the AV_CODEC_CAP_TRUNCATED (which you
> forgot to deprecate) set.
> 
> (fftools/cmdutils.c checks for AV_CODEC_CAP_TRUNCATED and informs the
> user about whether it is supported by a codec or not. It should probably
> be wrapped in #if LIBAVCODEC_VERSION_MAJOR < 60 checks.)
> 
>> ---
>>   doc/APIchanges             |  3 +++
>>   libavcodec/avcodec.h       |  4 ++++
>>   libavcodec/decode.c        |  6 +++++-
>>   libavcodec/h263dec.c       | 10 ++++++++--
>>   libavcodec/mpeg12dec.c     | 12 +++++++++++-
>>   libavcodec/mpegvideo.c     |  6 ++++++
>>   libavcodec/mpegvideo.h     |  2 ++
>>   libavcodec/options_table.h |  2 ++
>>   libavcodec/pthread.c       |  2 ++
>>   libavcodec/version.h       |  3 +++
>>   10 files changed, 46 insertions(+), 4 deletions(-)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index 4027d599e7..344f484a8b 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -15,6 +15,9 @@ libavutil:     2017-10-21
>>   
>>   API changes, most recent first:
>>   
>> +2021-03-xx - xxxxxxxxxx - avcodec.h
> 
> Missing version

[...]

>> diff --git a/libavcodec/version.h b/libavcodec/version.h
>> index 169c763e8a..d3e813428b 100644
>> --- a/libavcodec/version.h
>> +++ b/libavcodec/version.h
>> @@ -162,5 +162,8 @@
> 
> Missing minor version bump.

Entries in APIChanges, Changelog, and version bumps are many times 
skipped in patches to simplify rebasing and people applying for testing 
purposes since they will almost always end up conflicting with other 
changes pushed during the review phase, and are either added before 
pushing or in the last iteration of the patch.
Anton Khirnov March 8, 2021, 1:37 p.m. UTC | #3
Quoting Andreas Rheinhardt (2021-03-08 13:24:32)
> Anton Khirnov:
> > It is supported only by two decoders and is entirely redundant with
> > parsers.
> 
> Just because it is only used in two files doesn't mean it is only used
> by two decoders: Six decoders have the AV_CODEC_CAP_TRUNCATED (which you
> forgot to deprecate) set.
> 
> (fftools/cmdutils.c checks for AV_CODEC_CAP_TRUNCATED and informs the
> user about whether it is supported by a codec or not. It should probably
> be wrapped in #if LIBAVCODEC_VERSION_MAJOR < 60 checks.)
> 
> > ---
> >  doc/APIchanges             |  3 +++
> >  libavcodec/avcodec.h       |  4 ++++
> >  libavcodec/decode.c        |  6 +++++-
> >  libavcodec/h263dec.c       | 10 ++++++++--
> >  libavcodec/mpeg12dec.c     | 12 +++++++++++-
> >  libavcodec/mpegvideo.c     |  6 ++++++
> >  libavcodec/mpegvideo.h     |  2 ++
> >  libavcodec/options_table.h |  2 ++
> >  libavcodec/pthread.c       |  2 ++
> >  libavcodec/version.h       |  3 +++
> >  10 files changed, 46 insertions(+), 4 deletions(-)
> > 
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index 4027d599e7..344f484a8b 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -15,6 +15,9 @@ libavutil:     2017-10-21
> >  
> >  API changes, most recent first:
> >  
> > +2021-03-xx - xxxxxxxxxx - avcodec.h
> 
> Missing version
[...]
> > diff --git a/libavcodec/version.h b/libavcodec/version.h
> > index 169c763e8a..d3e813428b 100644
> > --- a/libavcodec/version.h
> > +++ b/libavcodec/version.h
> > @@ -162,5 +162,8 @@
> 
> Missing minor version bump.

That is intentional. I see no reason to bump version, because nothing in
the API or ABI changes with this patch.

We bump the version when new APIs are added to allow users to test
whether that API is present. But it makes no sense for the users to
check whether this flag (or anything else) is deprecated, since
deprecation is merely a declaration of intent to change something in the
future.
diff mbox series

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 4027d599e7..344f484a8b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@  libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2021-03-xx - xxxxxxxxxx - avcodec.h
+  Deprecate AV_CODEC_FLAG_TRUNCATED, as it is redundant with parsers.
+
 2021-03-04 - xxxxxxxxxx - lavc 58.128.101 - avcodec.h
   Enable err_recognition to be set for encoders.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 46d31b34ad..45929d6b05 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -310,11 +310,15 @@  typedef struct RcOverride{
  * error[?] variables will be set during encoding.
  */
 #define AV_CODEC_FLAG_PSNR            (1 << 15)
+#if FF_API_FLAG_TRUNCATED
 /**
  * Input bitstream might be truncated at a random location
  * instead of only at frame boundaries.
+ *
+ * @deprecated use codec parsers for packetizing input
  */
 #define AV_CODEC_FLAG_TRUNCATED       (1 << 16)
+#endif
 /**
  * Use interlaced DCT.
  */
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index c976795311..c00069b8d4 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -462,7 +462,11 @@  FF_ENABLE_DEPRECATION_WARNINGS
     if (!got_frame)
         av_frame_unref(frame);
 
-    if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))
+    if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO
+#if FF_API_FLAG_TRUNCATED
+        && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED)
+#endif
+        )
         ret = pkt->size;
 
 #if FF_API_AVCTX_TIMEBASE
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index dafa54d8d4..57d4a0d4e7 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -172,13 +172,17 @@  static int get_consumed_bytes(MpegEncContext *s, int buf_size)
         /* We would have to scan through the whole buf to handle the weird
          * reordering ... */
         return buf_size;
-    } else if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
+    }
+#if FF_API_FLAG_TRUNCATED
+    else if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
         pos -= s->parse_context.last_index;
         // padding is not really read so this might be -1
         if (pos < 0)
             pos = 0;
         return pos;
-    } else {
+    }
+#endif
+    else {
         // avoid infinite loops (maybe not needed...)
         if (pos == 0)
             pos = 1;
@@ -443,6 +447,7 @@  int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         return 0;
     }
 
+#if FF_API_FLAG_TRUNCATED
     if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
         int next;
 
@@ -462,6 +467,7 @@  int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
                              &buf_size) < 0)
             return buf_size;
     }
+#endif
 
 retry:
     if (s->divx_packed && s->bitstream_buffer_size) {
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 92dd6a0b24..9e1f9c4b79 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1267,10 +1267,14 @@  static int mpeg_decode_postinit(AVCodecContext *avctx)
         (s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
         0) {
         if (s1->mpeg_enc_ctx_allocated) {
+#if FF_API_FLAG_TRUNCATED
             ParseContext pc = s->parse_context;
             s->parse_context.buffer = 0;
             ff_mpv_common_end(s);
             s->parse_context = pc;
+#else
+            ff_mpv_common_end(s);
+#endif
             s1->mpeg_enc_ctx_allocated = 0;
         }
 
@@ -2506,7 +2510,11 @@  static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
             if (avctx->err_recognition & AV_EF_EXPLODE && s2->er.error_count)
                 return AVERROR_INVALIDDATA;
 
-            return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
+            return FFMAX(0, buf_ptr - buf
+#if FF_API_FLAG_TRUNCATED
+                         - s2->parse_context.last_index
+#endif
+                        );
         }
 
         input_size = buf_end - buf_ptr;
@@ -2812,6 +2820,7 @@  static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
         return buf_size;
     }
 
+#if FF_API_FLAG_TRUNCATED
     if (s2->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
         int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf,
                                            buf_size, NULL);
@@ -2820,6 +2829,7 @@  static int mpeg_decode_frame(AVCodecContext *avctx, void *data,
                              (const uint8_t **) &buf, &buf_size) < 0)
             return buf_size;
     }
+#endif
 
     s2->codec_tag = avpriv_toupper4(avctx->codec_tag);
     if (s->mpeg_enc_ctx_allocated == 0 && (   s2->codec_tag == AV_RL32("VCR2")
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 988dd18a33..45f42618e2 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -944,7 +944,9 @@  av_cold int ff_mpv_common_init(MpegEncContext *s)
     if ((ret = init_context_frame(s)))
         return AVERROR(ENOMEM);
 
+#if FF_API_FLAG_TRUNCATED
     s->parse_context.state = -1;
+#endif
 
     s->context_initialized = 1;
     memset(s->thread_context, 0, sizeof(s->thread_context));
@@ -1123,8 +1125,10 @@  void ff_mpv_common_end(MpegEncContext *s)
         s->slice_context_count = 1;
     } else free_duplicate_context(s);
 
+#if FF_API_FLAG_TRUNCATED
     av_freep(&s->parse_context.buffer);
     s->parse_context.buffer_size = 0;
+#endif
 
     av_freep(&s->bitstream_buffer);
     s->allocated_bitstream_buffer_size = 0;
@@ -2320,12 +2324,14 @@  void ff_mpeg_flush(AVCodecContext *avctx){
     s->mb_x= s->mb_y= 0;
     s->closed_gop= 0;
 
+#if FF_API_FLAG_TRUNCATED
     s->parse_context.state= -1;
     s->parse_context.frame_start_found= 0;
     s->parse_context.overread= 0;
     s->parse_context.overread_index= 0;
     s->parse_context.index= 0;
     s->parse_context.last_index= 0;
+#endif
     s->bitstream_buffer_size=0;
     s->pp_time=0;
 }
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 5a99c19656..0779a3d51a 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -359,7 +359,9 @@  typedef struct MpegEncContext {
     int mb_num_left;                 ///< number of MBs left in this video packet (for partitioned Slices only)
     int next_p_frame_damaged;        ///< set if the next p frame is damaged, to avoid showing trashed B-frames
 
+#if FF_API_FLAG_TRUNCATED
     ParseContext parse_context;
+#endif
 
     /* H.263 specific */
     int gob_index;
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index e12159f734..3202f68cd3 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -59,7 +59,9 @@  static const AVOption avcodec_options[] = {
 {"pass2", "use internal 2-pass ratecontrol in second pass mode", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"},
 {"gray", "only decode/encode grayscale", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"},
 {"psnr", "error[?] variables will be set during encoding", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"},
+#if FF_API_FLAG_TRUNCATED
 {"truncated", "Input bitstream might be randomly truncated", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, V|D, "flags"},
+#endif
 {"ildct", "use interlaced DCT", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_INTERLACED_DCT }, INT_MIN, INT_MAX, V|E, "flags"},
 {"low_delay", "force low delay", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_LOW_DELAY }, INT_MIN, INT_MAX, V|D|E, "flags"},
 {"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.i64 = AV_CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"},
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 572471586d..86c208e73e 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -46,7 +46,9 @@ 
 static void validate_thread_parameters(AVCodecContext *avctx)
 {
     int frame_threading_supported = (avctx->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)
+#if FF_API_FLAG_TRUNCATED
                                 && !(avctx->flags  & AV_CODEC_FLAG_TRUNCATED)
+#endif
                                 && !(avctx->flags  & AV_CODEC_FLAG_LOW_DELAY)
                                 && !(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS);
     if (avctx->thread_count == 1) {
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 169c763e8a..d3e813428b 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -162,5 +162,8 @@ 
 #ifndef FF_API_GET_FRAME_CLASS
 #define FF_API_GET_FRAME_CLASS     (LIBAVCODEC_VERSION_MAJOR < 60)
 #endif
+#ifndef FF_API_FLAG_TRUNCATED
+#define FF_API_FLAG_TRUNCATED      (LIBAVCODEC_VERSION_MAJOR < 60)
+#endif
 
 #endif /* AVCODEC_VERSION_H */