diff mbox series

[FFmpeg-devel] lavf/mpegts: Support mulaw audio in Lorex LNC recordings

Message ID CAB0OVGrCfeoDp_RPxcfUtvF=7K=jy7Qn14Q=75mJgRP9k4b02Q@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] lavf/mpegts: Support mulaw audio in Lorex LNC recordings | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate fail Make fate failed

Commit Message

Carl Eugen Hoyos Aug. 24, 2020, 7:56 p.m. UTC
Hi!

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

Please comment, Carl Eugen
Subject: [PATCH] lavf/mpegts: Support mulaw audio in Lorex LNC files.

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

Comments

Marton Balint Aug. 24, 2020, 8:51 p.m. UTC | #1
On Mon, 24 Aug 2020, Carl Eugen Hoyos wrote:

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

Please share some samples.

Thanks,
Marton
Carl Eugen Hoyos Aug. 24, 2020, 9:28 p.m. UTC | #2
Am Mo., 24. Aug. 2020 um 21:56 Uhr schrieb Carl Eugen Hoyos
<ceffmpeg@gmail.com>:

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

Sorry. this cannot work, not sure how to detect such recordings.

Carl Eugen
diff mbox series

Patch

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);