diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index efa8a9ac8d..c923b3e240 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2061,7 +2061,8 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
         memcpy(dst, pal, AVPALETTE_SIZE);
         return 1;
     } else if (pal) {
-        av_log(logctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
+        av_log(logctx, AV_LOG_ERROR,
+               "Palette size %"BUFFER_SPECIFIER" is wrong\n", size);
     }
     return 0;
 }
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index a05c2db6cb..771c9996a5 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -574,8 +574,8 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
                 put_bits(&s->pb, 8, 0xff);                  // marker_bits
             } else {
                 av_log(s->avctx, AV_LOG_WARNING,
-                    "Warning Closed Caption size (%d) can not exceed 93 bytes "
-                    "and must be a multiple of 3\n", side_data->size);
+                    "Closed Caption size (%"BUFFER_SPECIFIER") can not exceed "
+                    "93 bytes and must be a multiple of 3\n", side_data->size);
             }
         }
     }
diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c
index fe02649623..08ae8cdbad 100644
--- a/libavcodec/mscc.c
+++ b/libavcodec/mscc.c
@@ -160,7 +160,8 @@ static int decode_frame(AVCodecContext *avctx,
             for (j = 0; j < 256; j++)
                 s->pal[j] = 0xFF000000 | AV_RL32(pal + j * 4);
         } else if (pal) {
-            av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size);
+            av_log(avctx, AV_LOG_ERROR,
+                   "Palette size %"BUFFER_SPECIFIER" is wrong\n", size);
         }
         memcpy(frame->data[1], s->pal, AVPALETTE_SIZE);
     }
diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
index 9046e8d84a..e7b1d92e3d 100644
--- a/libavfilter/af_ashowinfo.c
+++ b/libavfilter/af_ashowinfo.c
@@ -170,7 +170,8 @@ static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd)
 
 static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd)
 {
-    av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size);
+    av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size "
+           "%"BUFFER_SPECIFIER" bytes", sd->type, sd->size);
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 6208892005..21577dce7e 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -314,7 +314,8 @@ static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const AVFrameSi
     int i;
 
     if (sd->size < uuid_size) {
-        av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))\n", sd->size, uuid_size);
+        av_log(ctx, AV_LOG_ERROR, "invalid data(%"BUFFER_SPECIFIER" < "
+               "UUID(%d-bytes))\n", sd->size, uuid_size);
         return;
     }
 
@@ -472,7 +473,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             av_log(ctx, AV_LOG_INFO, "pan/scan");
             break;
         case AV_FRAME_DATA_A53_CC:
-            av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size);
+            av_log(ctx, AV_LOG_INFO, "A/53 closed captions "
+                   "(%"BUFFER_SPECIFIER" bytes)", sd->size);
             break;
         case AV_FRAME_DATA_SPHERICAL:
             dump_spherical(ctx, frame, sd);
@@ -516,8 +518,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             dump_sei_unregistered_metadata(ctx, sd);
             break;
         default:
-            av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)\n",
-                   sd->type, sd->size);
+            av_log(ctx, AV_LOG_WARNING, "unknown side data type %d "
+                   "(%"BUFFER_SPECIFIER" bytes)\n", sd->type, sd->size);
             break;
         }
 
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 62ef5e9852..7b312f80a3 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -495,8 +495,8 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent)
             dump_s12m_timecode(ctx, st, sd);
             break;
         default:
-            av_log(ctx, AV_LOG_INFO,
-                   "unknown side data type %d (%d bytes)", sd->type, sd->size);
+            av_log(ctx, AV_LOG_INFO, "unknown side data type %d "
+                   "(%"BUFFER_SPECIFIER" bytes)", sd->type, sd->size);
             break;
         }
 
diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c
index 1fbe4aa4ee..7cd77db84a 100644
--- a/libavformat/framecrcenc.c
+++ b/libavformat/framecrcenc.c
@@ -88,7 +88,7 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
             case AV_PKT_DATA_SPHERICAL:
             case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
             case AV_PKT_DATA_S12M_TIMECODE:
-                for (int j = 0; j < sd->size / 4; j++) {
+                for (size_t j = 0; j < sd->size / 4; j++) {
                     uint8_t buf[4];
                     AV_WL32(buf, AV_RB32(sd->data + 4 * j));
                     side_data_crc = av_adler32_update(side_data_crc, buf, 4);
@@ -119,7 +119,8 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
             default:
                 side_data_crc = av_adler32_update(0, data, sd->size);
             }
-            av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08"PRIx32, pkt->side_data[i].size, side_data_crc);
+            av_strlcatf(buf, sizeof(buf), ", %8"BUFFER_SPECIFIER", 0x%08"PRIx32,
+                        pkt->side_data[i].size, side_data_crc);
         }
     }
     av_strlcatf(buf, sizeof(buf), "\n");
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index 1e9faf372a..578b425195 100644
--- a/libavformat/hashenc.c
+++ b/libavformat/hashenc.c
@@ -298,18 +298,19 @@ static int framehash_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     avio_write(s->pb, buf, strlen(buf));
 
     if (c->format_version > 1 && pkt->side_data_elems) {
-        int i, j;
+        int i;
         avio_printf(s->pb, ", S=%d", pkt->side_data_elems);
         for (i = 0; i < pkt->side_data_elems; i++) {
             av_hash_init(c->hashes[0]);
             if (HAVE_BIGENDIAN && pkt->side_data[i].type == AV_PKT_DATA_PALETTE) {
-                for (j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) {
+                for (size_t j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) {
                     uint32_t data = AV_RL32(pkt->side_data[i].data + j);
                     av_hash_update(c->hashes[0], (uint8_t *)&data, sizeof(uint32_t));
                 }
             } else
                 av_hash_update(c->hashes[0], pkt->side_data[i].data, pkt->side_data[i].size);
-            snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), ", %8d, ", pkt->side_data[i].size);
+            snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1),
+                     ", %8"BUFFER_SPECIFIER", ", pkt->side_data[i].size);
             len = strlen(buf);
             av_hash_final_hex(c->hashes[0], buf + len, sizeof(buf) - len);
             avio_write(s->pb, buf, strlen(buf));
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 4931988efd..73cbfca90e 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2170,7 +2170,8 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPac
     put_ebml_num(pb, track->track_num, track->track_num_size);
     avio_wb16(pb, ts - mkv->cluster_pts);
     avio_w8(pb, flags);
-    avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size, id, settings_size, settings, pkt->size, pkt->data);
+    avio_printf(pb, "%.*s\n%.*s\n%.*s", (int)id_size, id, (int)settings_size,
+                settings, pkt->size, pkt->data);
 
     put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, pkt->duration);
     end_ebml_master(pb, blockgroup);
diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c
index 8d2fdfed37..cf060bd011 100644
--- a/libavformat/webvttdec.c
+++ b/libavformat/webvttdec.c
@@ -78,7 +78,7 @@ static int webvtt_read_header(AVFormatContext *s)
         int64_t pos;
         AVPacket *sub;
         const char *p, *identifier, *settings;
-        int identifier_len, settings_len;
+        size_t identifier_len, settings_len;
         int64_t ts_start, ts_end;
 
         ff_subtitles_read_chunk(s->pb, &cue);
diff --git a/libavformat/webvttenc.c b/libavformat/webvttenc.c
index 552bc38b65..342cba6dd8 100644
--- a/libavformat/webvttenc.c
+++ b/libavformat/webvttenc.c
@@ -72,8 +72,13 @@ static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt)
     id = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_IDENTIFIER,
                                  &id_size);
 
-    if (id && id_size > 0)
-        avio_printf(pb, "%.*s\n", id_size, id);
+    if (id && id_size > 0) {
+#if !FF_API_BUFFER_SIZE_T
+        if (id_size > INT_MAX)
+            return AVERROR(ERANGE);
+#endif
+        avio_printf(pb, "%.*s\n", (int)id_size, id);
+    }
 
     webvtt_write_time(pb, pkt->pts);
     avio_printf(pb, " --> ");
@@ -82,8 +87,13 @@ static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt)
     settings = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_SETTINGS,
                                        &settings_size);
 
-    if (settings && settings_size > 0)
-        avio_printf(pb, " %.*s", settings_size, settings);
+    if (settings && settings_size > 0) {
+#if !FF_API_BUFFER_SIZE_T
+        if (id_size > INT_MAX)
+            return AVERROR(ERANGE);
+#endif
+        avio_printf(pb, " %.*s", (int)settings_size, settings);
+    }
 
     avio_printf(pb, "\n");
 
diff --git a/libavutil/internal.h b/libavutil/internal.h
index 572daefec3..989efeab5c 100644
--- a/libavutil/internal.h
+++ b/libavutil/internal.h
@@ -302,8 +302,10 @@ int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t time
 // Temporary typedef to simplify porting all AVBufferRef users to size_t
 #if FF_API_BUFFER_SIZE_T
 typedef int buffer_size_t;
+#define BUFFER_SPECIFIER "d"
 #else
 typedef size_t buffer_size_t;
+#define BUFFER_SPECIFIER SIZE_SPECIFIER
 #endif
 
 #endif /* AVUTIL_INTERNAL_H */
