Skip to content
abrignoniPublic

About

Rejoin the media Android apps cached through ExoPlayer: pieces joined in order, DASH streams joined from their cached manifest, video and audio put in one MP4 without re-encoding. One file, standard library only.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

exoprobe

Rejoins the media an Android app cached through ExoPlayer. One file, pure Python, standard library only. Read-only on the evidence: it writes only into the output folder you give it, and into a temporary copy of an index database it reads.

ExoPlayer (com.google.android.exoplayer2, now androidx.media3) is the media library most Android apps stream with, and it caches what they play. A cached video is not one file: it is split into pieces named for the byte offset they start at, and the address the video came from is kept in a separate index. Opening a piece on its own gives a truncated file at best. exoprobe reads the index, joins each item's pieces back into the file the app downloaded, joins a DASH or HLS stream's segments in the order its cached manifest or playlist lists them, and can put a video and its audio into one playable MP4 without re-encoding anything.

import exoprobe

for cache in exoprobe.find_caches("extraction/"):
    for record in exoprobe.rejoin(cache, "out/" + cache.root.replace("/", "_")):
        print(record["status"], record.get("file"), record.get("key"))

Command line

exoprobe scan   extraction/                  # every cache, item, key and state
exoprobe rejoin extraction/ -o out/          # the joined media, plus out/report.json
exoprobe mux    video.mp4 audio.m4a [more.m4a ...] -o combined.mp4

rejoin writes each cache into its own subfolder of out/ and records, for every item, which index named it, how many pieces were joined, how many bytes against the length the index recorded, whether the join is complete, and the last-touched time from the piece names. That time is when the piece was written, or later read again when the app's evictor asks ExoPlayer to track reads; a cache that also keeps an ExoPlayerCacheFileMetadata table records later reads there and leaves the name alone (SimpleCache.touchSpan).

In a window

python3 exoprobe_gui.py

exoprobe_gui.py is an optional tkinter window over the same command line, standard library only. Choose an evidence folder, then Scan to see its caches and items as a tree, or Rejoin into an output folder and double-click a file to open it. Mux... asks for a video, its audio and an output file. The window runs exoprobe.py and shows what it prints, so the results are the same either way.

It needs exoprobe_theme.py beside it (colours and the header, also standard library). The logo comes from assets/; without that folder the window opens with no logo. It starts in the system's light or dark mode where it can read it (macOS, Windows, and GNOME's setting on Linux), otherwise light, and the switch in its header changes it for that session.

What it reads

  • Pieces, <id>.<position>.<timestamp>.v3.exo in subfolders 0 to 9 of the cache folder, and the older <key>.<position>.<timestamp>.v2.exo (key escaped with %xx) and .v1.exo forms that carry the key in the name.
  • The index, either cached_content_index.exi (the .exi.bak wins when both are present, as ExoPlayer's AtomicFile restores it) or an ExoPlayerCacheIndex<uid> table in exoplayer_internal.db, matched to the cache by its <uid>.uid file. The database is read from a temporary copy with its -wal or -journal: even a read-only SQLite open rewrites the -shm beside the file it opens.
  • Metadata the index records per item: the full length (exo_len) and the address it was redirected to (exo_redir).
  • DASH manifests cached beside the segments. A stream is joined only from what the manifest lists, in its order: an initialization segment and then media segments up to the first one missing or incomplete. Addresses that merely look alike are never joined. A stream fetched as one file by byte range (SegmentBase) is already whole, and is paired with the other streams its manifest lists.
  • HLS playlists cached beside the segments, the same way: a media playlist's initialization segment (#EXT-X-MAP) and then its segments in order, every URI resolved against the playlist's own address as ExoPlayer requests it. A master playlist ties a video variant to its audio renditions by the variant's AUDIO group, and only that group's audio is combined with it. A playlist with encrypted segments (#EXT-X-KEY with a method other than NONE) or byte ranges is not joined, and a playlist with no initialization segment is joined only when its segments are MPEG transport streams, so a subtitles playlist (WebVTT) is left as it is.

The layout is taken from androidx/media 1.11.1 (8c6678b6), SimpleCacheSpan, CachedContentIndex, DefaultContentMetadata, for DASH DashManifestParser and DashUtil.resolveCacheKey, and for HLS HlsPlaylistParser and HlsMediaChunk.

Behaviours worth knowing

  • A gap ends the join. Pieces after it cannot be placed in a playable file without the bytes before them, so they are counted (pieces_left_out), not joined.
  • An item with no piece at position 0 is recorded, not written. Nothing in it can open.
  • Two pieces at one position: the one with the later last-touch time is used. When ExoPlayer touches a piece it renames the file to the new time (CachedContent.setLastTouchTimestamp) rather than adding one, so a live cache holds only one.
  • An encrypted index is named as such and no key is invented for its items.
  • An audio-only MP4 is audio, whatever its brand says, read from the track's own handler (hdlr).
  • mp4_layout tells what kind of MP4 a joined item is from its box headers: a movie header on its own (a DASH initialization segment cached alone, which holds no samples and cannot play), fragments, or a file that stops inside its last box.

Putting video and audio together

DASH, and HLS with separate audio renditions, serve video and sound as separate streams, so the cache holds a silent video and a picture-less audio track. mux rewrites the boxes that describe the tracks (ISO/IEC 14496-12) into one header and copies every sample's bytes unchanged, for fragmented MP4 (DASH and HLS) and for ordinary MP4 alike. An HLS video that already carries its own sound, as a transport stream does, is not combined.

When a manifest lists more than one cached audio stream, two languages say, picking one would be a guess, so every one goes in as its own track in the manifest's order. They share an alternate group and only the first is enabled, the marking ffmpeg writes for alternative languages, so a player that honours it starts on the first and offers the others. Each track's language is reported as the manifest writes it; the language field inside the file is copied from the cached stream unchanged. A whole-file video that is cut short is not combined, and a whole-file audio cut short is left out and counted.

The tests compare every combined file with its inputs frame by frame through ffmpeg's framemd5 where ffmpeg is installed, and always check the output's own boxes: every track declared, every input fragment present unchanged, every rewritten chunk offset pointing at the bytes it pointed at before.

What it does not do

  • A DASH stream described by a SegmentTemplate is not joined.
  • A transport-stream HLS video is joined into one .ts file but not converted to MP4.
  • An encrypted index (.exi flag 1) cannot be read without its key, which is not in the file. Encrypted media tracks (a sinf box) are not combined.
  • It reads only what an extraction holds: a video evicted from the cache is gone.

Standalone executables

Each release carries exoprobe and its window exoprobe_gui built as single executables with PyInstaller on Python 3.14, for Windows x64 and arm64, macOS on Apple silicon and Intel, and Linux x64 and arm64, beside exoprobe.py itself. The workflow that builds them (.github/workflows/build-executables.yml) runs each executable on caches built the way ExoPlayer writes them (a DASH stream, an HLS stream with two audio renditions, and an item indexed in exoplayer_internal.db) and on the mux fixtures, and requires it to write the same bytes as python exoprobe.py for scan, rejoin and mux before it is packaged with SHA256SUMS.txt and a README. The window re-enters itself with --cli to run the tool; the workflow runs the same comparison through that call and checks the window starts and stays up. The executables are not code signed; the README inside each archive says what Windows SmartScreen and macOS Gatekeeper will ask.

Licence

MIT. See LICENSE.

About

Rejoin the media Android apps cached through ExoPlayer: pieces joined in order, DASH streams joined from their cached manifest, video and audio put in one MP4 without re-encoding. One file, standard library only.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages