W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
視頻編解碼的主要工作是將視頻進行編碼和解碼。
接口名 | 功能描述 |
---|---|
createDecoder() | 創(chuàng)建解碼器Codec實例。 |
createEncoder() | 創(chuàng)建編碼器Codec實例。 |
registerCodecListener(ICodecListener listener) | 注冊偵聽器用來異步接收編碼或解碼后的數(shù)據(jù)。 |
setSource(Source source, TrackInfo trackInfo) | 根據(jù)解碼器的源軌道信息設置數(shù)據(jù)源,對于編碼器trackInfo無效。 |
setSourceFormat(Format format) | 編碼器的管道模式下,設置編碼器編碼格式。 |
setCodecFormat(Format format) | 普通模式設置編/解碼器參數(shù)。 |
setVideoSurface(Surface surface) | 設置解碼器的Surface。 |
getAvailableBuffer(long timeout) | 普通模式獲取可用ByteBuffer。 |
writeBuffer(ByteBuffer buffer, BufferInfo info) | 推送源數(shù)據(jù)給Codec。 |
getBufferFormat(ByteBuffer buffer) | 獲取輸出Buffer數(shù)據(jù)格式。 |
start() | 啟動編/解碼。 |
stop() | 停止編/解碼。 |
release() | 釋放所有資源。 |
在普通模式下進行編解碼,應用必須持續(xù)地傳輸數(shù)據(jù)到 Codec 實例。
編碼的具體開發(fā)步驟如下:
final Codec encoder = Codec.createEncoder();
Format fmt = new Format();
fmt.putStringValue(Format.MIME, Format.VIDEO_AVC);
fmt.putIntValue(Format.WIDTH, 1920);
fmt.putIntValue(Format.HEIGHT, 1080);
fmt.putIntValue(Format.BIT_RATE, 392000);
fmt.putIntValue(Format.FRAME_RATE, 30);
fmt.putIntValue(Format.FRAME_INTERVAL, -1);
codec.setCodecFormat(fmt);
Codec.ICodecListener listener = new Codec.ICodecListener() {
@Override
public void onReadBuffer(ByteBuffer byteBuffer, BufferInfo bufferInfo, int trackId) {
Format fmt = codec.getBufferFormat(byteBuffer);
}
@Override
public void onError(int errorCode, int act, int trackId) {
throw new RuntimeException();
}
};
解碼的具體開發(fā)步驟如下:
Format fmt = new Format();
fmt.putStringValue(Format.MIME, Format.VIDEO_AVC);
fmt.putIntValue(Format.WIDTH, 1920);
fmt.putIntValue(Format.HEIGHT, 1080);
fmt.putIntValue(Format.BIT_RATE, 392000);
fmt.putIntValue(Format.FRAME_RATE, 30);
fmt.putIntValue(Format.FRAME_INTERVAL, -1);
codec.setCodecFormat(fmt);
Codec.ICodecListener listener = new Codec.ICodecListener() {
@Override
public void onReadBuffer(ByteBuffer byteBuffer, BufferInfo bufferInfo, int trackId) {
Format fmt = codec.getBufferFormat(byteBuffer);
}
@Override
public void onError(int errorCode, int act, int trackId) {
throw new RuntimeException();
}
};
管道模式下應用只需要調(diào)用 Source 類的 setSource() 方法,數(shù)據(jù)會自動解析并傳輸給 Codec 實例。管道模式編碼支持視頻流編碼和音頻流編碼。
編碼的具體開發(fā)步驟如下:
Format fmt = new Format();
fmt.putStringValue(Format.MIME, Format.VIDEO_AVC);
fmt.putIntValue(Format.WIDTH, 1920);
fmt.putIntValue(Format.HEIGHT, 1080);
fmt.putIntValue(Format.BIT_RATE, 392000);
fmt.putIntValue(Format.FRAME_RATE, 30);
fmt.putIntValue(Format.FRAME_INTERVAL, -1);
codec.setSourceFormat(fmt);
Codec.ICodecListener listener = new Codec.ICodecListener() {
@Override
public void onReadBuffer(ByteBuffer byteBuffer, BufferInfo bufferInfo, int trackId) {
Format fmt = codec.getBufferFormat(byteBuffer);
}
@Override
public void onError(int errorCode, int act, int trackId) {
throw new RuntimeException();
}
};
解碼的具體開發(fā)步驟如下:
Codec.ICodecListener listener = new Codec.ICodecListener() {
@Override
public void onReadBuffer(ByteBuffer byteBuffer, BufferInfo bufferInfo, int trackId) {
Format fmt = codec.getBufferFormat(byteBuffer);
}
@Override
public void onError(int errorCode, int act, int trackId) {
throw new RuntimeException();
}
};
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: