[vlc-devel] [vlc-commits] ytdl: stream filter module for YoutubeDL

Pierre Ynard linkfanel at yahoo.fr
Tue Sep 29 05:44:08 CEST 2020


> +     const struct json_object *best_fmt = NULL;
> +     double pref_height = var_InheritInteger(s, "preferred-resolution");
> +     double best_height = -1.;
> +     double best_abr = -1.;
> +
> +     for (size_t i = 0; i < fmts->array.size; i++) {
> +         const struct json_value *v = &fmts->array.entries[i];
> +
> +         if (v->type != JSON_OBJECT)
> +             continue;
> +
> +         const struct json_object *fmt = &v->object;
> +         double height = json_get_num(fmt, "height");
> +         double abr = json_get_num(fmt, "abr");
> +
> +         if (!isgreaterequal(height, best_height)
> +          || (best_height < pref_height && pref_height < height))
> +             continue;
> +
> +         if (!isgreaterequal(abr, best_abr))
> +             continue;
> +
> +         best_fmt = fmt;
> +         best_height = height;
> +         best_abr = abr;
> +     }

This is confusing. First not everybody knows what isgreaterequal() is,
nor what the point is of using it here (presumably to reject NAN), nor
why and how we need to handle NAN (presumably because some platforms,
like YouTube, offer audio- and video-only streams that we aren't
interested in stitching back together). Maybe it's worth a comment.

But I don't understand the resolution selection logic. I don't think
it's right. You will want to pick a lower resolution than the current
best one, if the current best one is above the preferred resolution
limit. As for the second line I'm even less sure, but if you set
--preferred-resolution to the lowest possible - 0, or anything lower
than any available format - it looks to me like it will fail to pick a
format instead of picking the lowest resolution available.

It's also unclear whether the code makes the assumption that formats are
sorted in a particular order, and whether that assumption can be made.
In my experience it can be made for some websites at some time; I don't
know if youtube-dl enforces any ordering. youtube.lua contains format
selection logic examples for both cases (one legacy, one current).

As for the audio, I'm seeing several websites, for example vimeo or
dailymotion, for which I can't see the abr field ever set. So if I
understood correctly, those are always going to fail. My experience
gives me no suggestion to offer for audio selection.

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."


More information about the vlc-devel mailing list