Skip to content

fix: support rich:video (transcoded external media) and CMAF format#549

Open
ddmunhoz wants to merge 1 commit intoredlib-org:mainfrom
ddmunhoz:fix-dash-cmaf-bugs-live
Open

fix: support rich:video (transcoded external media) and CMAF format#549
ddmunhoz wants to merge 1 commit intoredlib-org:mainfrom
ddmunhoz:fix-dash-cmaf-bugs-live

Conversation

@ddmunhoz
Copy link
Copy Markdown

This PR addresses the issue where Gifs and other third-party video providers (flagged by Reddit as rich:video) fail to load or display a video player.

The problem revolves around Reddit has shifted how it handles external video embeds. Instead of just providing an oembed/iframe, it now transcodes many of these videos into its own v.redd.it infrastructure maybe for better mobile perf ? who knows ? These new transcodes differ from standard Reddit videos in two ways:

  1. They are categorized in the API under the post_hint: "rich:video" instead of the standard "video" hint.
  2. They use the CMAF (Common Media Application Format) AKA newer standard container, instead of the older DASH format. This manifests in the URL as a CMAF_ prefix (e.g., CMAF_1080.mp4) rather than the DASH_ prefix Redlib expects.

Because Redlib was looking specifically for DASH_ in both its regex logic and its proxy routing, these videos were being ignored or resulting in 404/403 errors when the browser tried to load them without the proxy.

Overall the changes are:

  • src/utils.rs:
    • Updated Media::parse to support the rich:video post hint. It now attempts to extract the video data from the reddit_video_preview object which contains the Reddit-hosted fallback URLs.
    • Updated REGEX_URL_VIDEOS to support both DASH_ and CMAF_ prefixes.
    • Updated format_url to handle a 3-segment structure for video proxies (/vid/ID/PREFIX/SIZE), allowing the format prefix to be passed dynamically to the proxy.
    • Added tests for coverage.
  • src/main.rs:
    • Refactored the /vid/ proxy route to be generic. It no longer hardcodes DASH_ and instead accepts a :prefix parameter. This makes the proxy futureproof for any other formats Reddit might introduce (like HLS_).

I tested on r/highqualitygifs and r/gifs, which appeared to be the biggest "offenders" using the CMAF container. Everything clicks.

Fix: #20
Simpler/safer approach over PR: #507 which focuses on fixing one edge case while adding a lot of dependencies/brittle code, since any API change will break this specific implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡 Feature request: redgifs support

1 participant