### Setup MediaPlayer Component in Unity C# Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Demonstrates how to initialize and configure a MediaPlayer component in Unity using C#. Covers basic playback settings, audio, visual quality, and resampler options. This script should be attached to a GameObject with a MediaPlayer component. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class MediaPlayerSetup : MonoBehaviour { void Start() { // Create MediaPlayer via GameObject menu: GameObject > Video > AVPro Video - MediaPlayer MediaPlayer mediaPlayer = GetComponent(); // Configure basic playback settings mediaPlayer.AutoOpen = true; mediaPlayer.AutoPlay = true; mediaPlayer.Loop = true; mediaPlayer.PlaybackRate = 1.0f; // Configure audio mediaPlayer.AudioVolume = 0.8f; mediaPlayer.AudioBalance = 0f; mediaPlayer.AudioMuted = false; // Configure visual quality mediaPlayer.TextureFilterMode = FilterMode.Bilinear; mediaPlayer.TextureWrapMode = TextureWrapMode.Clamp; mediaPlayer.TextureAnisoLevel = 1; // Enable video frame resampler for smooth playback mediaPlayer.UseResampler = true; mediaPlayer.ResampleMode = Resampler.SampleMode.POINT; } } ``` -------------------------------- ### C# Playlist Setup and Configuration with AVPro Video Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Demonstrates how to set up and configure a PlaylistMediaPlayer in Unity using C#. This includes assigning player instances, setting loop modes, transition behaviors, and audio properties. It also shows how to build the playlist by adding media items with specific configurations. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class PlaylistController : MonoBehaviour { public PlaylistMediaPlayer playlistPlayer; public MediaPlayer playerA; public MediaPlayer playerB; void SetupPlaylist() { // Assign two MediaPlayer instances playlistPlayer.PlayerA = playerA; playlistPlayer.PlayerB = playerB; // Configure playlist behavior playlistPlayer.LoopMode = PlaylistMediaPlayer.PlaylistLoopMode.Loop; playlistPlayer.AutoCloseVideo = true; playlistPlayer.AutoProgress = true; // Set default transition playlistPlayer.DefaultTransition = PlaylistMediaPlayer.Transition.Fade; playlistPlayer.DefaultTransitionDuration = 1.5f; playlistPlayer.DefaultTransitionEasing = PlaylistMediaPlayer.Easing.Preset.InOutCubic; playlistPlayer.PausePreviousOnTransition = true; // Build playlist BuildPlaylist(); // Control audio playlistPlayer.AudioVolume = 0.75f; playlistPlayer.AudioMuted = false; } void BuildPlaylist() { playlistPlayer.Playlist.Items.Clear(); // Add first video with fade transition MediaPlaylist.MediaItem item1 = new MediaPlaylist.MediaItem(); item1.mediaPath = new MediaPath("video1.mp4", MediaPathType.RelativeToStreamingAssetsFolder); item1.loop = false; item1.startMode = PlaylistMediaPlayer.StartMode.Immediate; item1.progressMode = PlaylistMediaPlayer.ProgressMode.OnFinish; item1.isOverrideTransition = true; item1.overrideTransition = PlaylistMediaPlayer.Transition.Fade; item1.overrideTransitionDuration = 2.0f; item1.overrideTransitionEasing = PlaylistMediaPlayer.Easing.Preset.Linear; playlistPlayer.Playlist.Items.Add(item1); // Add second video with zoom transition, progress before finish MediaPlaylist.MediaItem item2 = new MediaPlaylist.MediaItem(); item2.mediaPath = new MediaPath("video2.mp4", MediaPathType.RelativeToStreamingAssetsFolder); item2.loop = false; item2.startMode = PlaylistMediaPlayer.StartMode.Manual; item2.progressMode = PlaylistMediaPlayer.ProgressMode.BeforeFinish; item2.progressTimeSeconds = 3.0f; // Start transition 3s before end item2.isOverrideTransition = true; item2.overrideTransition = PlaylistMediaPlayer.Transition.Zoom; item2.overrideTransitionDuration = 3.0f; item2.overrideTransitionEasing = PlaylistMediaPlayer.Easing.Preset.InOutQuad; playlistPlayer.Playlist.Items.Add(item2); // Add streaming URL MediaPlaylist.MediaItem item3 = new MediaPlaylist.MediaItem(); item3.mediaPath = new MediaPath("https://example.com/stream.m3u8", MediaPathType.AbsolutePathOrURL); item3.progressMode = PlaylistMediaPlayer.ProgressMode.Manual; playlistPlayer.Playlist.Items.Add(item3); } void ControlPlaylist() { // Playback control playlistPlayer.Play(); playlistPlayer.Pause(); // Navigation if (playlistPlayer.NextItem()) { Debug.Log("Advanced to next item"); } if (playlistPlayer.PrevItem()) { Debug.Log("Returned to previous item"); } if (playlistPlayer.CanJumpToItem(2)) { playlistPlayer.JumpToItem(2); } // Query playlist state int playlistSize = playlistPlayer.Playlist.Items.Count; int currentIndex = playlistPlayer.PlaylistIndex; MediaPlaylist.MediaItem currentItem = playlistPlayer.PlaylistItem; if (currentItem != null) { Debug.Log($"Playing: {currentItem.mediaPath.GetResolvedFullPath()}"); } } } ``` -------------------------------- ### FFmpeg Encoding Commands for Hap Codecs Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-hap-codec These FFmpeg commands demonstrate how to encode videos into various Hap formats, including standard Hap, Hap Alpha, and HapQ. Ensure your input and output file paths are correct. FFmpeg must be installed and accessible in your system's PATH. ```bash ffmpeg -i input.mov -vcodec hap -format hap output-hap.mov ``` ```bash ffmpeg -i input.mov -vcodec hap -format hap_alpha output-hap.mov ``` ```bash ffmpeg -i input.mov -vcodec hap -format hap_q output-hap.mov ``` -------------------------------- ### Setup ApplyToMesh for Video on 3D Meshes (C#) Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt This C# script demonstrates how to set up the ApplyToMesh component to display video on a 3D mesh using AVPro Video. It covers initializing the component, assigning media players and renderers, and configuring texture properties and UV scaling. It also shows how to create and assign different materials for opaque, transparent, and 360° video playback. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class MeshDisplaySetup : MonoBehaviour { public MediaPlayer mediaPlayer; public MeshRenderer meshRenderer; public Texture2D defaultTexture; void SetupMeshDisplay() { // Create 3D object (e.g., Quad, Sphere for 360 video) // Add ApplyToMesh component ApplyToMesh applyToMesh = gameObject.AddComponent(); applyToMesh.Media = mediaPlayer; applyToMesh.Renderer = meshRenderer; applyToMesh.DefaultTexture = defaultTexture; // Apply to all materials or specific index applyToMesh.AllMaterials = false; applyToMesh.MaterialIndex = 0; // Specify texture property name (depends on shader/render pipeline) applyToMesh.TexturePropertyName = "_MainTex"; // Standard pipeline // applyToMesh.TexturePropertyName = "_BaseMap"; // URP // applyToMesh.TexturePropertyName = "_BaseColorMap"; // HDRP // UV offset and scale applyToMesh.Offset = Vector2.zero; applyToMesh.Scale = Vector2.one; // Create material with AVPro Video shader Material videoMaterial = new Material(Shader.Find("AVProVideo/Unlit/Opaque")); meshRenderer.material = videoMaterial; // For transparent video Material transparentMaterial = new Material(Shader.Find("AVProVideo/Unlit/Transparent")); meshRenderer.material = transparentMaterial; // For 360° equirectangular video on sphere Material vr360Material = new Material(Shader.Find("AVProVideo/VR/InsideSphere")); meshRenderer.material = vr360Material; } } ``` -------------------------------- ### AVPro Video uGUI Display Setup in Unity Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Configure the DisplayUGUI component to render AVPro Video content onto Unity's UI Canvas. This involves assigning the MediaPlayer, setting display properties like color and scaling, adjusting UV rectangles for cropping, and optionally fading the video. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class UIDisplaySetup : MonoBehaviour { public MediaPlayer mediaPlayer; void SetupUIDisplay() { // Create Canvas: GameObject > UI > Canvas // Create DisplayUGUI: GameObject > UI > AVPro Video uGUI DisplayUGUI display = GetComponent(); display.MediaPlayer = mediaPlayer; display.NoDefaultDisplay = false; display.DefaultTexture = null; // Texture to show when loading display.Color = Color.white; // Multiply color (useful for fading) // Set aspect ratio scaling mode display.ScaleMode = ScaleMode.ScaleToFit; // UV rectangle transformation (crop/zoom) display.UVRect = new Rect(0, 0, 1, 1); // Full texture display.UVRect = new Rect(0.25f, 0.25f, 0.5f, 0.5f); // Center crop // Adjust RectTransform to match video resolution display.SetNativeSize(); // Fade video to black over 2 seconds StartCoroutine(FadeToBlack(display, 2.0f)); } System.Collections.IEnumerator FadeToBlack(DisplayUGUI display, float duration) { float elapsed = 0f; while (elapsed < duration) { elapsed += Time.deltaTime; float alpha = 1f - (elapsed / duration); display.Color = new Color(alpha, alpha, alpha, 1f); yield return null; } } } ``` -------------------------------- ### Re-encode Video Timescale using FFMPEG Source: https://www.renderheads.com/content/docs/AVProVideo/articles/known-issues This command-line example demonstrates how to re-encode a video file using FFMPEG to correct issues caused by a very large timescale. It specifies output parameters such as pixel format, constant rate factor, timescale, and fast start. Ensure FFMPEG is installed and accessible in your system's PATH. ```bash ffmpeg -i input.mp4 -an -pix_fmt yuv420p -crf 18 -video_track_timescale 90000 -movflags faststart -y output.mp4 ``` -------------------------------- ### Configure Custom HTTP Headers (C# Scripting) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-content-protection-ultra Shows how to set custom HTTP headers for media playback using C# scripting. This includes examples for setting Authorization headers (Basic and Bearer) and Cookie headers. It also demonstrates setting headers for the current platform and specifies the need to set the video API to WinRT on Windows for custom header support. ```csharp // On Windows the Video API needs to be set to WinRT to use custom HTTP headers mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.WinRT; // Set custom HTTP headers on Android platform mediaPlayer.PlatformOptionsAndroid.httpHeaders.Add("Authorization", "Bearer "); mediaPlayer.PlatformOptionsAndroid.httpHeaders.Add("Cookie", "=;=;"); // For Basic Authorization the : should be base64 encoded: string username = "user"; string password = "password"; string base64token = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)); mediaPlayer.PlatformOptionsAndroid.httpHeaders.Add("Authorization", "Basic " + base64token); // Set custom HTTP headers on the currently running platform mediaPlayer.GetCurrentPlatformOptions().httpHeaders.Add("MyHlsUriToken", "1234567890"); ``` -------------------------------- ### Configure Windows for Adaptive Streaming in C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-streaming Configures Windows-specific platform options for AVPro Video to enhance adaptive streaming. This includes selecting the WinRT video API for better performance and compatibility, optionally starting with the highest bitrate, and enabling low latency for live streams. ```csharp // Start adaptive stream using the highest resolution - WinRT only mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.WinRT; mediaPlayer.PlatformOptionsWindows.startWithHighestBitrate = true; // Set live stream to use the lowest latency possible for live streams - WinRT only mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.WinRT; mediaPlayer.PlatformOptionsWindows.useLowLiveLatency = true; ``` -------------------------------- ### Get Media Cache Status - C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-caching Retrieves the caching status of a media item and its download progress. Returns whether the media is not cached, currently caching, or fully cached. ```csharp float progress = 0.0f; CachedMediaStatus status = mediaPlayer.Cache.GetCachedMediaStatus(url, ref progress); ``` -------------------------------- ### UWP/Hololens: Configure Adaptive Streams with WinRT API Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-streaming This snippet configures AVPro Video on UWP/Hololens to use the WinRT video API for adaptive streams. It enables starting with the highest bitrate and setting low latency for live streams. Requires Windows 10. The 'InternetClient' capability must be enabled in Player Settings, and 'PrivateNetworkClientServer' if streaming from a local server/LAN. ```csharp mediaPlayer.PlatformOptionsWindowsUWP.videoApi = WindowsUWP.VideoApi.WinRT; mediaPlayer.PlatformOptionsWindowsUWP.startWithHighestBitrate = true; // Set live stream to use the lowest latency possible for live streams - WinRT only mediaPlayer.PlatformOptionsWindowsUWP.videoApi = WindowsUWP.VideoApi.WinRT; mediaPlayer.PlatformOptionsWindowsUWP.useLowLiveLatency = true; ``` -------------------------------- ### Android ExoPlayer: Configure Adaptive Streaming Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-streaming Configure ExoPlayer on Android to start streaming at the highest available bit-rate, set a preferred maximum resolution (e.g., 1080p), and define a peak adaptive bit-rate (e.g., 4Mbps). Requires `mediaPlayer.PlatformOptionsAndroid.videoApi = Android.VideoApi.ExoPlayer;`. ```csharp // Start adaptive stream using the highest resolution - ExoPlayer only mediaPlayer.PlatformOptionsAndroid.videoApi = Android.VideoApi.ExoPlayer; mediaPlayer.PlatformOptionsAndroid.startWithHighestBitrate = true; // Set the maximum adaptive resolution to 1080p - ExoPlayer only mediaPlayer.PlatformOptionsAndroid.videoApi = Android.VideoApi.ExoPlayer; mediaPlayer.PlatformOptionsAndroid.preferredMaximumResolution = OptionsAndroid.Resolution._1080p; // Set the peak adaptive bitrate to 4Mbps - ExoPlayer only mediaPlayer.PlatformOptionsAndroid.videoApi = Android.VideoApi.ExoPlayer; mediaPlayer.PlatformOptionsAndroid.preferredPeakBitRate = 4.0f; mediaPlayer.PlatformOptionsAndroid.preferredPeakBitRateUnits = OptionsAndroid.BitRateUnits.Mbps; ``` -------------------------------- ### Scripting Playback Rate with MediaPlayer Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-seeking-playbackrate Control the playback speed of the video. This includes getting the current playback rate and setting a new rate, typically by multiplying the current rate. It's important to note potential platform differences and limitations on achievable rates. ```csharp // After the video is loaded and metadata event fires you can use these: // Get the current playback rate float rate = mediaPlayer.PlaybackRate; // Set the current playback rate mediaPlayer.PlaybackRate = rate * 2f; ``` -------------------------------- ### Get Stereo Packing Mode - C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-stereo-video This script retrieves the current stereo packing mode being used by the MediaPlayer. This mode can be either automatically detected from the video's metadata or manually specified. The result is obtained from the TextureProducer. ```csharp StereoPacking videoStereoPacking = mediaPlayer.TextureProducer.GetTextureStereoPacking(); ``` -------------------------------- ### Enable Support for Older macOS Versions (Unity 2019+) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/platform-macos This configuration enables AVPro Video to run on macOS versions older than 10.14.4 by defining a scripting symbol and ensuring Swift libraries are embedded. It is intended for standalone builds and requires Unity 2019 or later with the iOS Build Support module installed. ```bash In the Player Settings inspector: * In the Other Settings section * Add `AVPROVIDEO_SUPPORT_MACOSX_10_14_3_AND_OLDER` to "Scripting Define Symbols" In the main target's build settings (when 'Create Xcode Project' is checked): * Set "Always Embed Swift Standard Libraries" to "YES" ``` -------------------------------- ### Scripting Text Tracks in AVPro Video (C#) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-subtitles This snippet demonstrates how to interact with subtitle text tracks using the AVPro Video C# API. It covers retrieving track counts, iterating through available tracks, accessing information about the active track, setting an active track, and getting the current text cue. Ensure the mediaPlayer object is properly initialized. ```csharp // Get the number of text tracks int trackCount = mediaPlayer.TextTracks.GetTextTracks().Count; // Iterate through the tracks foreach (TextTrack track in mediaPlayer.TextTracks.GetTextTracks()) { Debug.Log(track.DisplayName); } // Get information about the active text track TextTrack track = mediaPlayer.TextTracks.GetActiveTextTrack(); if (track != null) { Debug.Log(string.Format("{0}:{1}", track.Name, track.Language)); } else { Debug.Log("No active text track"); } // Set the active text track mediaPlayer.TextTracks.SetActiveTextTrack(track); // Get the current text cue TextCue textCue = mediaPlayer.TextTracks.GetCurrentTextCue(); if (textCue != null) { Debug.Log(textCue.Text); } ``` -------------------------------- ### Time-based Seeking with MediaPlayer Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-seeking-playbackrate Control video playback by seeking to specific times in seconds. This method uses double precision for time values and provides functions to get duration, current time, seekable ranges, and perform direct or fast seeking. It also includes seeking to the live time for live streams. ```csharp // After the video is loaded and metadata event fires you can use these: // Get the media duration in seconds double duration = mediaPlayer.Info.GetDuration(); // Get current time in seconds double time = mediaPlayer.Control.GetCurrentTime(); // Get the ranges of time that can be seeked between TimeRanges seekRanges = mediaPlayer.Control.GetSeekableTimes(); // Seek to 24 seconds mediaPlayer.Control.Seek(24.0); // Seek to nearest keyframe at 24 seconds mediaPlayer.Control.SeekFast(24.0); // Seek to closest keyframe allowing keyframe to be either ahead, behind or on both sides of the desired time // This is only currently available on macOS, iOS, iPadOS and tvOS mediaPlayer.Control.SeekWithTolerance(24.0, 5.0, 0.0); // Seek to the current 'live' time for a live stream TimeRange seekableRange = Helper.GetTimelineRange(mediaPlayer.Info.GetDuration(), mediaPlayer.Control.GetSeekableTimes()); mediaPlayer.Control.Seek(seekableRange.endTime); ``` -------------------------------- ### Accessing Time Ranges in AVPro Video 2.x Source: https://www.renderheads.com/content/docs/AVProVideo/articles/upgrading-from-avpro-video-1x This C# code snippet illustrates how to get the number of buffered time ranges and access the first time range using the IMediaControl interface in AVPro Video 2.x. It assumes a mediaPlayer object is available and has buffered content. ```csharp int bufferZones = IMediaControl.GetBufferedTimes().Count; TimeRange range = IMediaControl.GetBufferedTimes()[0]; ``` -------------------------------- ### Load Media from Various Sources in Unity C# Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Illustrates how to open video media using AVPro Video from different locations including MediaReference assets, StreamingAssets, absolute paths, URLs, and the persistent data folder. It also shows how to set media hints for transparency and stereo packing. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class MediaLoader : MonoBehaviour { public MediaPlayer mediaPlayer; public MediaReference myMediaReference; void LoadMediaExamples() { // Open media via MediaReference asset (preferred method) bool isOpening = mediaPlayer.OpenMedia(myMediaReference, autoPlay: true); if (!isOpening) { Debug.LogError("Failed to open media from MediaReference"); } // Open media from StreamingAssets folder bool opened = mediaPlayer.OpenMedia( new MediaPath("myvideo.mp4", MediaPathType.RelativeToStreamingAssetsFolder), autoPlay: true ); // Open media from absolute path string absolutePath = Application.dataPath + "/Videos/intro.mp4"; mediaPlayer.OpenMedia( new MediaPath(absolutePath, MediaPathType.AbsolutePathOrURL), autoPlay: false ); // Open HLS streaming URL string hlsUrl = "https://stream.example.com/video.m3u8"; mediaPlayer.OpenMedia( new MediaPath(hlsUrl, MediaPathType.AbsolutePathOrURL), autoPlay: true ); // Open from persistent data path (recommended for Android) mediaPlayer.OpenMedia( new MediaPath("downloaded_video.mp4", MediaPathType.RelativeToPersistentDataFolder), autoPlay: true ); // Set media hints for path-based loading (transparency, stereo packing) MediaHints hints = mediaPlayer.FallbackMediaHints; hints.transparency = TransparencyMode.Transparent; hints.alphaPacking = AlphaPacking.TopBottom; hints.stereoPacking = StereoPacking.LeftRight; mediaPlayer.FallbackMediaHints = hints; } } ``` -------------------------------- ### Enable Facebook Audio 360 for AVPro Video Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Configures the MediaPlayer to use Facebook Audio 360, which is suitable for MKV files containing spatial audio. This setup specifically targets Windows and Android platforms and defines the channel mode. ```csharp #if UNITY_STANDALONE_WIN mediaPlayer.PlatformOptionsWindows.audioOutput = Windows.AudioOutput.FacebookAudio360; mediaPlayer.PlatformOptionsWindows.audio360ChannelMode = Windows.Audio360ChannelMode.TBE_8_2; #elif UNITY_ANDROID mediaPlayer.PlatformOptionsAndroid.audioOutput = Android.AudioOutput.FacebookAudio360; mediaPlayer.PlatformOptionsAndroid.audio360ChannelMode = Android.Audio360ChannelMode.TBE_8_2; mediaPlayer.PlatformOptionsAndroid.audioLatency = 0; // ms adjustment #endif ``` -------------------------------- ### PlaylistMediaPlayer Scripting - C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/component-playlist-media-player This C# script demonstrates how to set up and control the PlaylistMediaPlayer component. It covers initializing loop modes, transition settings, managing playlist items, controlling audio, and manipulating playback. This script requires the PlaylistMediaPlayer component to be attached to a GameObject. ```csharp PlaylistMediaPlayer pmp; // Setup pmp.LoopMode = PlaylistMediaPlayer.PlaylistLoopMode.Loop; pmp.AutoCloseVideo = true; pmp.AutoProgress = true; pmp.DefaultTransition = PlaylistMediaPlayer.Transition.Zoom; pmp.DefaultTransitionDuration = 2.0f; pmp.DefaultTransitionEasing = PlaylistMediaPlayer.Easing.Preset.InOutCubic; // Query the playlist int playlistSize = pmp.Playlist.Items.Count(); MediaPlaylist.MediaItem currentItem = pmp.PlaylistItem; if (currentItem != null) { Debug.Log("Current media is at " + currentItem.mediaPath.GetResolvedFullPath()); } int playlistItemIndex = pmp.PlaylistIndex; // Build the playlist pmp.PlaylistItems.Clear(); MediaPlaylist.MediaItem item = new MediaPlaylist.MediaItem(); item.mediaPath = new MediaPath("myvideo.mp4", MediaPathType.RelativeToStreamingAssetsFolder); item.progressMode = PlaylistMediaPlayer.ProgressMode.OnFinish; item.isOverrideTransition = true; item.overrideTransition = PlaylistMediaPlayer.Transition.Black; item.overrideTransitionDuration = 1.0f; item.overrideTransitionEasing = PlaylistMediaPlayer.Easing.Preset.Linear; pmp.Playlist.Items.Add(item); // Manipulate volume pmp.AudioVolume = 0.5; pmp.AudioMuted = true; // Control playback pmp.Pause(); pmp.Play(); if (pmp.CanJumpToItem(2)) { pmp.JumpToItem(2); } if (!pmp.NextItem()) { Debug.Log("Can't change item"); } if (!pmp.PrevItem()) { Debug.Log("Can't change item"); } ``` -------------------------------- ### OverlayManager Methods (C#) Source: https://www.renderheads.com/content/docs/AVProVideo/api/RenderHeads.Media.AVProVideo.Demos.UI Details the methods of the OverlayManager class: Reset for initializing state, TriggerFeedback for displaying specific feedback, and TriggerStalled for indicating a stalled condition. ```csharp public void Reset() ``` ```csharp public void TriggerFeedback(OverlayManager.Feedback feedback) ``` ```csharp public void TriggerStalled() ``` -------------------------------- ### FFmpeg: Prepare MP4 for Progressive Streaming Source: https://www.renderheads.com/content/docs/AVProVideo/articles/encoding-notes Prepares an existing MP4 video file for progressive streaming by rearranging metadata. The 'faststart' option moves the 'moov' atom to the beginning of the file, allowing playback to begin before the entire file is downloaded. ```bash ffmpeg -i input.mp4 -acodec copy -vcodec copy -movflags faststart output.mp4 ``` -------------------------------- ### Force Stereo Eye Mode - C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-stereo-video This code shows how to force a specific stereo eye mode (e.g., Left or Right) on a material using the static VideoRender class. This is particularly useful when applying stereo content to meshes or materials in a multi-pass stereo rendering setup. ```csharp VideoRender.SetupStereoEyeModeMaterial(material, StereoEye.Left); ``` -------------------------------- ### Open Media via Script in Unity AVPro Video Source: https://www.renderheads.com/content/docs/AVProVideo/articles/usage-loading-media Demonstrates how to open media using both MediaReference assets and file paths (URLs or local files) within Unity scripts. It also shows how to modify media hints for path-based media. This is useful for dynamically loading different media sources during runtime. ```csharp // Opening media via a MediaReference MediaReference mediaReference = _myMediaReference; bool isOpening = mediaPlayer.OpenMedia(mediaReference, autoPlay:true); // Opening media URL via a Path bool isOpening = mediaPlayer.OpenMedia(new MediaPath("https://www.myvideos.com/stream.m3u8", MediaPathType.AbsolutePathOrURL), autoPlay:true); // Opening local file media via a Path bool isOpening = mediaPlayer.OpenMedia(new MediaPath("myvideo.mp4", MediaPathType.RelativeToStreamingAssetsFolder), autoPlay:true); // Changing the media hints for content loaded via Path MediaHints hints = mediaPlayer.FallbackMediaHints; hints.stereoPacking = StereoPacking.TopBottom; mediaPlayer.FallbackMediaHints = hints; ``` -------------------------------- ### Frame-based Seeking with MediaPlayer Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-seeking-playbackrate Seek video playback using frame numbers, suitable for media with a constant frame rate. This allows getting duration in frames, the maximum seekable frame, and performing seeks to specific frames or relative frame changes. It also provides the current time in frames. ```csharp // After the video is loaded and metadata event fires you can use these: // Get the media duration in frames int durationFrames = mediaPlayer.Info.GetDurationFrames(); // Get the highest frame number you can seek to (the same as durationFrames-1) int maxFrame = mediaPlayer.Info.GetMaxFrameNumber(); // Seek to frame 60 mediaPlayer.Control.SeekToFrame(60); // Seek back 10 frames mediaPlayer.Control.SeekToFrameRelative(-10.0); // Get current time in frames int frame = mediaPlayer.Control.GetCurrentTimeFrames(); ``` -------------------------------- ### Define Apple Expected Plugin Version Source: https://www.renderheads.com/content/docs/AVProVideo/api/RenderHeads.Media.AVProVideo.Helper This snippet shows the constant string declaration for the expected plugin version on Apple platforms. It is part of the Helper.ExpectedPluginVersion class. ```csharp public const string Apple = "2.9.2" ``` -------------------------------- ### Define Windows Expected Plugin Version Source: https://www.renderheads.com/content/docs/AVProVideo/api/RenderHeads.Media.AVProVideo.Helper This snippet shows the constant string declaration for the expected plugin version on Windows. It is part of the Helper.ExpectedPluginVersion class. ```csharp public const string Windows = "2.8.5" ``` -------------------------------- ### Create Batch File for Video Conversion (Windows Command-Line) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-content-protection-ultra Provides a Windows command-line script to create a batch file for easily appending a video file to a dummy video. This script takes the first argument (`%1`) as the video file to be processed and creates a new file named `filename-hidden.mp4` by copying the dummy video and appending the specified video. ```batch copy /b DummyVideo.mp4 + %1 %~n1-hidden.mp4 ``` -------------------------------- ### Configure Windows Advanced Platform Options in C# Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt This C# snippet demonstrates how to configure advanced platform-specific options for Windows using AVPro Video. It includes settings for Media Foundation and DirectShow APIs, hardware decoding, low-latency playback, Hap/NotchLC codec support, and frame selection. Dependencies include the MediaPlayer component and RenderHeads.Media.AVProVideo namespace. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class AdvancedConfiguration : MonoBehaviour { public MediaPlayer mediaPlayer; void ConfigureWindowsAdvanced() { // Use Media Foundation API (default, best compatibility) mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.MediaFoundation; mediaPlayer.PlatformOptionsWindows.useHardwareDecoding = true; mediaPlayer.PlatformOptionsWindows.useLowLatency = false; // Degrades performance mediaPlayer.PlatformOptionsWindows.useStereoDetection = true; mediaPlayer.PlatformOptionsWindows.useTextTrackSupport = true; // Hap/NotchLC codec options (high-performance codecs for 8K+) mediaPlayer.PlatformOptionsWindows.useHapNotchLC = true; mediaPlayer.PlatformOptionsWindows.useCustomMovParser = true; mediaPlayer.PlatformOptionsWindows.hap_parallelFrameCount = 4; mediaPlayer.PlatformOptionsWindows.hap_prerollFrameCount = 8; // Frame selection (experimental smooth playback) mediaPlayer.PlatformOptionsWindows.useFrameSelection = true; mediaPlayer.PlatformOptionsWindows.pauseAfterPrerollComplete = false; // DirectShow API (legacy, for codec packs like LAV Filters) mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.DirectShow; mediaPlayer.PlatformOptionsWindows.forceAudioOutputDeviceName = "Speakers"; mediaPlayer.PlatformOptionsWindows.preferredFilters = new string[] { "LAV Video Decoder", "LAV Audio Decoder" }; } } ``` -------------------------------- ### Create Batch File for Multiple File Conversion (Windows Command Line) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-content-protection-core Creates a Windows batch file command to easily append a video file to a dummy video, enabling batch conversion of multiple files for content hiding. ```batch copy /b DummyVideo.mp4 + %1 %~n1-hidden.mp4 ``` -------------------------------- ### Define WinRT Expected Plugin Version Source: https://www.renderheads.com/content/docs/AVProVideo/api/RenderHeads.Media.AVProVideo.Helper This snippet shows the constant string declaration for the expected plugin version on WinRT. It is part of the Helper.ExpectedPluginVersion class. ```csharp public const string WinRT = "2.8.5" ``` -------------------------------- ### Check Caching Support - C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-caching Determines if the current platform supports media caching. This is a prerequisite for utilizing any caching functionalities. ```csharp if (mediaPlayer.Cache.IsMediaCachingSupported()) { // Caching is supported } ``` -------------------------------- ### Set Video Layout Mapping Hint via Script Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-arvrxr This C# code snippet demonstrates how to programmatically set the video layout mapping hint on a MediaPlayer component. This is crucial for correctly interpreting spatial formats like Equirectangular 180 in XR experiences. No external dependencies are required beyond the AVPro Video SDK. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class SetVideoLayout : MonoBehaviour { public MediaPlayer mediaPlayer; void Start() { if (mediaPlayer != null) { // Set the video layout mapping hint on the MediaPlayer mediaPlayer.VideoLayoutMapping = VideoMapping.EquiRectangular180; } else { Debug.LogError("MediaPlayer is not assigned."); } } } ``` -------------------------------- ### Encode HEVC 10-Bit Video with FFMPEG Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-10bit This command-line snippet uses FFMPEG to encode a video file into HEVC Main 10 profile with Rec709 color primaries and high quality settings. It specifies pixel format, color details, CRF for quality, and includes fast start options. Ensure Rec709 is used for correct color rendering. ```bash ffmpeg -y -i %1 -pix_fmt yuv420p10le -color_primaries 1 -color_trc 1 -colorspace 1 -color_range 2 -crf 4 -vcodec libx265 -movflags +write_colr -movflags +faststart %i-hevc-10bit-rec709-high.mp4 ``` -------------------------------- ### Append Video to Dummy File (Windows Command Line) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-content-protection-core Appends a video file to a dummy file using the Windows command prompt. This is useful for hiding media by embedding it within another file. ```batch copy /b DummyFile.dat + MyVideo.mp4 MysteryFile.dat ``` -------------------------------- ### Configure Android Streaming Settings for AVPro Video Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Sets up adaptive streaming on Android using ExoPlayer. Allows configuration of bitrate, resolution, buffering behavior, and forcing RTP over TCP for optimal playback. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class StreamingConfiguration : MonoBehaviour { public MediaPlayer mediaPlayer; void ConfigureAndroidStreaming() { // Use ExoPlayer for best streaming support mediaPlayer.PlatformOptionsAndroid.videoApi = Android.VideoApi.ExoPlayer; // Start with highest bitrate mediaPlayer.PlatformOptionsAndroid.startWithHighestBitrate = true; // Limit maximum resolution to 1080p mediaPlayer.PlatformOptionsAndroid.preferredMaximumResolution = OptionsAndroid.Resolution._1080p; // Set peak bitrate to 4 Mbps mediaPlayer.PlatformOptionsAndroid.preferredPeakBitRate = 4.0f; mediaPlayer.PlatformOptionsAndroid.preferredPeakBitRateUnits = OptionsAndroid.BitRateUnits.Mbps; // Configure buffering (values in milliseconds) mediaPlayer.PlatformOptionsAndroid.minBufferMs = 50000; // 50 seconds mediaPlayer.PlatformOptionsAndroid.maxBufferMs = 50000; mediaPlayer.PlatformOptionsAndroid.bufferForPlaybackMs = 2500; // 2.5 seconds mediaPlayer.PlatformOptionsAndroid.bufferForPlaybackAfterRebufferMs = 5000; // 5 seconds // Force RTP over TCP mediaPlayer.PlatformOptionsAndroid.forceRtpTcp = true; } } ``` -------------------------------- ### OverlayManager Class Definition (C#) Source: https://www.renderheads.com/content/docs/AVProVideo/api/RenderHeads.Media.AVProVideo.Demos.UI Defines the OverlayManager class, inheriting from MonoBehaviour, within the RenderHeads.Media.AVProVideo.Demos.UI namespace. This class manages UI overlay functionalities. ```csharp public class OverlayManager : MonoBehaviour ``` -------------------------------- ### FFmpeg: Encode Video to Hap Codecs Source: https://www.renderheads.com/content/docs/AVProVideo/articles/encoding-notes Provides FFmpeg commands for encoding videos into various Hap codec formats, including basic Hap, Hap with an alpha channel, and HapQ for higher quality. It also demonstrates options for chunking and compression. ```bash ffmpeg -i input.mov -vcodec hap -format hap output.mov ``` ```bash ffmpeg -i input.mov -vcodec hap -format hap_alpha output.mov ``` ```bash ffmpeg -i input.mov -vcodec hap -format hap_q output.mov ``` ```bash ffmpeg -i input.mov -vcodec hap -format hap_q -chunks 8 -compressor snappy output.mov ``` -------------------------------- ### Mux Opus Audio into MKV Container with FFmpeg Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-360audio This command demonstrates how to mux an Opus audio file into a video container using FFmpeg. It assumes the video file is an MP4 and the output should be an MKV with the audio and video streams copied. This is a step in manually preparing audio-video files for AVPro Video. ```bash ffmpeg -i audio.opus -i video.mp4 -c:a copy -c:v copy audio_video.mkv ``` -------------------------------- ### Prepare MP4 for Streaming with FFMPEG Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-streaming This command prepares an MP4 video file for HTTP progressive streaming by copying audio and video codecs and ensuring header data is at the beginning of the file. This is crucial for efficient streaming from network sources that support byte range requests. ```bash ffmpeg -i %1 -acodec copy -vcodec copy -movflags faststart %1-streaming.mp4 ``` -------------------------------- ### Define Android Expected Plugin Version Source: https://www.renderheads.com/content/docs/AVProVideo/api/RenderHeads.Media.AVProVideo.Helper This snippet shows the constant string declaration for the expected plugin version on Android. It is part of the Helper.ExpectedPluginVersion class. ```csharp public const string Android = "2.9.1" ``` -------------------------------- ### FFmpeg Conversion to VP9 for VR/High Resolution Source: https://www.renderheads.com/content/docs/AVProVideo/articles/encoding-notes This FFmpeg command converts a video to the VP9 codec, another option suitable for high-resolution and VR content. It uses a CRF of 18 and '-movflags faststart' for optimized playback. VP9 is an open and royalty-free codec. ```bash ffmpeg -i input.mov -pix_fmt yuv420p -crf 18 -libvpx-vp9 -movflags faststart output.mp4 ``` -------------------------------- ### Managing Audio Tracks in AVPro Video 2.x Source: https://www.renderheads.com/content/docs/AVProVideo/articles/upgrading-from-avpro-video-1x This C# code snippet demonstrates how to retrieve the count of available audio tracks, access a specific track by index, and set it as the active track in AVPro Video 2.x. It assumes a valid mediaPlayer object is already initialized. ```csharp int trackCount = mediaPlayer.AudioTracks.GetAudioTracks().Count; AudioTrack track = mediaPlayer.AudioTracks.GetAudioTracks()[index]; mediaPlayer.AudioTracks.SetActiveAudioTrack(track); ``` -------------------------------- ### Configure Windows Streaming Settings for AVPro Video Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Configures HLS/DASH streaming on Windows using the WinRT API. Supports custom HTTP headers, AES-128 decryption, and low-latency live streaming. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class StreamingConfiguration : MonoBehaviour { public MediaPlayer mediaPlayer; void ConfigureWindowsStreaming() { // Use WinRT API for best HLS/DASH streaming (Windows 10+) mediaPlayer.PlatformOptionsWindows.videoApi = Windows.VideoApi.WinRT; mediaPlayer.PlatformOptionsWindows.startWithHighestBitrate = true; mediaPlayer.PlatformOptionsWindows.useLowLiveLatency = true; // Custom HTTP headers mediaPlayer.PlatformOptionsWindows.httpHeaders.Clear(); mediaPlayer.PlatformOptionsWindows.httpHeaders.Add( new OptionsWindows.HttpHeader { header = "Authorization", value = "Bearer token123" } ); // HLS AES-128 decryption mediaPlayer.PlatformOptionsWindows.keyAuth = "my-auth-token"; mediaPlayer.PlatformOptionsWindows.overrideDecryptionKey = "base64EncodedKey=="; // Open HLS stream mediaPlayer.OpenMedia( new MediaPath("https://example.com/stream.m3u8", MediaPathType.AbsolutePathOrURL), autoPlay: true ); } } ``` -------------------------------- ### Append Video to Dummy Video (Windows Command Line) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-content-protection-core Appends a video file to a dummy video file using the Windows command prompt. This method further obscures the hidden video by making it appear as a playable dummy video. ```batch copy /b DummyVideo.mp4 + MyVideo.mp4 MysteryFile.mp4 ``` -------------------------------- ### hls.js: Custom Configuration for Low Latency Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-streaming This JavaScript snippet shows how to instantiate the hls.js library with custom configuration options, specifically enabling `lowLatencyMode`. This is useful when integrating hls.js with AVPro Video for WebGL, requiring modification of the AVProVideo.jslib file. ```javascript var config = { lowLatencyMode: true, }; hls = new Hls(config); ``` -------------------------------- ### FFmpeg Transparency Packing (Top-Bottom) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/encoding-notes This FFmpeg command converts a video with an alpha channel into a top-and-bottom packing format using the H.264 codec. It extracts the alpha channel and stacks it vertically with the color channels through FFmpeg's filtergraph. ```bash ffmpeg -i input.mov -c:v libx264 -pix_fmt yuv420p -vf "split [a], pad=iw:ih*2 [b], [a] alphaextract, [b] overlay=0:h" -y output.mp4 ``` -------------------------------- ### Manually Set Stereo Packing - C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-stereo-video This code snippet demonstrates how to manually set the stereo packing format for a MediaPlayer when loading videos via the Path Media Source. It accesses and modifies the FallbackMediaHints to specify the desired StereoPacking mode, such as TopBottom. ```csharp MediaHints hints = mediaPlayer.FallbackMediaHints; hints.stereoPacking = StereoPacking.TopBottom; mediaPlayer.FallbackMediaHints = hints; ``` -------------------------------- ### Configure Unity Audio Output for AVPro Video Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt Sets the audio output of the MediaPlayer to Unity's audio system. Requires the AudioOutput component to be added to the GameObject. This enables positional audio and access to audio visualization data. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class AudioConfiguration : MonoBehaviour { public MediaPlayer mediaPlayer; public Transform headTransform; public Transform focusTransform; void ConfigureUnityAudio() { // Set audio output to Unity (requires AudioOutput component) #if UNITY_STANDALONE_WIN mediaPlayer.PlatformOptionsWindows.audioOutput = Windows.AudioOutput.Unity; #elif UNITY_ANDROID mediaPlayer.PlatformOptionsAndroid.audioOutput = Android.AudioOutput.Unity; #elif UNITY_IOS mediaPlayer.PlatformOptionsIOS.audioMode = OptionsApple.AudioMode.Unity; #endif // Add AudioOutput component AudioOutput audioOutput = gameObject.AddComponent(); audioOutput.MediaPlayer = mediaPlayer; audioOutput.AudioOutputMode = AudioOutput.Mode.MultipleChannels; audioOutput.SupportPositionalAudio = true; // Access AudioSource for visualization AudioSource audioSource = mediaPlayer.AudioSource; if (audioSource != null) { float[] spectrumData = new float[256]; audioSource.GetSpectrumData(spectrumData, 0, FFTWindow.Blackman); } } void ConfigureFacebookAudio360() { // Enable Facebook Audio 360 (for MKV files with spatial audio) #if UNITY_STANDALONE_WIN mediaPlayer.PlatformOptionsWindows.audioOutput = Windows.AudioOutput.FacebookAudio360; mediaPlayer.PlatformOptionsWindows.audio360ChannelMode = Windows.Audio360ChannelMode.TBE_8_2; #elif UNITY_ANDROID mediaPlayer.PlatformOptionsAndroid.audioOutput = Android.AudioOutput.FacebookAudio360; mediaPlayer.PlatformOptionsAndroid.audio360ChannelMode = Android.Audio360ChannelMode.TBE_8_2; mediaPlayer.PlatformOptionsAndroid.audioLatency = 0; // ms adjustment #endif } void Configure360AudioFocus() { // Set head transform for 360 audio (usually main camera) mediaPlayer.Audio360HeadTransform = headTransform; // Enable audio focus feature mediaPlayer.Audio360Focus = true; mediaPlayer.Audio360OffFocusLevel = -12f; // Decibels (-24 to 0) mediaPlayer.Audio360FocusWidthDegrees = 60f; // Degrees (40 to 120) mediaPlayer.Audio360FocusTransform = focusTransform; } } ``` -------------------------------- ### Setting Media Hints in AVPro Video 2.x Source: https://www.renderheads.com/content/docs/AVProVideo/articles/upgrading-from-avpro-video-1x This C# code snippet shows how to modify media hints, specifically setting stereo packing to 'None', using AVPro Video 2.x. It involves accessing and updating the FallbackMediaHints property of the mediaPlayer object. ```csharp MediaHints hints = mediaPlayer.FallbackMediaHints; hints.stereoPacking = StereoPacking.None; mediaPlayer.FallbackMediaHints = hints; ``` -------------------------------- ### FFmpeg Transparency Packing (Left-Right) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/encoding-notes This FFmpeg command converts a video with an alpha channel into a side-by-side (left-right) packing format using the H.264 codec. It extracts the alpha channel and places it alongside the color channels using FFmpeg's filtergraph capabilities. ```bash ffmpeg -i input.mov -c:v libx264 -pix_fmt yuv420p -vf "split [a], pad=iw*2:ih [b], [a] alphaextract, [b] overlay=w" -y output.mp4 ``` -------------------------------- ### Detect and Handle Live Streams in C# Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-streaming Detects if a media stream is live by checking if its duration is positive infinity. It also demonstrates how to retrieve the seekable time range for live streams, allowing for playback from an offset. ```csharp // Detect a live stream double duration = mediaPlayer.Info.GetDuration(); bool isLive = double.IsInfinity(duration); // Get the seekable time range TimeRanges seekable = mediaPlayer.Control.GetSeekableTimes(); Debug.Log("Seekable time: " + seekable.MinTime + " " + seekable.MaxTime); ``` -------------------------------- ### Append Video to Dummy File (Windows Command-Line) Source: https://www.renderheads.com/content/docs/AVProVideo/articles/feature-content-protection-ultra Demonstrates how to append a video file to a dummy file using the Windows 'copy' command. This is useful for hiding media files by embedding them within other files, creating a 'mystery file'. The command concatenates the contents of 'DummyFile.dat' and 'MyVideo.mp4' into 'MysteryFile.dat'. ```batch copy /b DummyFile.dat + MyVideo.mp4 MysteryFile.dat ``` -------------------------------- ### Configure Android Advanced Platform Options in C# Source: https://context7.com/context7/renderheads_content_avprovideo/llms.txt This C# snippet shows how to configure advanced platform-specific options for Android using AVPro Video. It focuses on enabling the fast OES path for improved performance and memory usage with high-resolution video, and controlling software decoder preference and poster frame display. Requires the MediaPlayer component. ```csharp using UnityEngine; using RenderHeads.Media.AVProVideo; public class AdvancedConfiguration : MonoBehaviour { public MediaPlayer mediaPlayer; void ConfigureAndroidAdvanced() { // Use OES rendering (saves memory, improves performance for high-res) mediaPlayer.PlatformOptionsAndroid.useFastOesPath = true; // Prefer software decoder (debugging only) mediaPlayer.PlatformOptionsAndroid.preferSoftwareDecoder = false; // Show poster frame when not auto-playing (MediaPlayer API only) mediaPlayer.PlatformOptionsAndroid.showPosterFrame = true; } } ```