public class

KSYTranscodeKit

extends Object
java.lang.Object
   ↳ com.ksyun.media.shortvideo.kit.KSYTranscodeKit

Class Overview

Trancode: Demux -> Decode -> Encode -> Mux.

Summary

Constants
float DEFAULT_IFRAME_INTERVAL
int ERROR_DECODER_FAILED
int ERROR_DEMUXER_FAILED
int ERROR_PUBLISHER_FAILED
int INFO_DECODER_STARTED
int INFO_DECODER_STOPPED
int INFO_DEMUXER_STARTED
int INFO_DEMUXER_STOPPED
int INFO_PUBLISHER_ABORTED
int INFO_PUBLISHER_COMPLETED
int INFO_PUBLISHER_STARTED
Fields
protected int mAudioChannels
public FilePublisher.PubListener mFilePublisherListener
Public Constructors
KSYTranscodeKit()
Public Methods
int getAudioBitrate()
float getProgress()
int getVideoBitrate()
int getVideoCodecId()
int getVideoEncodeMethod()
int getVideoEncodeProfile()
float getVideoFps()
void release()
void setAudioBitrate(int bitrate)
Set audio bitrate in bps.
void setAudioChannels(int channels)
Set audio channel number.
void setAudioEncodeProfile(int profile)
Set audio encode profile.
void setAudioKBitrate(int kBitrate)
Set audio bitrate in kbps.
void setAudioSampleRate(int sampleRate)
Set audio sample rate while streaming.
void setEnableMp4FastStart(boolean enable)
Run a second pass moving the index (moov atom) to the beginning of the mp4 file.
void setEncodeMethod(int encodeMethod)
Set encode method for both video and audio.
void setIFrameInterval(float interval)
void setOnErrorListener(KSYTranscodeKit.OnErrorListener onErrorListener)
Set onErrorListener.
void setOnInfoListener(KSYTranscodeKit.OnInfoListener onInfoListener)
Set OnInfoListener.
void setScaleMode(int scaleMode)
void setTargetResolution(int width, int height)
Set transcode target resolution.
void setVideoBitrate(int bitrate)
Set video bitrate in bps, and disable video bitrate auto adjustment.
void setVideoCodecId(int codecId)
Set codec id to video encoder.
void setVideoCrf(int crf)
set Constant Rate Factor
void setVideoDecodeMethod(int decodeMethod)
Set decode method for video.
void setVideoEncodeMethod(int encodeMethod)
Set encode method for video.
void setVideoEncodeProfile(int profile)
Set encode profile to video encoder.
void setVideoFps(float fps)
Sets video fps.
void setVideoKBitrate(int kBitrate)
Set video bitrate in kbps, and disable video bitrate auto adjustment.
void start(String srcUrl, String desUrl)
void stop()
Protected Methods
void setAudioParams()
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final float DEFAULT_IFRAME_INTERVAL

Constant Value: 1.0

public static final int ERROR_DECODER_FAILED

Constant Value: -1000 (0xfffffc18)

public static final int ERROR_DEMUXER_FAILED

Constant Value: -100 (0xffffff9c)

public static final int ERROR_PUBLISHER_FAILED

Constant Value: -2000 (0xfffff830)

public static final int INFO_DECODER_STARTED

Constant Value: 1000 (0x000003e8)

public static final int INFO_DECODER_STOPPED

Constant Value: 1004 (0x000003ec)

public static final int INFO_DEMUXER_STARTED

Constant Value: 101 (0x00000065)

public static final int INFO_DEMUXER_STOPPED

Constant Value: 102 (0x00000066)

public static final int INFO_PUBLISHER_ABORTED

Constant Value: 2002 (0x000007d2)

public static final int INFO_PUBLISHER_COMPLETED

Constant Value: 2001 (0x000007d1)

public static final int INFO_PUBLISHER_STARTED

Constant Value: 2000 (0x000007d0)

Fields

protected int mAudioChannels

public FilePublisher.PubListener mFilePublisherListener

Public Constructors

public KSYTranscodeKit ()

Public Methods

public int getAudioBitrate ()

public float getProgress ()

public int getVideoBitrate ()

public int getVideoCodecId ()

public int getVideoEncodeMethod ()

public int getVideoEncodeProfile ()

public float getVideoFps ()

public void release ()

public void setAudioBitrate (int bitrate)

Set audio bitrate in bps.

Parameters
bitrate audio bitrate in bps.
Throws
IllegalArgumentException

public void setAudioChannels (int channels)

Set audio channel number.
default value : 1

Parameters
channels audio channel number, 1 for mono, 2 for stereo, 0 for input config.
Throws
IllegalArgumentException

public void setAudioEncodeProfile (int profile)

Set audio encode profile.

Parameters
profile profile to set.
See Also
  • AVConst#PROFILE_AAC_LOW
  • AVConst#PROFILE_AAC_HE
  • AVConst#PROFILE_AAC_HE_V2

public void setAudioKBitrate (int kBitrate)

Set audio bitrate in kbps.

Parameters
kBitrate audio bitrate in kbps.
Throws
IllegalArgumentException

public void setAudioSampleRate (int sampleRate)

Set audio sample rate while streaming.
default value 44100

Parameters
sampleRate sample rate in Hz.
Throws
IllegalArgumentException

public void setEnableMp4FastStart (boolean enable)

Run a second pass moving the index (moov atom) to the beginning of the mp4 file. This operation can take a while, and will not work in various situations such as fragmented output, thus it is not enabled by default.

Parameters
enable true to enable, false to disable

public void setEncodeMethod (int encodeMethod)

Set encode method for both video and audio.
Must not be set while encoding. default value:ENCODE_METHOD_SOFTWARE

Parameters
encodeMethod Encode method.
Throws
IllegalStateException
IllegalArgumentException
IllegalStateException
See Also
  • StreamerConstants#ENCODE_METHOD_SOFTWARE
  • StreamerConstants#ENCODE_METHOD_SOFTWARE_COMPAT
  • StreamerConstants#ENCODE_METHOD_HARDWARE

public void setIFrameInterval (float interval)

Parameters
interval I frame interval

public void setOnErrorListener (KSYTranscodeKit.OnErrorListener onErrorListener)

Set onErrorListener.

Parameters
onErrorListener error callback

public void setOnInfoListener (KSYTranscodeKit.OnInfoListener onInfoListener)

Set OnInfoListener.

Parameters
onInfoListener info callback

public void setScaleMode (int scaleMode)

public void setTargetResolution (int width, int height)

Set transcode target resolution.

The set resolution would take effect immediately if compose started.

The set width and height must not be 0 at same time. If one of the params is 0, the other would calculated by the actual preview view size to keep the ratio of the preview view.

Parameters
width streaming width.
height streaming height.
Throws
IllegalArgumentException

public void setVideoBitrate (int bitrate)

Set video bitrate in bps, and disable video bitrate auto adjustment.

Parameters
bitrate video bitrate in bps
Throws
IllegalArgumentException

public void setVideoCodecId (int codecId)

Set codec id to video encoder.

Parameters
codecId video codec id to set.
Throws
IllegalArgumentException
See Also
  • AVConst#CODEC_ID_AVC
  • AVConst#CODEC_ID_HEVC

public void setVideoCrf (int crf)

set Constant Rate Factor

public void setVideoDecodeMethod (int decodeMethod)

Set decode method for video.
Must not be set while decoding.

Parameters
decodeMethod Decode method.
Throws
IllegalStateException
IllegalArgumentException
IllegalStateException
See Also
  • StreamerConstants#DECODE_METHOD_SOFTWARE
  • StreamerConstants#DECODE_METHOD_HARDWARE

public void setVideoEncodeMethod (int encodeMethod)

Set encode method for video.
Must not be set while encoding.

Parameters
encodeMethod Encode method.
Throws
IllegalStateException
IllegalArgumentException
IllegalStateException
See Also
  • StreamerConstants#ENCODE_METHOD_SOFTWARE
  • StreamerConstants#ENCODE_METHOD_SOFTWARE_COMPAT
  • StreamerConstants#ENCODE_METHOD_HARDWARE

public void setVideoEncodeProfile (int profile)

Set encode profile to video encoder.

Only valid in ENCODE_METHOD_SOFTWARE and ENCODE_METHOD_SOFTWARE_COMPAT mode.

Parameters
profile encode profile mode to be set, default value VideoEncodeFormat#ENCODE_PROFILE_LOW_POWER
See Also
  • VideoEncodeFormat#ENCODE_PROFILE_LOW_POWER
  • VideoEncodeFormat#ENCODE_PROFILE_BALANCE
  • VideoEncodeFormat#ENCODE_PROFILE_HIGH_PERFORMANCE

public void setVideoFps (float fps)

Sets video fps.

Parameters
fps the fps

public void setVideoKBitrate (int kBitrate)

Set video bitrate in kbps, and disable video bitrate auto adjustment.

Parameters
kBitrate video bitrate in kbps
Throws
IllegalArgumentException

public void start (String srcUrl, String desUrl)

public void stop ()

Protected Methods

protected void setAudioParams ()