[FFmpeg-devel] [PATCH 1/1] Added support to get specific periods from the mpeg-dash demuxer instead of just the longest one.
Louis Letourneau
lletourn49 at gmail.com
Wed Oct 23 19:57:14 EEST 2024
From: Louis Letourneau <lletourn49 at gmail.com>
---
libavformat/dashdec.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index a1d274f2f0..345454e6b6 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -150,6 +150,7 @@ typedef struct DASHContext {
int is_live;
AVIOInterruptCB *interrupt_callback;
+ int64_t period_index;
char *allowed_extensions;
AVDictionary *avio_opts;
int max_url_size;
@@ -1220,6 +1221,7 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
char *val = NULL;
uint32_t period_duration_sec = 0;
uint32_t period_start_sec = 0;
+ int64_t period_index = -1;
if (!in) {
close_in = 1;
@@ -1314,6 +1316,7 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
// at now we can handle only one period, with the longest duration
node = xmlFirstElementChild(node);
while (node) {
+ period_index++;
if (!av_strcasecmp(node->name, "Period")) {
period_duration_sec = 0;
period_start_sec = 0;
@@ -1328,13 +1331,15 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
attr = attr->next;
xmlFree(val);
}
- if ((period_duration_sec) >= (c->period_duration)) {
+ if ((period_duration_sec) >= (c->period_duration) || period_index == c->period_index) {
period_node = node;
c->period_duration = period_duration_sec;
c->period_start = period_start_sec;
if (c->period_start > 0)
c->media_presentation_duration = c->period_duration;
}
+ if(period_index == c->period_index)
+ break;
} else if (!av_strcasecmp(node->name, "ProgramInformation")) {
parse_programinformation(s, node);
}
@@ -1345,6 +1350,11 @@ static int parse_manifest(AVFormatContext *s, const char *url, AVIOContext *in)
ret = AVERROR_INVALIDDATA;
goto cleanup;
}
+ if(c->period_index > period_index) {
+ av_log(s, AV_LOG_ERROR, "Period index out of bounds. Asked '%ld' vs Highest period index '%ld'\n", c->period_index, period_index);
+ ret = AVERROR_INVALIDDATA;
+ goto cleanup;
+ }
adaptionset_node = xmlFirstElementChild(period_node);
while (adaptionset_node) {
@@ -2341,6 +2351,8 @@ static int dash_probe(const AVProbeData *p)
#define OFFSET(x) offsetof(DASHContext, x)
#define FLAGS AV_OPT_FLAG_DECODING_PARAM
static const AVOption dash_options[] = {
+ {"period_index", "Period to use in a multi period dash. If negative, the longest period is used",
+ OFFSET(period_index), AV_OPT_TYPE_INT64, {.i64 = -1}, INT_MIN, INT_MAX, FLAGS},
{"allowed_extensions", "List of file extensions that dash is allowed to access",
OFFSET(allowed_extensions), AV_OPT_TYPE_STRING,
{.str = "aac,m4a,m4s,m4v,mov,mp4,webm,ts"},
--
2.43.0
More information about the ffmpeg-devel
mailing list