### Initialize and Control AVEngine Source: https://context7.com/galis/opentiktok/llms.txt Get the AVEngine singleton, configure it with a SurfaceView, and start/pause playback. Includes setting a frame update callback for UI elements like progress bars. Ensure to release resources in Activity.onDestroy. ```java AVEngine engine = AVEngine.getVideoEngine(); engine.configure(surfaceView); // 注册 SurfaceHolder 回调,自动管理 EGL Surface engine.create(); // 启动 EngineThread(OpenGL)和 AudioThread // 2. 设置帧更新回调,用于刷新进度条等 UI engine.setOnFrameUpdateCallback(args -> runOnUiThread(() -> { long posMs = (engine.getMainClock() + 999) / 1000; long durMs = (engine.getVideoState().videoDuration + 999) / 1000; timeTextView.setText(String.format("%02d:%02d:%03d / %02d:%02d:%03d", posMs/1000/60%60, posMs/1000%60, posMs%1000, durMs/1000/60%60, durMs/1000%60, durMs%1000)); })); // 3. 播放 / 暂停 / 快速跳帧 engine.start(); engine.pause(); engine.togglePlayPause(); engine.fastSeek(3_000_000L); // 跳到第 3 秒(单位:微秒) // 4. 释放资源(在 Activity.onDestroy 中调用) engine.release(); ``` -------------------------------- ### Configure AVAudio for Specific Segments Source: https://context7.com/galis/opentiktok/llms.txt Instantiate an AVAudio component and manually set clip start and end times to play only a specific segment of the audio file. The engine will automatically handle seeking and frame reading during playback. ```java // 音频组件独立使用示例(通常与同路径的 AVVideo 配对) AVAudio audio = new AVAudio( 0L, // engineStartTime(微秒) "/sdcard/DCIM/bgm.mp4", null // render: null 使用默认 AudioRender(AudioTrack 输出) ); // 手动裁剪:只播放文件 5s-15s 片段 audio.open(); audio.setClipStartTime(5_000_000L); audio.setClipEndTime(15_000_000L); audio.setEngineEndTime(audio.getEngineStartTime() + audio.getClipDuration()); // 加入引擎后引擎会在播放时自动调用 seekFrame / readFrame engine.addComponent(audio, callback); ``` -------------------------------- ### Configure and Apply Video Transitions with AVTransaction Source: https://context7.com/galis/opentiktok/llms.txt Implements transition effects between video segments, starting with Alpha fade. Configures transition type, duration, and visibility. The engine automatically uses `TransactionRender` during the transition window. ```java List transactions = engine.findComponents( AVComponent.AVComponentType.TRANSACTION, -1); if (!transactions.isEmpty()) { AVTransaction tran = (AVTransaction) transactions.get(0); Map config = new HashMap<>(); config.put("tran_type", AVTransaction.TRAN_ALPHA); // 渐变转场 config.put("tran_duration", 1_000_000L); // 转场时长 1 秒 config.put("tran_visible", true); // 启用转场 engine.changeComponent(tran, config, args -> { engine.fastSeek(tran.getEngineStartTime()); // 跳到转场起点预览效果 }); } // 关闭转场(恢复直接拼接) config.put("tran_visible", false); engine.changeComponent(tran, config, null); ``` -------------------------------- ### Remove Component from AVEngine Timeline Source: https://context7.com/galis/opentiktok/llms.txt Removes a specified component (video, audio, text, sticker, transition, etc.) from the engine timeline. The engine automatically recalculates the total duration after removal. This example shows how to remove a component when a preview layer element is long-pressed. ```java view.setOnLongClickListener(v -> { AVComponent component = (AVComponent) v.getTag(); engine.removeComponent(component); previewContainer.removeView(v); runOnUiThread(() -> previewPanel.updateData(engine.getVideoState())); return true; }); ``` -------------------------------- ### Add AVVideo and AVAudio Components Source: https://context7.com/galis/opentiktok/llms.txt Create video and audio components using hardware-accelerated decoding. The AVVideo component outputs OES textures, while AVAudio handles AAC decoding. Components are added asynchronously to the engine, with UI updates requiring a switch to the main thread. ```java // 创建视频组件并加入引擎(texture 模式输出 OES 纹理) AVVideo video = new AVVideo( true, // isTextureType: true = 输出 OES 纹理,false = 输出 ByteBuffer -1L, // engineStartTime: -1 表示追加到当前轨道末尾 "/sdcard/DCIM/clip1.mp4", null // render: null 使用引擎默认 OESRender ); // 配套音频组件(同一文件) AVAudio audio = new AVAudio(-1L, "/sdcard/DCIM/clip1.mp4", null); // 异步添加,回调在 Engine 线程,UI 操作需切换主线程 engine.addComponent(video, args -> runOnUiThread(() -> { // 视频加载完成后设置画布比例 engine.setCanvasType("原始", sizeArgs -> { Size size = (Size) sizeArgs[0]; previewContainer.getLayoutParams().width = size.getWidth(); previewContainer.getLayoutParams().height = size.getHeight(); previewContainer.requestLayout(); }); previewPanel.updateData(engine.getVideoState()); })); engine.addComponent(audio, args -> runOnUiThread(() -> previewPanel.updateData(engine.getVideoState()))); ``` -------------------------------- ### AVEngine - Video Engine Core Source: https://context7.com/galis/opentiktok/llms.txt The AVEngine is the singleton core of the framework, managing all AVComponent components, driving the OpenGL rendering loop and audio playback thread, and exposing playback control, Seek, component management, canvas settings, and video composition operations. All engine calls are delivered asynchronously via a command queue, ensuring thread safety. ```APIDOC ## AVEngine - Video Engine Core ### Description The AVEngine is the singleton core of the framework, managing all AVComponent components, driving the OpenGL rendering loop and audio playback thread, and exposing playback control, Seek, component management, canvas settings, and video composition operations. All engine calls are delivered asynchronously via a command queue, ensuring thread safety. ### Usage 1. **Initialization**: Get the engine instance and configure it with a SurfaceView. ```java AVEngine engine = AVEngine.getVideoEngine(); engine.configure(surfaceView); engine.create(); // Starts EngineThread (OpenGL) and AudioThread ``` 2. **Frame Update Callback**: Set a callback to receive frame updates for UI elements like progress bars. ```java engine.setOnFrameUpdateCallback(args -> runOnUiThread(() -> { // Update UI elements with current playback time and duration })); ``` 3. **Playback Control**: Control playback, pause, and seek operations. ```java engine.start(); engine.pause(); engine.togglePlayPause(); engine.fastSeek(3_000_000L); // Seek to 3 seconds (microseconds) ``` 4. **Resource Release**: Release engine resources, typically in `Activity.onDestroy()`. ```java engine.release(); ``` ``` -------------------------------- ### Load GIF Sticker with AVSticker Source: https://context7.com/galis/opentiktok/llms.txt Loads a GIF from raw resources and overlays it on the video preview. Supports custom display duration, looping, and seeking. Gesture handling for drag and scale is automatically synchronized. ```java InputStream gifStream = context.getResources().openRawResource(R.raw.aini); ImageView stickerView = new ImageView(context); AVSticker sticker = new AVSticker( engine.getMainClock(), // 贴纸起始时间(微秒) gifStream, new ImageViewRender(stickerView) // ImageViewRender 用于在预览层显示 ); engine.addComponent(sticker, args -> previewPanel.post(() -> { previewPanel.updateEffect(); // 按 GIF 原始尺寸显示 stickerView.getLayoutParams().width = sticker.getSize().getWidth(); stickerView.getLayoutParams().height = sticker.getSize().getHeight(); previewContainer.addView(stickerView); stickerView.setTag(sticker); // 拖拽/缩放手势自动同步到组件矩阵 GestureUtils.setupView(stickerView, v -> { sticker.lock(); sticker.setMatrix(MathUtils.calMatrix( new Rect(0, 0, surfaceView.getWidth(), surfaceView.getHeight()), new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()) )); sticker.unlock(); }); })); ``` -------------------------------- ### Load PAG Animation with AVPag Source: https://context7.com/galis/opentiktok/llms.txt Integrates Tencent's PAG animation library to overlay `.pag` files onto video. Renders frames to OpenGL textures, suitable for intros, outros, and animated stickers. Handles aspect ratio scaling based on available space. ```java PAGView pagView = new PAGView(context); AVPag avPag = new AVPag( "pag/time_test.pag", // assets 路径 engine.getMainClock(), // 引擎起始时间 new PagRender(pagView) // PagRender 负责预览层渲染 ); engine.addComponent(avPag, args -> previewPanel.post(() -> { previewPanel.updateEffect(); // 按 PAG 文件原始尺寸等比缩放 int h = Math.min(surfaceView.getHeight(), avPag.getSize().getHeight()); int w = (int)(h * avPag.getSize().getWidth() / (float)avPag.getSize().getHeight()); pagView.getLayoutParams().width = w; pagView.getLayoutParams().height = h; previewContainer.addView(pagView); pagView.setTag(avPag); pagView.requestLayout(); })); ``` -------------------------------- ### Set Canvas Aspect Ratio and Background Color with AVEngine Source: https://context7.com/galis/opentiktok/llms.txt Dynamically adjusts `SurfaceView` size and OpenGL transformation matrix based on preset aspect ratio strings. Synchronizes the target resolution for composite output. Also sets the background color for letterbox areas. ```java // 支持的比例:原始 / 16:9 / 9:16 / 4:3 / 3:4 / 1:1 engine.setCanvasType("9:16", args -> { Size size = (Size) args[0]; // 返回调整后的像素尺寸 previewContainer.post(() -> { previewContainer.getLayoutParams().width = size.getWidth(); previewContainer.getLayoutParams().height = size.getHeight(); previewContainer.requestLayout(); }); }); // 设置背景填充色(信箱区域) engine.setBgColor(Color.BLACK); ``` -------------------------------- ### Composite MP4 Video with AVEngine.compositeMp4() Source: https://context7.com/galis/opentiktok/llms.txt Initiates a separate video synthesis process after preview pause. It renders frames using OpenGL, encodes them with MediaCodec (H.264) and AAC, and muxes into an MP4 file using MediaMuxer. Progress is reported via a callback. ```java // 配置合成参数 AVEngine.VideoState state = engine.getVideoState(); state.lock(); state.compositePath = "/sdcard/Movies/output.mp4"; state.compositeHeight = 1080; // 1080p 或 720p state.compositeGop = 30; // 帧率 state.compositeVb = 8_000_000; // 视频码率 8Mbps state.compositeAb = 128_000; // 音频码率 128kbps state.unlock(); // 开始合成,回调在合成线程,UI 操作需切换主线程 engine.compositeMp4(progress -> runOnUiThread(() -> { progressBar.setProgress(progress); if (progress == 100) { Toast.makeText(context, "导出完成:" + state.compositePath, Toast.LENGTH_LONG).show(); } })); ``` -------------------------------- ### AVEngine.compositeMp4() - Video Composition and Export Source: https://context7.com/galis/opentiktok/llms.txt Initiates a separate composition process that renders frames using OpenGL, encodes them with MediaCodec (H.264) and AAC, and muxes them into an MP4 file using MediaMuxer. Progress is reported via a callback. ```APIDOC ## AVEngine.compositeMp4() — 视频合成导出 调用 `compositeMp4()` 后,引擎暂停预览,起动独立合成流程:OpenGL 逐帧渲染 → MediaCodec H.264 编码 → AAC 音频编码 → MediaMuxer 混流写入 MP4 文件,通过回调报告 0-100 的进度。 ```java // 配置合成参数 AVEngine.VideoState state = engine.getVideoState(); state.lock(); state.compositePath = "/sdcard/Movies/output.mp4"; state.compositeHeight = 1080; // 1080p 或 720p state.compositeGop = 30; // 帧率 state.compositeVb = 8_000_000; // 视频码率 8Mbps state.compositeAb = 128_000; // 音频码率 128kbps state.unlock(); // 开始合成,回调在合成线程,UI 操作需切换主线程 engine.compositeMp4(progress -> runOnUiThread(() -> { progressBar.setProgress(progress); if (progress == 100) { Toast.makeText(context, "导出完成:" + state.compositePath, Toast.LENGTH_LONG).show(); } })); ``` ``` -------------------------------- ### AVSticker - GIF Sticker Component Source: https://context7.com/galis/opentiktok/llms.txt Integrates GIF stickers into videos. It decodes GIF frames into Bitmaps, uploads them as OpenGL textures, and supports custom display durations, looping, and seeking. ```APIDOC ## AVSticker — GIF 贴纸特效组件 `AVSticker` 支持加载 GIF 动图作为贴纸叠加在视频上,通过内置 `GifDecoder` 解析每帧 Bitmap 并上传为 OpenGL 纹理,默认显示时长 5 秒,支持循环播放与 seek。 ```java // 从 raw 资源加载 GIF 贴纸 InputStream gifStream = context.getResources().openRawResource(R.raw.aini); ImageView stickerView = new ImageView(context); AVSticker sticker = new AVSticker( engine.getMainClock(), // 贴纸起始时间(微秒) gifStream, new ImageViewRender(stickerView) // ImageViewRender 用于在预览层显示 ); engine.addComponent(sticker, args -> previewPanel.post(() -> { previewPanel.updateEffect(); // 按 GIF 原始尺寸显示 stickerView.getLayoutParams().width = sticker.getSize().getWidth(); stickerView.getLayoutParams().height = sticker.getSize().getHeight(); previewContainer.addView(stickerView); stickerView.setTag(sticker); // 拖拽/缩放手势自动同步到组件矩阵 GestureUtils.setupView(stickerView, v -> { sticker.lock(); sticker.setMatrix(MathUtils.calMatrix( new Rect(0, 0, surfaceView.getWidth(), surfaceView.getHeight()), new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()) )); sticker.unlock(); }); })); ``` ``` -------------------------------- ### AVAudio - Audio Component Source: https://context7.com/galis/opentiktok/llms.txt AVAudio encapsulates AAC decoding of audio files, outputting PCM data frames via MediaCodec, driven by the engine's AudioThread for playback. It supports seeking, frame dropping to prevent audio from slowing down playback during A/V sync issues, and an automatic retry mechanism. ```APIDOC ## AVAudio - Audio Component ### Description AVAudio encapsulates AAC decoding of audio files, outputting PCM data frames via MediaCodec, driven by the engine's AudioThread for playback. It supports seeking, frame dropping to prevent audio from slowing down playback during A/V sync issues, and an automatic retry mechanism. ### Usage 1. **Create Audio Component**: Create an AVAudio instance. Typically paired with an AVVideo component from the same file. ```java AVAudio audio = new AVAudio( 0L, // engineStartTime (microseconds) "/sdcard/DCIM/bgm.mp4", null // render: null uses default AudioRender (AudioTrack output) ); ``` 2. **Manual Cropping**: Specify a start and end time for the audio segment to be played. ```java audio.open(); audio.setClipStartTime(5_000_000L); // Start at 5 seconds audio.setClipEndTime(15_000_000L); // End at 15 seconds audio.setEngineEndTime(audio.getEngineStartTime() + audio.getClipDuration()); ``` 3. **Add to Engine**: Add the audio component to the engine. The engine will automatically handle seeking and reading frames during playback. ```java engine.addComponent(audio, callback); ``` ``` -------------------------------- ### AVPag - PAG Animation Component Source: https://context7.com/galis/opentiktok/llms.txt Integrates Tencent's PAG (Portable Animation Graphics) library. It supports loading `.pag` files for overlaying animations on video, suitable for intros, outros, and dynamic stickers. ```APIDOC ## AVPag — PAG 动效组件 `AVPag` 集成腾讯 PAG 动效库,支持加载 `.pag` 文件叠加到视频画面,由 `PAGPlayer` 驱动逐帧渲染到 OpenGL 纹理,适合片头片尾动画、贴纸动效等场景。 ```java // 加载 assets 目录下的 PAG 文件 PAGView pagView = new PAGView(context); AVPag avPag = new AVPag( "pag/time_test.pag", // assets 路径 engine.getMainClock(), // 引擎起始时间 new PagRender(pagView) // PagRender 负责预览层渲染 ); engine.addComponent(avPag, args -> previewPanel.post(() -> { previewPanel.updateEffect(); // 按 PAG 文件原始尺寸等比缩放 int h = Math.min(surfaceView.getHeight(), avPag.getSize().getHeight()); int w = (int)(h * avPag.getSize().getWidth() / (float)avPag.getSize().getHeight()); pagView.getLayoutParams().width = w; pagView.getLayoutParams().height = h; previewContainer.addView(pagView); pagView.setTag(avPag); pagView.requestLayout(); })); ``` ``` -------------------------------- ### AVTransaction - Transition Component Source: https://context7.com/galis/opentiktok/llms.txt Handles transition effects between adjacent video segments. Currently supports Alpha fading (`TRAN_ALPHA`). Configuration includes transition type, duration, and visibility. ```APIDOC ## AVTransaction — 转场组件 `AVTransaction` 在两段相邻视频之间实现转场效果,目前支持 Alpha 渐变(`TRAN_ALPHA`)。通过 `write()` 配置转场类型、时长及可见性,引擎会在转场时间窗内自动用 `TransactionRender` 替代普通视频渲染。 ```java // 转场组件由 AVEngine 在 addComponent(AVVideo) 时自动创建,也可手动配置 List transactions = engine.findComponents( AVComponent.AVComponentType.TRANSACTION, -1); if (!transactions.isEmpty()) { AVTransaction tran = (AVTransaction) transactions.get(0); Map config = new HashMap<>(); config.put("tran_type", AVTransaction.TRAN_ALPHA); // 渐变转场 config.put("tran_duration", 1_000_000L); // 转场时长 1 秒 config.put("tran_visible", true); // 启用转场 engine.changeComponent(tran, config, args -> { engine.fastSeek(tran.getEngineStartTime()); // 跳到转场起点预览效果 }); } // 关闭转场(恢复直接拼接) config.put("tran_visible", false); engine.changeComponent(tran, config, null); ``` ``` -------------------------------- ### Batch Clear All Stickers from AVEngine Source: https://context7.com/galis/opentiktok/llms.txt Finds all components of type STICKER and removes them from the engine. This is useful for clearing all stickers at once. ```java List stickers = engine.findComponents( AVComponent.AVComponentType.STICKER, -1); for (AVComponent s : stickers) { engine.removeComponent(s); } ``` -------------------------------- ### Crop Video Segments with AVEngine.changeComponent() Source: https://context7.com/galis/opentiktok/llms.txt Modifies component time ranges using `comm_src` (original time range) and `comm_dst` (target time range) Rect objects. This internally calculates offsets for `ClipStartTime` and `ClipEndTime`. Useful for trimming video clips via a timeline control. ```java // 裁剪视频片段(通过拖动时间轴控件触发) Map clipConfig = new HashMap<>(); clipConfig.put("comm_src", new Rect(0, 0, 300, 1)); // 原始范围(像素/时间轴坐标) clipConfig.put("comm_dst", new Rect(30, 0, 270, 1)); // 裁剪后范围(前后各剪掉 10%) engine.changeComponent( engine.getVideoState().editComponent, clipConfig, args -> { engine.fastSeek(engine.getMainClock()); // 刷新预览 runOnUiThread(() -> previewPanel.updateData(engine.getVideoState())); } ); ``` -------------------------------- ### AVEngine.changeComponent() - Cropping/Modifying Component Time Source: https://context7.com/galis/opentiktok/llms.txt Describes cropping operations using `comm_src` (original time range) and `comm_dst` (target time range) Rect objects. The engine internally calculates the offsets for ClipStartTime/ClipEndTime. ```APIDOC ## AVEngine.changeComponent() — 裁剪/修改组件时间 通过 `comm_src`(原始时间范围 Rect)和 `comm_dst`(目标时间范围 Rect)两个 Rect 对象描述裁剪操作,引擎内部换算为 ClipStartTime/ClipEndTime 的偏移量。 ```java // 裁剪视频片段(通过拖动时间轴控件触发) Map clipConfig = new HashMap<>(); clipConfig.put("comm_src", new Rect(0, 0, 300, 1)); // 原始范围(像素/时间轴坐标) clipConfig.put("comm_dst", new Rect(30, 0, 270, 1)); // 裁剪后范围(前后各剪掉 10%) engine.changeComponent( engine.getVideoState().editComponent, clipConfig, args -> { engine.fastSeek(engine.getMainClock()); // 刷新预览 runOnUiThread(() -> previewPanel.updateData(engine.getVideoState())); } ); ``` ``` -------------------------------- ### Add Dynamic Text Effects with AVWord Source: https://context7.com/galis/opentiktok/llms.txt Create an AVWord component to render text from an Android EditText onto the video canvas. Supports real-time text updates and transformation via matrix for position and scaling. The EditText is added to the preview container and linked to gesture detection for interactive manipulation. ```java // 在视频编辑界面动态添加文字 EditText editText = new EditText(context); editText.setText("Hello OpenTikTok!"); editText.setTextColor(Color.WHITE); editText.setTextSize(24f); AVWord word = new AVWord( engine.getMainClock(), // 当前播放时间作为文字起始时间 editText, new TextRender(editText) // TextRender 负责把 EditText 内容上屏 ); engine.addComponent(word, args -> previewPanel.post(() -> { previewPanel.updateEffect(); // 将 EditText 添加到预览容器,手势缩放/移动后自动更新矩阵 previewContainer.addView(editText); editText.setTag(word); GestureUtils.setupView(editText, v -> { word.lock(); word.setMatrix(MathUtils.calMatrix( new Rect(0, 0, surfaceView.getWidth(), surfaceView.getHeight()), new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()) )); word.unlock(); }); })); ``` -------------------------------- ### AVEngine.setCanvasType() - Canvas Aspect Ratio Setting Source: https://context7.com/galis/opentiktok/llms.txt Dynamically adjusts the `SurfaceView` size and OpenGL transformation matrix based on preset aspect ratio strings (e.g., "16:9", "9:16"). It also calculates the target resolution for the composite output. ```APIDOC ## AVEngine.setCanvasType() — 画布比例设置 根据预设比例字符串("原始"、"16:9"、"9:16"、"4:3"、"3:4"、"1:1")动态调整 `SurfaceView` 尺寸与 OpenGL 变换矩阵,同步计算合成输出的目标分辨率。 ```java // 支持的比例:原始 / 16:9 / 9:16 / 4:3 / 3:4 / 1:1 engine.setCanvasType("9:16", args -> { Size size = (Size) args[0]; // 返回调整后的像素尺寸 previewContainer.post(() -> { previewContainer.getLayoutParams().width = size.getWidth(); previewContainer.getLayoutParams().height = size.getHeight(); previewContainer.requestLayout(); }); }); // 设置背景填充色(信箱区域) engine.setBgColor(Color.BLACK); ``` ``` -------------------------------- ### AVWord - Text Effect Component Source: https://context7.com/galis/opentiktok/llms.txt AVWord renders the content of an Android EditText into a Bitmap texture, which is then overlaid onto the video. It supports real-time text modification (driven by TextWatcher) and has a default duration of 5 seconds. Position and scaling can be controlled via matrix transformations. ```APIDOC ## AVWord - Text Effect Component ### Description AVWord renders the content of an Android EditText into a Bitmap texture, which is then overlaid onto the video. It supports real-time text modification (driven by TextWatcher) and has a default duration of 5 seconds. Position and scaling can be controlled via matrix transformations. ### Usage 1. **Create Text Component**: Create an AVWord instance, typically initiated at the current playback time. ```java EditText editText = new EditText(context); editText.setText("Hello OpenTikTok!"); editText.setTextColor(Color.WHITE); editText.setTextSize(24f); AVWord word = new AVWord( engine.getMainClock(), // Start time at current playback position editText, new TextRender(editText) // TextRender handles rendering EditText content ); ``` 2. **Add to Engine and UI**: Add the text component to the engine and the EditText to the preview container. Use gesture detection to update the text's transformation matrix. ```java engine.addComponent(word, args -> previewPanel.post(() -> { previewPanel.updateEffect(); // Add EditText to preview container and enable gesture controls previewContainer.addView(editText); editText.setTag(word); GestureUtils.setupView(editText, v -> { word.lock(); word.setMatrix(MathUtils.calMatrix(...)); // Calculate matrix based on view position/size word.unlock(); }); })); ``` ``` -------------------------------- ### AVEngine.removeComponent() Source: https://context7.com/galis/opentiktok/llms.txt Removes a specified component (video, audio, text, sticker, etc.) from the engine timeline. The engine automatically recalculates the total duration after removal. ```APIDOC ## AVEngine.removeComponent() ### Description Removes a specified component (video, audio, text, sticker, etc.) from the engine timeline. The engine automatically recalculates the total duration after removal. ### Method Signature `void removeComponent(AVComponent component)` ### Parameters - **component** (AVComponent) - Required - The component to be removed from the engine timeline. ### Usage Examples ```java // Example: Remove a component when its preview layer element is long-pressed view.setOnLongClickListener(v -> { AVComponent component = (AVComponent) v.getTag(); engine.removeComponent(component); previewContainer.removeView(v); runOnUiThread(() -> previewPanel.updateData(engine.getVideoState())); return true; }); // Batch clear all stickers List stickers = engine.findComponents( AVComponent.AVComponentType.STICKER, -1); for (AVComponent s : stickers) { engine.removeComponent(s); } ``` ``` -------------------------------- ### AVVideo - Video Component Source: https://context7.com/galis/opentiktok/llms.txt AVVideo encapsulates the decoding of a single video file segment using MediaCodec and MediaExtractor for hardware-accelerated decoding, outputting OES textures for OpenGL rendering. It parses video duration, resolution, and frame rate upon opening and sets ClipTime/EngineTime. ```APIDOC ## AVVideo - Video Component ### Description AVVideo encapsulates the decoding of a single video file segment using MediaCodec and MediaExtractor for hardware-accelerated decoding, outputting OES textures for OpenGL rendering. It parses video duration, resolution, and frame rate upon opening and sets ClipTime/EngineTime. ### Usage 1. **Create and Add Video Component**: Create an AVVideo instance and add it to the engine. The `isTextureType` parameter determines if OES textures or ByteBuffers are output. ```java AVVideo video = new AVVideo( true, // isTextureType: true for OES texture output, false for ByteBuffer -1L, // engineStartTime: -1 to append to the end of the current track "/sdcard/DCIM/clip1.mp4", null // render: null uses the engine's default OESRender ); engine.addComponent(video, callback); ``` 2. **Add Corresponding Audio Component**: If the video has audio, add a corresponding AVAudio component. ```java AVAudio audio = new AVAudio(-1L, "/sdcard/DCIM/clip1.mp4", null); engine.addComponent(audio, callback); ``` 3. **Callback**: The callback is executed on the Engine thread; UI operations require switching to the main thread. ```java // Example callback for adding video component engine.addComponent(video, args -> runOnUiThread(() -> { // Set canvas aspect ratio after video loading engine.setCanvasType("Original", sizeArgs -> { Size size = (Size) sizeArgs[0]; // Update layout parameters based on video size }); previewPanel.updateData(engine.getVideoState()); })); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.