Hi!

Attached patch allows audio decoding in Lorex LNC recordings, tested
with hi- and low-res files.

Please comment, Carl Eugen
From 4ade92cd6612a21226ea42113bb66deacfd2b8e1 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffm...@gmail.com>
Date: Mon, 24 Aug 2020 21:52:52 +0200
Subject: [PATCH] lavf/mpegts: Support mulaw audio in Lorex LNC files.

---
 libavformat/mpegts.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 50d4d5e9bc..b159d40368 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -153,6 +153,8 @@ struct MpegTSContext {
 
     int resync_size;
     int merge_pmt_versions;
+    /* Lorex LNC crf file */
+    int lorex_crf;
 
     /******************************************/
     /* private mpegts data */
@@ -860,6 +862,10 @@ static const StreamType METADATA_types[] = {
     { 0 },
 };
 
+static const StreamType crf_types[] = {
+    { 0x06, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_MULAW },
+};
+
 /* descriptor present */
 static const StreamType DESC_types[] = {
     { 0x6a, AVMEDIA_TYPE_AUDIO,    AV_CODEC_ID_AC3          }, /* AC-3 descriptor */
@@ -947,6 +953,12 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes,
     }
     if (st->codecpar->codec_id == AV_CODEC_ID_NONE)
         mpegts_find_stream_type(st, pes->stream_type, MISC_types);
+    if (pes->ts->lorex_crf && st->codecpar->codec_id == AV_CODEC_ID_NONE)
+        mpegts_find_stream_type(st, pes->stream_type, crf_types);
+    if (st->codecpar->codec_id == AV_CODEC_ID_PCM_MULAW) {
+        st->codecpar->channels = 1;
+        st->codecpar->sample_rate = 8000;
+    }
     if (st->codecpar->codec_id == AV_CODEC_ID_NONE) {
         st->codecpar->codec_id  = old_codec_id;
         st->codecpar->codec_type = old_codec_type;
@@ -3054,8 +3066,13 @@ static int mpegts_read_header(AVFormatContext *s)
 
     s->internal->prefer_codec_framerate = 1;
 
-    if (ffio_ensure_seekback(pb, probesize) < 0)
+    if (ffio_ensure_seekback(pb, probesize) < 0) {
         av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n");
+    } else {
+        if ((avio_rb64(pb) & 0xFFFFFF00FFFFFFFF) == 0x474011000042b025)
+            ts->lorex_crf = 1;
+        avio_seek(pb, -8, SEEK_CUR);
+    }
 
     pos = avio_tell(pb);
     ts->raw_packet_size = get_packet_size(s);
-- 
2.24.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to