diff --git a/doc/APIchanges b/doc/APIchanges
index c55dfe81625170133d6098399dd3fbe118eacb6b..efdb81c2d0f1f55fcb5c4877e39044924841b639 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,13 +15,15 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2015-10-29 - lavc 57.12.100 / 57.8.0 - avcodec.h
+  xxxxxx - Deprecate av_free_packet(). Use av_packet_unref() as replacement,
+           it resets the packet in a more consistent way.
+  xxxxxx - Deprecate av_dup_packet(), it is a no-op for most cases.
+           Use av_packet_ref() to make a non-refcounted AVPacket refcounted.
+
 2015-10-27 - xxxxxxx - lavu 55.5.100 - cpu.h
   Add AV_CPU_FLAG_AESNI.
 
-2015-10-27 - xxxxxxx - lavc 57.12.100 / 57.8.0 - avcodec.h
-  Deprecate av_free_packet(). Use av_packet_unref() as replacement,
-  it resets the packet in a more consistent way.
-
 2015-10-22 - xxxxxxx - lavc 57.9.100 / lavc 57.5.0 - avcodec.h
   Add data and linesize array to AVSubtitleRect, to be used instead of
   the ones from the embedded AVPicture.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c4104cfa6c122dbe94ea003cf29202b283b308ed..936d9fe2402ddf8dd3c1b22d64cfd1a93c580720 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3898,12 +3898,15 @@ int av_grow_packet(AVPacket *pkt, int grow_by);
  */
 int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
 
+#if FF_API_AVPACKET_OLD_API
 /**
  * @warning This is a hack - the packet memory allocation stuff is broken. The
  * packet is allocated if it was not really allocated.
+ *
+ * @deprecated Use av_packet_ref
  */
+attribute_deprecated
 int av_dup_packet(AVPacket *pkt);
-#if FF_API_AVPACKET_OLD_API
 /**
  * Copy packet, including contents
  *
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index a87150ed823aac84f163ee30766c9d44ac7ab429..34ef2659ef26b3edb7dee3602be308249b70c7b8 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -130,6 +130,8 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
     return 0;
 }
 
+#if FF_API_AVPACKET_OLD_API
+FF_DISABLE_DEPRECATION_WARNINGS
 #define ALLOC_MALLOC(data, size) data = av_malloc(size)
 #define ALLOC_BUF(data, size)                \
 do {                                         \
@@ -207,6 +209,8 @@ failed_alloc:
     av_packet_unref(pkt);
     return AVERROR(ENOMEM);
 }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
 
 int av_dup_packet(AVPacket *pkt)
 {
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index b41888f3353dacd94101730ba87a7deea8cf71c8..10cf0a034b7e5cc27a855e3e1d2b19b466e143a3 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1945,15 +1945,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
     // buffer an audio packet to ensure the packet containing the video
     // keyframe's timecode is contained in the same cluster for WebM
     if (codec_type == AVMEDIA_TYPE_AUDIO) {
-        mkv->cur_audio_pkt = *pkt;
-        if (pkt->buf) {
-            mkv->cur_audio_pkt.buf = av_buffer_ref(pkt->buf);
-            ret = mkv->cur_audio_pkt.buf ? 0 : AVERROR(ENOMEM);
-        } else
-            ret = av_dup_packet(&mkv->cur_audio_pkt);
-        if (mkv->cur_audio_pkt.side_data_elems > 0) {
-            ret = av_copy_packet_side_data(&mkv->cur_audio_pkt, &mkv->cur_audio_pkt);
-        }
+        ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
     } else
         ret = mkv_write_packet_internal(s, pkt, 0);
     return ret;
diff --git a/libavformat/mux.c b/libavformat/mux.c
index b2d843bc38a321e4c491b997022fe3085366d2c2..bf7a47296c9527f4b5a4e02cac8ab066c2bb2d57 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -740,19 +740,14 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
     this_pktl      = av_mallocz(sizeof(AVPacketList));
     if (!this_pktl)
         return AVERROR(ENOMEM);
-    this_pktl->pkt = *pkt;
-    pkt->buf       = NULL;
-    pkt->side_data = NULL;
-    pkt->side_data_elems = 0;
     if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
         av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE);
         av_assert0(((AVFrame *)pkt->data)->buf);
-    } else {
-        // Duplicate the packet if it uses non-allocated memory
-        if ((ret = av_dup_packet(&this_pktl->pkt)) < 0) {
-            av_free(this_pktl);
-            return ret;
-        }
+    }
+
+    if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) {
+        av_free(this_pktl);
+        return ret;
     }
 
     if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
@@ -803,6 +798,8 @@ next_non_null:
     s->streams[pkt->stream_index]->last_in_packet_buffer =
         *next_point                                      = this_pktl;
 
+    av_packet_unref(pkt);
+
     return 0;
 }