Skip to content

feat: Share lyrics as video with audio - #1918

Open
Kratosgado wants to merge 4 commits into
knighthat:mainfrom
Kratosgado:feat/share-lyrics-video
Open

feat: Share lyrics as video with audio#1918
Kratosgado wants to merge 4 commits into
knighthat:mainfrom
Kratosgado:feat/share-lyrics-video

Conversation

@Kratosgado

Copy link
Copy Markdown

Summary

Adds video sharing mode to the lyrics card feature. Users can now share selected lyrics as a short MP4 video with the actual audio from the song playing over the card.

Closes #1917

Note: This PR depends on #1916 (lyrics image card). Should be merged after that PR.

Changes

  • Audio extraction (AudioSegmentExtractor.kt): Reads audio from Media3 cache, transcodes Opus→AAC via MediaCodec, trims to the selected lyrics' timestamp range
  • Video encoding (LyricsVideoEncoder.kt): Encodes lyrics card bitmap as H.264 video frames via EGL/GLES20 surface rendering, muxes with audio using a two-pass strategy
  • UI toggle: Image/Video mode selector shown when synced lyrics are available
  • Share fixes: Fixed FileProvider permission grant using clipData, fixed recycled bitmap crash from Coil memory cache

Architecture

User selects lyrics → LRC timestamps → audio start/end
                                      ↓
                          Cache (Opus) → Decode → AAC encode → trimmed.m4a
                                      ↓
                    Lyrics card bitmap → H.264 encode → video.mp4
                                      ↓
                          Mux video.mp4 + trimmed.m4a → final.mp4
                                      ↓
                              Share via Intent (video/mp4)

Fallback behavior

If audio extraction or video encoding fails (song not cached, codec error), gracefully falls back to sharing as an image card.

Testing

  • Tested video generation with Opus audio from YouTube streams
  • Verified fallback to image on uncached songs
  • Build compiles cleanly

- Add video sharing mode alongside existing image card sharing
- Extract audio segment from Media3 cache with Opus→AAC transcoding
- Encode static lyrics card + audio into MP4 using MediaCodec
- Two-pass muxing strategy (video-only first, then mux with audio)
- Image/Video toggle in selection UI (shown when synced lyrics available)
- Fix FileProvider permission grant using clipData
- Fix recycled bitmap crash from Coil memory cache
- Add LyricsFrameRenderer for per-frame rendering with active line highlighted
- Three sharing modes: Image, Video (static), Animated (karaoke-style)
- Animated mode renders at 15fps with 1Mbps bitrate (~1.5-2MB for 10s)
- Active line: bold white 62px, inactive lines: dimmed 35% opacity 54px
- Pre-computed static background for efficient per-frame rendering
- Rename lyrics_share_as_image to lyrics_share
@knighthat

Copy link
Copy Markdown
Owner

thanks for the contribution. However, I'm working on a backend overhaul, so contributions aren't actively reviewed and accepted. I'll let you know once the overhaul is done

@Kratosgado

Copy link
Copy Markdown
Author

thanks for the contribution. However, I'm working on a backend overhaul, so contributions aren't actively reviewed and accepted. I'll let you know once the overhaul is done

alright

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.

feat: Share lyrics as video with audio

2 participants