Regarding frequently asked questions among developers, Tencent Cloud offers an easy-to-understand API example project, which you can use to quickly learn how to use different APIs.
Platform | GitHub Address |
---|---|
iOS | Github |
Android | Github |
If you need to process video by yourself (for example, add subtitles) but want to leave the rest of the process to LiteAVSDK, follow the steps below.
V2TXLivePusher
to enable custom video processing, so that you will receive the callback of video data.dstFrame.textureId
to a new texture ID in the callback API. - (void) onProcessVideoFrame:(V2TXLiveVideoFrame _Nonnull)srcFrame dstFrame:(V2TXLiveVideoFrame _Nonnull)dstFrame
{
GLuint dstTextureId = renderItemWithTexture(srcFrame.textureId, srcFrame.width, srcFrame.height);
dstFrame.textureId = dstTextureId;
}
- (void) onProcessVideoFrame:(V2TXLiveVideoFrame _Nonnull)srcFrame dstFrame:(V2TXLiveVideoFrame _Nonnull)dstFrame
{
thirdparty_process(srcFrame.textureId, srcFrame.width, srcFrame.height, dstFrame.textureId);
}
onProcessVideoFrame
is called at the same frequency as the frame rate, and sophisticated processing may cause GPU overheating.If you need to process video by yourself (for example, add subtitles) but want to leave the rest of the process to LiteAVSDK, follow the steps below.
V2TXLivePusher
to enable custom video processing, so that you will receive the callback of video data.dstFrame.textureId
to a new texture ID in the callback API.private class MyPusherObserver extends V2TXLivePusherObserver {
@Override
public void onGLContextCreated() {
mFURenderer.onSurfaceCreated();
mFURenderer.setUseTexAsync(true);
}
@Override
public int onProcessVideoFrame(V2TXLiveVideoFrame srcFrame, V2TXLiveVideoFrame dstFrame) {
dstFrame.texture.textureId = mFURenderer.onDrawFrameSingleInput(
srcFrame.texture.textureId, srcFrame.width, srcFrame.height);
return 0;
}
@Override
public void onGLContextDestroyed() {
mFURenderer.onSurfaceDestroyed();
}
}
@Override
public int onProcessVideoFrame(V2TXLiveVideoFrame srcFrame, V2TXLiveVideoFrame dstFrame) {
thirdparty_process(srcFrame.texture.textureId, srcFrame.width, srcFrame.height, dstFrame.texture.textureId);
return 0;
}
onProcessVideoFrame
is called at the same frequency as the frame rate, and sophisticated processing may cause GPU overheating.@interface V2TXLivePlayer : NSObject
/**
* @brief Set callbacks for the player<br>
* After setting callbacks, you can listen for events of V2TXLivePlayer,
* including the player status, playback volume, first audio/video frame, statistics, and warning and error messages.
*
* @param observer Target object for the player’s callbacks. For more information, see {@link V2TXLivePlayerObserver}
*/
- (void)setObserver:(id<v2txliveplayerobserver>)observer;
/**
* @brief Video frame information
* V2TXLiveVideoFrame is the raw data that describes a video frame before encoding or after decoding
* @note It is used during custom video capturing to package the video frames to be sent, and during custom video rendering to get the packaged video frames
*/
@interface V2TXLiveVideoFrame : NSObject
///**Field meaning:** video pixel format
///**Recommended value:** V2TXLivePixelFormatNV12
@property(nonatomic, assign) V2TXLivePixelFormat pixelFormat;
///**Field meaning:** video data container format
///**Recommended value:** V2TXLiveBufferTypePixelBuffer
@property(nonatomic, assign) V2TXLiveBufferType bufferType;
///**Field meaning:** video data when bufferType is V2TXLiveBufferTypeNSData
@property(nonatomic, strong, nullable) NSData *data;
///**Field meaning:** video data when bufferType is V2TXLiveBufferTypePixelBuffer
@property(nonatomic, assign, nullable) CVPixelBufferRef pixelBuffer;
///**Field meaning:** video width
@property(nonatomic, assign) NSUInteger width;
///**Field meaning:** video height
@property(nonatomic, assign) NSUInteger height;
///**Field meaning:** clockwise rotation of video
@property(nonatomic, assign) V2TXLiveRotation rotation;
/// **Field description:** video texture ID
@property (nonatomic, assign) GLuint textureId;
@end
@protocol V2TXLivePlayerObserver <nsobject>
@optional
/**
* @brief Custom video rendering callback
*
* @note You will receive this callback after calling [enableCustomRendering](@ref V2TXLivePlayer#enableCustomRendering:pixelFormat:bufferType:) to enable custom video rendering
*
* @param videoFrame Video frame data {@link V2TXLiveVideoFrame}
*/
- (void)onRenderVideoFrame:(id<v2txliveplayer>)player
frame:(V2TXLiveVideoFrame *)videoFrame
@end
public abstract void setObserver(V2TXLivePlayerObserver observer)
public final static class V2TXLiveVideoFrame
{
/// Video pixel format
public V2TXLivePixelFormat pixelFormat = V2TXLivePixelFormat.V2TXLivePixelFormatUnknown;
/// Video data container format
public V2TXLiveBufferType bufferType = V2TXLiveBufferType.V2TXLiveBufferTypeUnknown;
/// Video texture pack
public V2TXLiveTexture texture;
/// Video data
public byte[] data;
/// Video data
public ByteBuffer buffer;
/// Video width
public int width;
/// Video height
public int height;
/// Clockwise rotation of video
public int rotation;
}
public abstract class V2TXLivePlayerObserver {
/**
* Callback for custom video rendering
*
* @param player The player object sending this callback
* @param videoFrame Video frame data {@link V2TXLiveVideoFrame}
*/
void onRenderVideoFrame(V2TXLivePlayer player, V2TXLiveVideoFrame videoFrame);
}
Was this page helpful?