diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 2be06293098cf766d3cfb39102cf8fdf8e1b22ca..205bc1cad46b2d002401c7192d5fea6a03f3d288 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -910,8 +910,8 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
     }
 
     if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
-        if (par->bits_per_coded_sample)
-            bit_depth = par->bits_per_coded_sample;
+        if (par->bits_per_raw_sample)
+            bit_depth = par->bits_per_raw_sample;
         else
             bit_depth = av_get_bytes_per_sample(par->format) << 3;
     }