-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: hls support segments pretend to be gif & png
both headers contain ts sync byte 'G'. png: https://yundunm3.czys.art:88/vtt/gc02/sifangguan/sifangguan01.m3u8 gif: https://yun.366day.site/mp4hls/dmhls/dianwanka1.m3u8
- Loading branch information
Showing
3 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
patches/5.1/0032-hls-support-segments-pretend-to-be-gif-png.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
From bbaa08785c93082c71f18cbd4cbd46bab4609e22 Mon Sep 17 00:00:00 2001 | ||
From: wang-bin <[email protected]> | ||
Date: Sun, 29 Sep 2024 15:59:13 +0800 | ||
Subject: [PATCH 32/32] hls: support segments pretend to be gif & png | ||
|
||
--- | ||
libavformat/hls.c | 21 ++++++++++++++++++++- | ||
1 file changed, 20 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/libavformat/hls.c b/libavformat/hls.c | ||
index bf7fdc1553..4b9bfa082b 100644 | ||
--- a/libavformat/hls.c | ||
+++ b/libavformat/hls.c | ||
@@ -45,6 +45,7 @@ | ||
#include "id3v2.h" | ||
|
||
#include "hls_sample_encryption.h" | ||
+#include "libavcodec/gif.h" | ||
|
||
#define INITIAL_BUFFER_SIZE 32768 | ||
|
||
@@ -220,6 +221,7 @@ typedef struct HLSContext { | ||
AVIOInterruptCB *interrupt_callback; | ||
AVDictionary *avio_opts; | ||
AVDictionary *seg_format_opts; | ||
+ int seg_allow_img; | ||
char *allowed_extensions; | ||
int max_reload; | ||
int http_persistent; | ||
@@ -2101,7 +2103,22 @@ static int hls_read_header(AVFormatContext *s) | ||
pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE; | ||
pls->ctx->interrupt_callback = s->interrupt_callback; | ||
url = av_strdup(pls->segments[0]->url); | ||
- ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, 0, 0); | ||
+ unsigned skip = 0; | ||
+ if (!c->seg_allow_img) { | ||
+ uint8_t b[10] = { 0 }; | ||
+ avio_read(&pls->pb.pub, b, sizeof(b)); | ||
+ avio_seek(&pls->pb.pub, 0, SEEK_SET); | ||
+ if (AV_RB64(b) == 0x89504e470d0a1a0a) { | ||
+ skip = 3; | ||
+ av_log(s, AV_LOG_INFO, "segments pretend to be png\n"); | ||
+ } else if ((memcmp(b, gif87a_sig, 6) == 0 || memcmp(b, gif89a_sig, 6) == 0) | ||
+ && (AV_RL16(&b[6]) && AV_RL16(&b[8]))) { | ||
+ skip = 10; | ||
+ av_log(s, AV_LOG_INFO, "segments pretend to be gif\n"); | ||
+ } | ||
+ } | ||
+ | ||
+ ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, skip, 0); | ||
if (ret < 0) { | ||
/* Free the ctx - it isn't initialized properly at this point, | ||
* so avformat_close_input shouldn't be called. If | ||
@@ -2549,6 +2566,8 @@ static const AVOption hls_options[] = { | ||
OFFSET(http_seekable), AV_OPT_TYPE_BOOL, { .i64 = -1}, -1, 1, FLAGS}, | ||
{"seg_format_options", "Set options for segment demuxer", | ||
OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS}, | ||
+ {"seg_allow_img", "Allow segments detected as images, 0 = disable, 1 = enable", | ||
+ OFFSET(seg_allow_img), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, FLAGS}, | ||
{NULL} | ||
}; | ||
|
||
-- | ||
2.39.5 (Apple Git-154) | ||
|
65 changes: 65 additions & 0 deletions
65
patches/6.1/0032-hls-support-segments-pretend-to-be-gif-png.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
From 5b5b8a4c8a8af68d20bf3f60a47bfef62c5d5adc Mon Sep 17 00:00:00 2001 | ||
From: wang-bin <[email protected]> | ||
Date: Sun, 29 Sep 2024 15:59:13 +0800 | ||
Subject: [PATCH 32/32] hls: support segments pretend to be gif & png | ||
|
||
--- | ||
libavformat/hls.c | 21 ++++++++++++++++++++- | ||
1 file changed, 20 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/libavformat/hls.c b/libavformat/hls.c | ||
index f5f549b24d..c14676f1d5 100644 | ||
--- a/libavformat/hls.c | ||
+++ b/libavformat/hls.c | ||
@@ -46,6 +46,7 @@ | ||
#include "url.h" | ||
|
||
#include "hls_sample_encryption.h" | ||
+#include "libavcodec/gif.h" | ||
|
||
#define INITIAL_BUFFER_SIZE 32768 | ||
|
||
@@ -221,6 +222,7 @@ typedef struct HLSContext { | ||
AVIOInterruptCB *interrupt_callback; | ||
AVDictionary *avio_opts; | ||
AVDictionary *seg_format_opts; | ||
+ int seg_allow_img; | ||
char *allowed_extensions; | ||
int max_reload; | ||
int http_persistent; | ||
@@ -2104,7 +2106,22 @@ static int hls_read_header(AVFormatContext *s) | ||
pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE; | ||
pls->ctx->interrupt_callback = s->interrupt_callback; | ||
url = av_strdup(pls->segments[0]->url); | ||
- ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, 0, 0); | ||
+ unsigned skip = 0; | ||
+ if (!c->seg_allow_img) { | ||
+ uint8_t b[10] = { 0 }; | ||
+ avio_read(&pls->pb.pub, b, sizeof(b)); | ||
+ avio_seek(&pls->pb.pub, 0, SEEK_SET); | ||
+ if (AV_RB64(b) == 0x89504e470d0a1a0a) { | ||
+ skip = 3; | ||
+ av_log(s, AV_LOG_INFO, "segments pretend to be png\n"); | ||
+ } else if ((memcmp(b, gif87a_sig, 6) == 0 || memcmp(b, gif89a_sig, 6) == 0) | ||
+ && (AV_RL16(&b[6]) && AV_RL16(&b[8]))) { | ||
+ skip = 10; | ||
+ av_log(s, AV_LOG_INFO, "segments pretend to be gif\n"); | ||
+ } | ||
+ } | ||
+ | ||
+ ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, skip, 0); | ||
if (ret < 0) { | ||
/* Free the ctx - it isn't initialized properly at this point, | ||
* so avformat_close_input shouldn't be called. If | ||
@@ -2579,6 +2596,8 @@ static const AVOption hls_options[] = { | ||
OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS}, | ||
{"seg_max_retry", "Maximum number of times to reload a segment on error.", | ||
OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS}, | ||
+ {"seg_allow_img", "Allow segments detected as images, 0 = disable, 1 = enable", | ||
+ OFFSET(seg_allow_img), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, FLAGS}, | ||
{NULL} | ||
}; | ||
|
||
-- | ||
2.39.5 (Apple Git-154) | ||
|
65 changes: 65 additions & 0 deletions
65
patches/master/0030-hls-support-segments-pretend-to-be-gif-png.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
From ecda273842418e9827cab2a193138060a4224629 Mon Sep 17 00:00:00 2001 | ||
From: wang-bin <[email protected]> | ||
Date: Sun, 29 Sep 2024 15:59:13 +0800 | ||
Subject: [PATCH 30/30] hls: support segments pretend to be gif & png | ||
|
||
--- | ||
libavformat/hls.c | 21 ++++++++++++++++++++- | ||
1 file changed, 20 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/libavformat/hls.c b/libavformat/hls.c | ||
index 62473a15dd..2fd7f8ca2f 100644 | ||
--- a/libavformat/hls.c | ||
+++ b/libavformat/hls.c | ||
@@ -47,6 +47,7 @@ | ||
#include "url.h" | ||
|
||
#include "hls_sample_encryption.h" | ||
+#include "libavcodec/gif.h" | ||
|
||
#define INITIAL_BUFFER_SIZE 32768 | ||
|
||
@@ -222,6 +223,7 @@ typedef struct HLSContext { | ||
AVIOInterruptCB *interrupt_callback; | ||
AVDictionary *avio_opts; | ||
AVDictionary *seg_format_opts; | ||
+ int seg_allow_img; | ||
char *allowed_extensions; | ||
int max_reload; | ||
int http_persistent; | ||
@@ -2113,7 +2115,22 @@ static int hls_read_header(AVFormatContext *s) | ||
pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE; | ||
pls->ctx->interrupt_callback = s->interrupt_callback; | ||
url = av_strdup(pls->segments[0]->url); | ||
- ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, 0, 0); | ||
+ unsigned skip = 0; | ||
+ if (!c->seg_allow_img) { | ||
+ uint8_t b[10] = { 0 }; | ||
+ avio_read(&pls->pb.pub, b, sizeof(b)); | ||
+ avio_seek(&pls->pb.pub, 0, SEEK_SET); | ||
+ if (AV_RB64(b) == 0x89504e470d0a1a0a) { | ||
+ skip = 3; | ||
+ av_log(s, AV_LOG_INFO, "segments pretend to be png\n"); | ||
+ } else if ((memcmp(b, gif87a_sig, 6) == 0 || memcmp(b, gif89a_sig, 6) == 0) | ||
+ && (AV_RL16(&b[6]) && AV_RL16(&b[8]))) { | ||
+ skip = 10; | ||
+ av_log(s, AV_LOG_INFO, "segments pretend to be gif\n"); | ||
+ } | ||
+ } | ||
+ | ||
+ ret = av_probe_input_buffer(&pls->pb.pub, &in_fmt, url, NULL, skip, 0); | ||
if (ret < 0) { | ||
/* Free the ctx - it isn't initialized properly at this point, | ||
* so avformat_close_input shouldn't be called. If | ||
@@ -2590,6 +2607,8 @@ static const AVOption hls_options[] = { | ||
OFFSET(seg_format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS}, | ||
{"seg_max_retry", "Maximum number of times to reload a segment on error.", | ||
OFFSET(seg_max_retry), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS}, | ||
+ {"seg_allow_img", "Allow segments detected as images, 0 = disable, 1 = enable", | ||
+ OFFSET(seg_allow_img), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, FLAGS}, | ||
{NULL} | ||
}; | ||
|
||
-- | ||
2.39.5 (Apple Git-154) | ||
|