[FFmpeg-cvslog] avformat/flacdec: set time base for headerless flac

Paul B Mahol git at videolan.org
Sat Sep 9 13:03:55 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Wed Sep  6 02:04:10 2023 +0200| [5f8c113b75de9c2a7f49e337cd332abbf8adbb6e] | committer: Paul B Mahol

avformat/flacdec: set time base for headerless flac

Fixes #6396.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5f8c113b75de9c2a7f49e337cd332abbf8adbb6e
---

 libavformat/flacdec.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index b58ec03963..5104f23110 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -46,11 +46,16 @@ static void reset_index_position(int64_t metadata_head_size, AVStream *st)
         sti->index_entries[i].pos += metadata_head_size;
 }
 
+static const uint16_t sr_table[16] = {
+    0, 1764, 3528, 3840, 160, 320, 441, 480, 640, 882, 960, 1920, 0, 0, 0, 0
+};
+
 static int flac_read_header(AVFormatContext *s)
 {
     int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
     uint8_t header[4];
     uint8_t *buffer=NULL;
+    uint32_t marker;
     FLACDecContext *flac = s->priv_data;
     AVStream *st = avformat_new_stream(s, NULL);
     if (!st)
@@ -61,7 +66,11 @@ static int flac_read_header(AVFormatContext *s)
     /* the parameters will be extracted from the compressed bitstream */
 
     /* if fLaC marker is not found, assume there is no header */
-    if (avio_rl32(s->pb) != MKTAG('f','L','a','C')) {
+    marker = avio_rl32(s->pb);
+    if (marker != MKTAG('f','L','a','C')) {
+        const int sample_rate = 50 * sr_table[(marker >> 16) & 0xF];
+        if (sample_rate)
+            avpriv_set_pts_info(st, 64, 1, sample_rate);
         avio_seek(s->pb, -4, SEEK_CUR);
         return 0;
     }



More information about the ffmpeg-cvslog mailing list