PAG官网 | PAG动效

PAG官网 | PAG动效

  • 首页
  • 产品
  • 功能
  • 文档
  • 案例
  • CN
  • GitHub
  • 论坛交流
  • 免费下载
  • Languages iconEN
    • CN

›移动端进阶

了解 PAG

  • Introduction
  • FAQs

快速开始

  • Install PAGViewer
  • Install PAGExporter
  • Export PAG Files
  • SDK Integration

导出插件

  • Use Configuration Panel
  • Use Exporting Panel
  • Export BMP Compositions
  • Config Fill Modes
  • Config Time Stretch Modes
  • Exporting Shortcut Keys
  • Error Code
  • Auto Detection Rules
  • Text Editing Rules
  • Add Text Background
  • Export Audio
  • Manually Install PAGExporter

预览工具

  • Preview Replacements
  • View File Structure
  • Preview Shortcut Keys
  • Export Image Sequence
  • File Encryption
  • Add Watermark
  • Upgrade to Beta Version

性能优化

  • Use Performance Panel
  • PAG File Optimization

移动端进阶

  • Common API Overview
  • Use PAGImageView
  • Video Replacement
  • Play Audio
  • Text Layer Description
  • Use Encripted File
  • Export To Video
  • SDK Authentication

Web 进阶

  • SDK Installation
  • Load PAG File
  • Play PAG File
  • Platform Capabilities
  • Use WebWorker

API 参考

  • API Document

视频教程

  • PAG Workflow
  • File Optimization Best Practices
  • Use PAGExporter Panel
  • PAG Online Q&A

资源下载

  • PAGViewer Installer
  • PAG Test Files
  • PAG Demo Projects
  • China LiveVideoStackCon2022
  • PAG Conversion Tool
  • PAG File Format Spec

TAVMedia

  • Introduction to TAVMedia
  • TAVMedia Quick access
  • Common API Overview

其他

  • From Lottie To PAG
  • PAG Dictionary

Video Replacement


The PAG SDK is designed specifically for rendering effects. However, the Community Edition does not support audio and video-related content. If you require the option to replace videos with placeholder images, you should consider using the PAG Enterprise Edition.

The PAG Enterprise Edition (the package name has a movie suffix) includes the Movie function, which allows the creation of a PAGMovie using video materials. PAGMovie inherits from PAGImage and can seamlessly replaces the placeholder image of PAGImageLayer. Once replaced, PAGView, PAGPlayer and PAGAudioPlayer will automatically update their internal data and can be presented without any additional steps.

PAGMovie inherits the complete features of PAGImage and the detailed documentation of PAGImage can be found in Android | iOS.

The encapsulation formats supported by PAGMovie are mov, mp4, m4a, 3gp, 3g2, mj2, and the supported encoding formats are h264 and h265 (hevc).

Use Flow

1、Build a PAGMovie Instance

PAGMovie supports building through the native video path and allows for cropping and variable speed and volume settings.

android:

// Method 1: Generate a PAGMovie through the file path, without changing the speed in the default complete interval: duration = file duration us, speed = 1.0f, volume = 1.0f
PAGMovie movie = PAGMovie.MakeFromFile (MOVIE_FILE_PATH);
// Method 2: Generate a PAGMovie through the file path and set the attributes. The parameters here indicate to select the complete interval of the video material. The speed is not changed, and the volume is 0
PAGMovie silentMovie = PAGMovie.MakeFromFile (MOVIE_FILE_PATH, -1, -1, 1, 0);
// Method 3: Generate a PAGMovie through the file path and set the attributes. The parameters here indicate that the video material is selected for 1~3 seconds. The speed is set to 0.5 times, and the volume is 0.5
PAGMovie cutMovie = PAGMovie.MakeFromFile (MOVIE_FILE_PATH, 1_000_000, 2_000_000, 0.5f, 0.5f);

iOS:

// Method 1: Generate a PAGMovie through the file path. Default starttime = 0 us, and duration = file duration us, speed = 1.0f, volume = 1.0f
PAGMovie *movie = [PAGMovie MakeFromFile:moviePath];
// Method 2: Generate a PAGMovie through the file path and set the attributes. The parameters here indicate that the video material is selected for 1~3 seconds. The speed is set to 0.5 times, and the volume is 0.5
// When startTime and duration are both - 1, PAGMovie will automatically adapt to the full duation of the video
movie = [PAGMovie MakeFromFile:moviePath startTime:1*1000*1000 duration:2*1000*1000 speed:0.5f volume:0.5f];

2、Replace the Placeholder Image

PAGMovie is a subclass of PAGImage, and the method of replacing placeholder images is consistent with that of PAGImage.

Note: When the video duration is shorter than the required duration of the image layer, the video will freeze at the last frame.

Code Examples

android:

// Method 1 : Directly replace the image resource
for (int i = 0; i < selectData.size() && i < pagFile.numImages(); i++) {
    PAGMovie movie = makePAGMovie(selectData.get(i));
    pagFile.replaceImage(i, movie);
}
// Method 2 : Replace with the editable layer
int[] indices = pagFile.getEditableIndices(PAGLayer.LayerTypeImage);
for (int i = 0; i < selectData.size() && i < indices.length; i++) {
    PAGMovie movie = makePAGMovie(selectData.get(i));
    PAGLayer[] pagLayers = pagFile
            .getLayersByEditableIndex(indices[i], PAGLayer.LayerTypeImage);
    for (PAGLayer layer : pagLayers) {
        ((PAGImageLayer) layer).setImage(movie);
    }
}

iOS

// Method 1: Directly replaced by PAGFile
for (int i = 0; i < moviePaths.count && i < pagFile.numImages; i++) {
    PAGMovie *movie = [PAGMovie MakeFromFile:moviePaths[i]];
    [pagFile replaceImage:i data:movie];
}


// Method 2: Replaced by PAGImageLayer
NSArray *indices = [pagFile getEditableIndices:PAGLayerTypeImage];
for (NSUInteger i = 0; i < moviePaths.count && i < indices.count; i++) {
  PAGMovie *movie = [PAGMovie MakeFromFile:moviePaths[i]];
  NSArray *imageLayers = [pagFile getLayersByEditableIndex:indices[i] layerType:PAGLayerTypeImage];
  for (PAGImageLayer *layer in imageLayer) {
      [layer setImage:movie];
  }
}
← Use PAGImageViewPlay Audio →
  • Use Flow
    • 1、Build a PAGMovie Instance
    • 2、Replace the Placeholder Image
Address: Tencent Binhai Building, No. 33 Haitian Second Road, Nanshan District, Shenzhen, Guangdong Province, China.
TEL: 0755-86013388
QQ Group: 893379574
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
Privacy Policy
公司地址:广东省深圳市南山区海天二路33号腾讯滨海大厦
联系电话:0755-86013388
QQ群:893379574
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
隐私政策
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
Address: Tencent Binhai Building, No. 33 Haitian Second Road, Nanshan District, Shenzhen, Guangdong Province, China.
TEL: 0755-86013388
QQ Group: 893379574
Privacy Policy
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
公司地址:广东省深圳市南山区海天二路33号腾讯滨海大厦
联系电话:0755-86013388
QQ群:893379574
隐私政策