[FFmpeg-devel] [PATCH] avcodec: Switch bitrate to 64bit with the bump

wm4 nfxjfg at googlemail.com
Wed Sep 2 22:55:42 CEST 2015


On Wed,  2 Sep 2015 22:20:40 +0200
Michael Niedermayer <michaelni at gmx.at> wrote:

> From: Michael Niedermayer <michael at niedermayer.cc>
> 
> a 32bit bitrate is insufficient for high resolution, high framerate material
> an example would be rawvideo
> 
> Not all changes are covered by #if as its easier to just push when the
> bump is done instead of making it coditional and removig the conditionallity
>  again
> 
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  doc/APIchanges                   |    3 +++
>  ffserver.c                       |    2 +-
>  libavcodec/avcodec.h             |   12 ++++++++++++
>  libavcodec/cook.c                |    2 +-
>  libavcodec/dcaenc.c              |    2 +-
>  libavcodec/libfdk-aacenc.c       |    2 +-
>  libavcodec/libgsmenc.c           |    2 +-
>  libavcodec/libopusenc.c          |    4 ++--
>  libavcodec/libspeexenc.c         |    4 ++--
>  libavcodec/mpegvideo_enc.c       |    2 +-
>  libavcodec/pcm-bluray.c          |    2 +-
>  libavcodec/pcm-dvd.c             |    2 +-
>  libavcodec/sipr.c                |    2 +-
>  libavcodec/utils.c               |    4 ++--
>  libavcodec/version.h             |    3 +++
>  libavcodec/wma.c                 |    2 +-
>  libavcodec/wmaenc.c              |    2 +-
>  libavformat/movenc.c             |    2 +-
>  libavformat/rdt.c                |    2 +-
>  libavformat/sdp.c                |    2 +-
>  libavformat/smoothstreamingenc.c |    6 +++---
>  libavformat/vqf.c                |    2 +-
>  22 files changed, 42 insertions(+), 24 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index aa92b69..e7380ff 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,9 @@ libavutil:     2014-08-09
>  
>  
>  API changes, most recent first:
> +2015-xx-xx -
> +  bit_rate/rc_max_rate/rc_min_rate where changed to 64bit, make sure you update
> +  any printf() or other type sensitive code
>  
>  2015-xx-xx - lavc 56.58.100 - vaapi.h
>    Deprecate old VA-API context (vaapi_context) fields that were only
> diff --git a/ffserver.c b/ffserver.c
> index 8b6e441..22d2156 100644
> --- a/ffserver.c
> +++ b/ffserver.c
> @@ -1787,7 +1787,7 @@ static inline void print_stream_params(AVIOContext *pb, FFServerStream *stream)
>              abort();
>          }
>  
> -        avio_printf(pb, "<tr><td align=right>%d<td>%s<td align=right>%d"
> +        avio_printf(pb, "<tr><td align=right>%d<td>%s<td align=right>%"PRId64
>                          "<td>%s<td>%s\n",
>                      i, type, st->codec->bit_rate/1000,
>                      codec ? codec->name : "", parameters);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 9d38b59..28c4353 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -1564,7 +1564,11 @@ typedef struct AVCodecContext {
>       * - decoding: Set by user, may be overwritten by libavcodec
>       *             if this info is available in the stream
>       */
> +#if FF_API_64BIT_BITRATE
>      int bit_rate;
> +#else
> +    int64_t bit_rate;
> +#endif

I wonder what's the purpose of this #if. If these fields are compiled
as int, all the av_log calls changed below will be incorrect.

I think you can change this without an ifdef. It's more of an ABI
change, rather than an API change, anyway.

Rest looks ok.

>  
>      /**
>       * number of bits the bitstream is allowed to diverge from the reference.
> @@ -2601,14 +2605,22 @@ typedef struct AVCodecContext {
>       * - encoding: Set by user.
>       * - decoding: Set by user, may be overwritten by libavcodec.
>       */
> +#if FF_API_64BIT_BITRATE
>      int rc_max_rate;
> +#else
> +    int64_t rc_max_rate;
> +#endif
>  
>      /**
>       * minimum bitrate
>       * - encoding: Set by user.
>       * - decoding: unused
>       */
> +#if FF_API_64BIT_BITRATE
>      int rc_min_rate;
> +#else
> +    int64_t rc_min_rate;
> +#endif
>  
>  #if FF_API_MPV_OPT
>      /**
> diff --git a/libavcodec/cook.c b/libavcodec/cook.c
> index 673896d..d8fb736 100644
> --- a/libavcodec/cook.c
> +++ b/libavcodec/cook.c
> @@ -1028,7 +1028,7 @@ static void dump_cook_context(COOKContext *q)
>      }
>      ff_dlog(q->avctx, "COOKContext\n");
>      PRINT("nb_channels", q->avctx->channels);
> -    PRINT("bit_rate", q->avctx->bit_rate);
> +    PRINT("bit_rate", (int)q->avctx->bit_rate);
>      PRINT("sample_rate", q->avctx->sample_rate);
>      PRINT("samples_per_channel", q->subpacket[0].samples_per_channel);
>      PRINT("subbands", q->subpacket[0].subbands);
> diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
> index 23587a7..9c5c17c 100644
> --- a/libavcodec/dcaenc.c
> +++ b/libavcodec/dcaenc.c
> @@ -145,7 +145,7 @@ static int encode_init(AVCodecContext *avctx)
>      c->samplerate_index = i;
>  
>      if (avctx->bit_rate < 32000 || avctx->bit_rate > 3840000) {
> -        av_log(avctx, AV_LOG_ERROR, "Bit rate %i not supported.", avctx->bit_rate);
> +        av_log(avctx, AV_LOG_ERROR, "Bit rate %"PRId64" not supported.", avctx->bit_rate);
>          return AVERROR(EINVAL);
>      }
>      for (i = 0; ff_dca_bit_rates[i] < avctx->bit_rate; i++)
> diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
> index 5df0c90..0e2051b 100644
> --- a/libavcodec/libfdk-aacenc.c
> +++ b/libavcodec/libfdk-aacenc.c
> @@ -215,7 +215,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>          }
>          if ((err = aacEncoder_SetParam(s->handle, AACENC_BITRATE,
>                                         avctx->bit_rate)) != AACENC_OK) {
> -            av_log(avctx, AV_LOG_ERROR, "Unable to set the bitrate %d: %s\n",
> +            av_log(avctx, AV_LOG_ERROR, "Unable to set the bitrate %"PRId64": %s\n",
>                     avctx->bit_rate, aac_get_error(err));
>              goto error;
>          }
> diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c
> index 45fdb8e..e25db95 100644
> --- a/libavcodec/libgsmenc.c
> +++ b/libavcodec/libgsmenc.c
> @@ -62,7 +62,7 @@ static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
>      if (avctx->bit_rate != 13000 /* Official */ &&
>          avctx->bit_rate != 13200 /* Very common */ &&
>          avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) {
> -        av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n",
> +        av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %"PRId64"bps\n",
>                 avctx->bit_rate);
>          if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
>              return -1;
> diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
> index a170b71..5f63930 100644
> --- a/libavcodec/libopusenc.c
> +++ b/libavcodec/libopusenc.c
> @@ -180,11 +180,11 @@ static av_cold int libopus_encode_init(AVCodecContext *avctx)
>          avctx->bit_rate = 64000 * opus->stream_count +
>                            32000 * coupled_stream_count;
>          av_log(avctx, AV_LOG_WARNING,
> -               "No bit rate set. Defaulting to %d bps.\n", avctx->bit_rate);
> +               "No bit rate set. Defaulting to %"PRId64" bps.\n", avctx->bit_rate);
>      }
>  
>      if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * avctx->channels) {
> -        av_log(avctx, AV_LOG_ERROR, "The bit rate %d bps is unsupported. "
> +        av_log(avctx, AV_LOG_ERROR, "The bit rate %"PRId64" bps is unsupported. "
>                 "Please choose a value between 500 and %d.\n", avctx->bit_rate,
>                 256000 * avctx->channels);
>          return AVERROR(EINVAL);
> diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
> index fbc1738..c369443 100644
> --- a/libavcodec/libspeexenc.c
> +++ b/libavcodec/libspeexenc.c
> @@ -125,10 +125,10 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
>          av_log(avctx, AV_LOG_DEBUG, "  quality: %f\n", s->vbr_quality);
>      } else if (s->abr) {
>          av_log(avctx, AV_LOG_DEBUG, "rate control: ABR\n");
> -        av_log(avctx, AV_LOG_DEBUG, "  bitrate: %d bps\n", avctx->bit_rate);
> +        av_log(avctx, AV_LOG_DEBUG, "  bitrate: %"PRId64" bps\n", avctx->bit_rate);
>      } else {
>          av_log(avctx, AV_LOG_DEBUG, "rate control: CBR\n");
> -        av_log(avctx, AV_LOG_DEBUG, "  bitrate: %d bps\n", avctx->bit_rate);
> +        av_log(avctx, AV_LOG_DEBUG, "  bitrate: %"PRId64" bps\n", avctx->bit_rate);
>      }
>      av_log(avctx, AV_LOG_DEBUG, "complexity: %d\n",
>             avctx->compression_level);
> diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
> index 488ec51..a4f4daa 100644
> --- a/libavcodec/mpegvideo_enc.c
> +++ b/libavcodec/mpegvideo_enc.c
> @@ -482,7 +482,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          avctx->bit_rate * av_q2d(avctx->time_base) >
>              avctx->bit_rate_tolerance) {
>          av_log(avctx, AV_LOG_WARNING,
> -               "bitrate tolerance %d too small for bitrate %d, overriding\n", avctx->bit_rate_tolerance, avctx->bit_rate);
> +               "bitrate tolerance %d too small for bitrate %"PRId64", overriding\n", avctx->bit_rate_tolerance, avctx->bit_rate);
>          avctx->bit_rate_tolerance = 5 * avctx->bit_rate * av_q2d(avctx->time_base);
>      }
>  
> diff --git a/libavcodec/pcm-bluray.c b/libavcodec/pcm-bluray.c
> index e7f9ee4..517d7b5 100644
> --- a/libavcodec/pcm-bluray.c
> +++ b/libavcodec/pcm-bluray.c
> @@ -117,7 +117,7 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
>  
>      if (avctx->debug & FF_DEBUG_PICT_INFO)
>          ff_dlog(avctx,
> -                "pcm_bluray_parse_header: %d channels, %d bits per sample, %d Hz, %d bit/s\n",
> +                "pcm_bluray_parse_header: %d channels, %d bits per sample, %d Hz, %"PRId64" bit/s\n",
>                  avctx->channels, avctx->bits_per_coded_sample,
>                  avctx->sample_rate, avctx->bit_rate);
>      return 0;
> diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
> index 985a19b..c2fb64f 100644
> --- a/libavcodec/pcm-dvd.c
> +++ b/libavcodec/pcm-dvd.c
> @@ -140,7 +140,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
>  
>      if (avctx->debug & FF_DEBUG_PICT_INFO)
>          ff_dlog(avctx,
> -                "pcm_dvd_parse_header: %d channels, %d bits per sample, %d Hz, %d bit/s\n",
> +                "pcm_dvd_parse_header: %d channels, %d bits per sample, %d Hz, %"PRId64" bit/s\n",
>                  avctx->channels, avctx->bits_per_coded_sample,
>                  avctx->sample_rate, avctx->bit_rate);
>  
> diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
> index eb8b471..40332f4 100644
> --- a/libavcodec/sipr.c
> +++ b/libavcodec/sipr.c
> @@ -493,7 +493,7 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
>          else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5;
>          else                              ctx->mode = MODE_5k0;
>          av_log(avctx, AV_LOG_WARNING,
> -               "Invalid block_align: %d. Mode %s guessed based on bitrate: %d\n",
> +               "Invalid block_align: %d. Mode %s guessed based on bitrate: %"PRId64"\n",
>                 avctx->block_align, modes[ctx->mode].mode_name, avctx->bit_rate);
>      }
>  
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index f51070c..0f2cf1d 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1643,7 +1643,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          }
>          if (   (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
>              && avctx->bit_rate>0 && avctx->bit_rate<1000) {
> -            av_log(avctx, AV_LOG_WARNING, "Bitrate %d is extremely low, maybe you mean %dk\n", avctx->bit_rate, avctx->bit_rate);
> +            av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate);
>          }
>  
>          if (!avctx->rc_initial_buffer_occupancy)
> @@ -3253,7 +3253,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
>                   ", %d kb/s", bitrate / 1000);
>      } else if (enc->rc_max_rate > 0) {
>          snprintf(buf + strlen(buf), buf_size - strlen(buf),
> -                 ", max. %d kb/s", enc->rc_max_rate / 1000);
> +                 ", max. %"PRId64" kb/s", enc->rc_max_rate / 1000);
>      }
>  }
>  
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 6dbeeff..a6b3900 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -175,6 +175,9 @@
>  #ifndef FF_API_AFD
>  #define FF_API_AFD               (LIBAVCODEC_VERSION_MAJOR < 57)
>  #endif
> +#ifndef FF_API_64BIT_BITRATE
> +#define FF_API_64BIT_BITRATE     (LIBAVCODEC_VERSION_MAJOR < 57)
> +#endif
>  #ifndef FF_API_VISMV
>  /* XXX: don't forget to drop the -vismv documentation */
>  #define FF_API_VISMV             (LIBAVCODEC_VERSION_MAJOR < 57)
> diff --git a/libavcodec/wma.c b/libavcodec/wma.c
> index 006d8d5..6a330c2 100644
> --- a/libavcodec/wma.c
> +++ b/libavcodec/wma.c
> @@ -185,7 +185,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
>              high_freq = high_freq * 0.5;
>      }
>      ff_dlog(s->avctx, "flags2=0x%x\n", flags2);
> -    ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
> +    ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%"PRId64" block_align=%d\n",
>              s->version, avctx->channels, avctx->sample_rate, avctx->bit_rate,
>              avctx->block_align);
>      ff_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
> diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
> index fc23d4e..f850922 100644
> --- a/libavcodec/wmaenc.c
> +++ b/libavcodec/wmaenc.c
> @@ -50,7 +50,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
>  
>      if (avctx->bit_rate < 24 * 1000) {
>          av_log(avctx, AV_LOG_ERROR,
> -               "bitrate too low: got %i, need 24000 or higher\n",
> +               "bitrate too low: got %"PRId64", need 24000 or higher\n",
>                 avctx->bit_rate);
>          return AVERROR(EINVAL);
>      }
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index 08d0c2a..5605003 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -3296,7 +3296,7 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov)
>          } else {
>              continue;
>          }
> -        avio_printf(pb, "<%s systemBitrate=\"%d\">\n", type,
> +        avio_printf(pb, "<%s systemBitrate=\"%"PRId64"\">\n", type,
>                                                         track->enc->bit_rate);
>          param_write_int(pb, "systemBitrate", track->enc->bit_rate);
>          param_write_int(pb, "trackID", track_id);
> diff --git a/libavformat/rdt.c b/libavformat/rdt.c
> index 046d273..c3ac198 100644
> --- a/libavformat/rdt.c
> +++ b/libavformat/rdt.c
> @@ -448,7 +448,7 @@ real_parse_asm_rule(AVStream *st, const char *p, const char *end)
>  {
>      do {
>          /* can be either averagebandwidth= or AverageBandwidth= */
> -        if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%d", &st->codec->bit_rate) == 1)
> +        if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%"SCNd64, &st->codec->bit_rate) == 1)
>              break;
>          if (!(p = strchr(p, ',')) || p > end)
>              p = end;
> diff --git a/libavformat/sdp.c b/libavformat/sdp.c
> index 45974b3..808b62d 100644
> --- a/libavformat/sdp.c
> +++ b/libavformat/sdp.c
> @@ -740,7 +740,7 @@ void ff_sdp_write_media(char *buff, int size, AVStream *st, int idx,
>      av_strlcatf(buff, size, "m=%s %d RTP/AVP %d\r\n", type, port, payload_type);
>      sdp_write_address(buff, size, dest_addr, dest_type, ttl);
>      if (c->bit_rate) {
> -        av_strlcatf(buff, size, "b=AS:%d\r\n", c->bit_rate / 1000);
> +        av_strlcatf(buff, size, "b=AS:%"PRId64"\r\n", c->bit_rate / 1000);
>      }
>  
>      sdp_write_media_attributes(buff, size, c, payload_type, fmt);
> diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
> index 07173a9..5a267cc 100644
> --- a/libavformat/smoothstreamingenc.c
> +++ b/libavformat/smoothstreamingenc.c
> @@ -260,7 +260,7 @@ static int write_manifest(AVFormatContext *s, int final)
>              if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_VIDEO)
>                  continue;
>              last = i;
> -            avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->width, s->streams[i]->codec->height, os->private_str);
> +            avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%"PRId64"\" FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->width, s->streams[i]->codec->height, os->private_str);
>              index++;
>          }
>          output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size);
> @@ -274,7 +274,7 @@ static int write_manifest(AVFormatContext *s, int final)
>              if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO)
>                  continue;
>              last = i;
> -            avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->sample_rate, s->streams[i]->codec->channels, os->packet_size, os->audio_tag, os->private_str);
> +            avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%"PRId64"\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->sample_rate, s->streams[i]->codec->channels, os->packet_size, os->audio_tag, os->private_str);
>              index++;
>          }
>          output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size);
> @@ -321,7 +321,7 @@ static int ism_write_header(AVFormatContext *s)
>              ret = AVERROR(EINVAL);
>              goto fail;
>          }
> -        snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%d)", s->filename, s->streams[i]->codec->bit_rate);
> +        snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%"PRId64")", s->filename, s->streams[i]->codec->bit_rate);
>          if (mkdir(os->dirname, 0777) == -1 && errno != EEXIST) {
>              ret = AVERROR(errno);
>              av_log(s, AV_LOG_ERROR, "mkdir failed\n");
> diff --git a/libavformat/vqf.c b/libavformat/vqf.c
> index 29c726d..d8fbc20 100644
> --- a/libavformat/vqf.c
> +++ b/libavformat/vqf.c
> @@ -211,7 +211,7 @@ static int vqf_read_header(AVFormatContext *s)
>          size = 2048;
>          break;
>      default:
> -        av_log(s, AV_LOG_ERROR, "Mode not suported: %d Hz, %d kb/s.\n",
> +        av_log(s, AV_LOG_ERROR, "Mode not suported: %d Hz, %"PRId64" kb/s.\n",
>                 st->codec->sample_rate, st->codec->bit_rate);
>          return -1;
>      }



More information about the ffmpeg-devel mailing list