How SmartTube Handles Video Codecs: AV1, HDR Detection, and AVI Support
SmartTube delegates all codec operations to a custom ExoPlayer fork, detecting HDR formats including AV1 and VP9.2 by inspecting codec strings, while treating AVI as unsupported since ExoPlayer lacks an AVI container parser.
SmartTube relies on ExoPlayer for media playback rather than implementing low-level codec logic itself. This architecture determines which video formats play successfully and how high dynamic range (HDR) metadata surfaces in the user interface, with specific handling for modern codecs like AV1 and legacy limitations such as AVI incompatibility.
Architecture Overview: ExoPlayer Fork and Codec Delegation
SmartTube does not implement native decoding logic. Instead, it uses a fork of ExoPlayer located in exoplayer-amzn-2.10.6. When a video is selected, the application builds an ExoPlayerController (see EmbedPlayerView.java). The controller receives FormatInfo or direct URLs (HLS, DASH, MP4) and forwards them to ExoPlayer.
The player's track selector determines which audio and video tracks are playable based on device-specific codec support reported by Android's MediaCodec API. This delegation means SmartTube supports any format that ExoPlayer understands but cannot play formats that ExoPlayer does not parse.
Container Support and Codec Limitations
Supported Streaming Containers
ExoPlayer parses modern streaming containers including MP4, WebM, MKV, HLS, and DASH. The MatroskaExtractor (found in exoplayer-amzn-2.10.6/library/core/src/main/java/com/google/android/exoplayer2/extractor/mkv/MatroskaExtractor.java) demonstrates MKV support, while other extractors handle the remaining formats. SmartTube inherits this compatibility automatically.
AVI Files Are Not Supported
ExoPlayer's core does not include an AVI container parser. Consequently, SmartTube cannot play AVI streams out-of-the-box. When an AVI URL reaches the controller, the track-selection step fails and the UI displays "no media" (see the containsMedia() check in EmbedPlayerView.java). Users must provide supported containers instead.
HDR Detection and AV1 Codec Handling
SmartTube adds a thin layer on top of ExoPlayer to surface HDR information to the UI. The helper class TrackSelectorUtil inspects codec strings to identify HDR-capable tracks.
How SmartTube Detects HDR Streams
The utility methods TrackSelectorUtil.buildHDRString() and TrackSelectorUtil.isHdrFormat() (lines 20-26 and 83-88) check for specific HDR identifiers:
- VP9 HDR:
"vp9.2" - AV1 HDR:
"10.0.110.09.18.09.0"or"10.0.110.09.16.09.0" - Generic HDR: any codec suffix ending with
"hdr"
When a track matches these patterns, the UI layer (TrackInfoFormatter2) appends the "HDR" label next to resolution and bit-rate information.
ExoPlayer HDR Compatibility Shim
The ExoPlayer fork contains a modification to ColorInfo.java (exoplayer-amzn-2.10.6/library/core/src/main/java/com/google/android/exoplayer2/video/ColorInfo.java) that supplies a placeholder static HDR info block (FAKE_HDR_STATIC_INFO). This prevents crashes on devices that expose HDR metadata but lack full implementations. Additionally, ExoPlayerInitializer.java contains a comment placeholder "HDR fix?" indicating where HDR-related MediaFormat keys are set (line 54).
Implementation Details and Code Examples
The following code demonstrates the core HDR detection logic and player initialization:
// Creating the player and controller – SmartTube delegates to ExoPlayer
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
ExoPlayerController controller = new ExoPlayerController(context, playbackPresenter);
controller.setPlayer(player);
controller.setTrackSelector(trackSelector);
The HDR detection utility inspects codec identifiers to determine format capabilities:
// HDR detection – core utility
public static boolean isHdrFormat(Format format) {
String codec = format.codecs;
return codec.equals(CODEC_PREFIX_VP9_HDR) ||
Helpers.endsWithAny(codec, CODEC_SUFFIX_AV1_HDR,
CODEC_SUFFIX_AV1_HDR2, HDR_PROFILE_ENDING);
}
For UI presentation, the formatter converts boolean detection into display labels:
// UI label – adds “HDR” when a track is HDR
public static String buildHDRString(Format format) {
return isHdrFormat(format) ? "HDR" : "";
}
Summary
- SmartTube delegates all codec handling to a custom ExoPlayer fork in
exoplayer-amzn-2.10.6. - AVI files are unsupported because ExoPlayer lacks an AVI parser, causing track selection to fail.
- HDR detection occurs in
TrackSelectorUtil.javaby inspecting codec strings for AV1 HDR ("10.0.110.09.18.09.0"), VP9 HDR ("vp9.2"), or generic"hdr"suffixes. - The UI displays HDR labels via
TrackInfoFormatter2when high dynamic range formats are detected. - A compatibility shim in
ColorInfo.javaprovidesFAKE_HDR_STATIC_INFOto prevent crashes on partially compatible HDR devices.
Frequently Asked Questions
Does SmartTube support AVI files?
No. SmartTube cannot play AVI streams because ExoPlayer does not include an AVI container parser. When an AVI URL is passed to the ExoPlayerController, the containsMedia() check fails and the interface displays "no media". Users must convert AVI files to supported containers like MP4, WebM, MKV, HLS, or DASH.
How does SmartTube detect HDR videos?
SmartTube detects HDR content in TrackSelectorUtil.java by analyzing codec strings. The isHdrFormat() method checks for specific identifiers including VP9 HDR ("vp9.2"), AV1 HDR profile strings ("10.0.110.09.18.09.0" or "10.0.110.09.16.09.0"), or any codec ending with the "hdr" suffix. When detected, TrackInfoFormatter2 adds an "HDR" label to the track description.
What HDR formats does SmartTube support?
According to the source code, SmartTube identifies HDR streams encoded with VP9 HDR profiles or AV1 HDR profiles. The detection relies on codec string parsing rather than metadata extraction, covering VP9.2 and specific AV1 HDR configurations. The actual rendering capability depends on the device's MediaCodec support and ExoPlayer's HDR shim (FAKE_HDR_STATIC_INFO in ColorInfo.java).
Where does SmartTube handle codec selection?
Codec selection occurs in the ExoPlayer track selector, initialized in EmbedPlayerView.java through the ExoPlayerController. The controller passes FormatInfo or URLs to ExoPlayer, which queries Android's MediaCodec API to determine hardware or software decoding capabilities. SmartTube's TrackSelectorUtil then filters tracks based on HDR compatibility and user preferences.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →