【Android】使用MediaCodec硬编码实现视频直播推流端(一)
2016年06月15日 18:37:15 gitzzp 阅读数:7162 标签: 视频 直播 推流 MediaCodec 硬编码 更多
个人分类: 多媒体相关
版权声明:本文为博主原创文章,转载请注明来源。 https://blog.youkuaiyun.com/gitzzp/article/details/51684466
废话不说,直接上代码。
布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.gitzzp.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="publish"
android:id="@+id/publish"
android:layout_alignParentTop="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop"
android:id="@+id/stop"
android:layout_toRightOf="@id/publish"
android:layout_marginTop="0dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="switch"
android:id="@+id/swCam"
android:layout_alignBottom="@id/stop"
android:layout_toRightOf="@id/stop" />
<EditText
android:id="@+id/vbitrate"
android:textSize="14dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/publish"
android:layout_marginTop="0dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:id="@+id/url"
android:layout_below="@id/publish"
android:layout_above="@+id/frameLayout"
android:layout_toRightOf="@id/vbitrate" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/vbitrate"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:id="@+id/frameLayout">
<com.example.gitzzp.CameraPreview
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/preview" />
</FrameLayout>
</RelativeLayout>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
非常简单的布局,没什么可说的,唯一要说的就是最后边这个CameraPreview,这是一个自定义控件,继承自SurfaceView,用于显示摄像头的预览,具体代码后边会贴出来。
MainActivity:
package com.example.gitzzp;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
private SharedPreferences sp;
private CameraPreview mCameraView = null;
private String mNotifyMsg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//保持屏幕常亮
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main1);
// 响应屏幕旋转事件
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
// 本地存储数据
sp = getSharedPreferences("SrsPublisher", MODE_PRIVATE);
SrsEncoder.rtmpUrl = sp.getString("rtmpUrl", SrsEncoder.rtmpUrl);
SrsEncoder.vbitrate = sp.getInt("vbitrate", SrsEncoder.vbitrate);
Log.i(TAG, String.format("init rtmp url %s, vbitrate=%dkbps", SrsEncoder.rtmpUrl, SrsEncoder.vbitrate));
// 设置程序刚开始显示的url
final EditText efu = (EditText) findViewById(R.id.url);
efu.setText(SrsEncoder.rtmpUrl);
// 设置初始化时的视频码率
final EditText evb = (EditText) findViewById(R.id.vbitrate);
evb.setText(String.format("%dkbps", SrsEncoder.vbitrate / 1000));
// for camera, @see https://developer.android.com/reference/android/hardware/Camera.html
final Button btnPublish = (Button) findViewById(R.id.publish);
final Button btnStop = (Button) findViewById(R.id.stop);
final Button btnSwitch = (Button) findViewById(R.id.swCam);
//布局中的surfaceview
mCameraView = (CameraPreview) findViewById(R.id.preview);
btnPublish.setEnabled(true);
btnStop.setEnabled(false);
btnPublish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int vb = Integer.parseInt(evb.getText().toString().replaceAll("kbps", ""));
SrsEncoder.vbitrate = vb * 1000;
SrsEncoder.rtmpUrl = "替换为你自己想要推流的rtmp服务器地址";
Log.i(TAG, String.format("RTMP URL changed to %s", SrsEncoder.rtmpUrl));
Log.i(TAG, String.format("Video bitrate changed to %skbps", SrsEncoder.vbitrate / 1000));
SharedPreferences.Editor editor = sp.edit();
editor.putInt("vbitrate", SrsEncoder.vbitrate);
editor.putString("rtmpUrl", SrsEncoder.rtmpUrl);
editor.commit();
btnPublish.setEnabled(false);
btnStop.setEnabled(true);
//发布直播
mCameraView.startPublish();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCameraView.stopPublish();
btnPublish.setEnabled(true);
btnStop.setEnabled(false);
}
});
btnSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCameraView.initCameraPreview(1);
}
});
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
mNotifyMsg = ex.getMessage();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), mNotifyMsg,Toast.LENGTH_SHORT).show();
btnPublish.setEnabled(true);
btnStop.setEnabled(false);
mCameraView.stopPublish();
}
});
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
final Button btn = (Button) findViewById(R.id.publish);
btn.setEnabled(true);
mCameraView.handler.postDelayed(new Runnable() {
@Override
public void run() {
mCameraView.initCameraPreview();
}
},100);
}
@Override
protected void onPause() {
super.onPause();
mCameraView.stopPublish();
//停止预览
mCameraView.stopCamera();
}
@Override
protected void onDestroy() {
super.onDestroy();
mCameraView.stopPublish();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mCameraView.stopPublish();
mCameraView.mEncoder.setScreenOrientation(newConfig.orientation);
mCameraView.startPublish();
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
在MainActivity中做了一些控件和数据的初始化,监听事件的添加,以及在各个生命周期中对surfaceview和camera的控制等操作。
当我们点击publish按钮的时候,会根据我们设置的推流地址,码率等,调用surfaceview中的startPublish()来开始推流。swtich用于切换前置后置摄像头。
CameraPreview:接收camera中的数据,并显示出来,作为camera的预览图像。
package com.example.gitzzp;
import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
import com.example.gitzzp.rtmp.RtmpPublisher;
import java.io.IOException;
import java.util.List;
/**
* 相机预览图像
* Created by gitzzp on 16/6/2.
*/
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback, Camera.PreviewCallback {
private static final String TAG = "CameraPreview";
private SurfaceHolder mHolder;
private Activity mContext;
private AudioRecord mic = null;
private boolean isPublish = false;
private Thread aworker = null;//音频录制的线程
public Camera mCamera = null;
private int mPreviewRotation = 90;
private int mDisplayRotation = 90;
private int mCamId = Camera.getNumberOfCameras() - 1; // default camera 该设备的摄像头数量
// private byte[] mYuvFrameBuffer = new byte[SrsEncoder.VWIDTH * SrsEncoder.VHEIGHT * 3 / 2];
private byte[] mYuvFrameBuffer = new byte[SrsEncoder.VWIDTH * SrsEncoder.VHEIGHT * 3 *10];
private String mNotifyMsg;
Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 1:
initCameraPreview();
break;
}
}
};
public CameraPreview(Context context) {
this(context,null);
}
public CameraPreview(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
public CameraPreview(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = (Activity) context;
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setKeepScreenOn(true);
}
public void initCameraPreview(){
if (mCamera != null && mEncoder != null) {
stopCamera();
startCamera();
}else if(mCamera == null && mEncoder != null) {
startCamera();
}
}
public void initCameraPreview(int num) {
if (mCamera != null && mEncoder != null) {
mCamId = (mCamId + num) % Camera.getNumberOfCameras();
stopCamera();
mEncoder.swithCameraFace();
startCamera();
}else if(mCamera == null && mEncoder != null) {
mCamId = (mCamId + num) % Camera.getNumberOfCameras();
mEncoder.swithCameraFace();
startCamera();
}
}
//开始推流
public void startPublish() {
int ret = mEncoder.start();
//小于0表示有某个地方出错 但是SrsEncoder中没有做具体区分 统一以-1来进行返回 后期可以根据需求分别进行处理
//返回0表示流创建成功
if (ret < 0) {
return;
}
//开启摄像头
startCamera();
aworker = new Thread(new Runnable() {
@Override
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
startAudio();
}
});
isPublish = true;
aworker.start();
}
public void startCamera() {
if (mCamera != null) {
Log.d(TAG, "start camera, already started. return");//摄像头已经开启
return;
}
if (mCamId > (Camera.getNumberOfCameras() - 1) || mCamId < 0) {
Log.e(TAG, "####### start camera failed, inviald params, camera No.="+ mCamId);
return;
}
mCamera = Camera.open(mCamId);
Camera.CameraInfo info = new Camera.CameraInfo();
//获取摄像头信息
Camera.getCameraInfo(mCamId, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT){//前置摄像头
mDisplayRotation = (mPreviewRotation + 180) % 360;
mDisplayRotation = (360 - mDisplayRotation) % 360;
} else {
mDisplayRotation = mPreviewRotation;
}
Camera.Parameters params = mCamera.getParameters();
/* preview size */
Camera.Size size = mCamera.new Size(SrsEncoder.VWIDTH, SrsEncoder.VHEIGHT);
if (!params.getSupportedPreviewSizes().contains(size)) {
//摄像头预览尺寸小于我们设置的预览尺寸 抛出异常
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
new IllegalArgumentException(String.format("Unsupported preview size %dx%d", size.width, size.height)));
}
/* picture size */
if (!params.getSupportedPictureSizes().contains(size)) {
//图片尺寸小于我们设置的图片尺寸
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
new IllegalArgumentException(String.format("Unsupported picture size %dx%d", size.width, size.height)));
}
/***** set parameters *****/
//params.set("orientation", "portrait");
//params.set("orientation", "landscape");
// params.setRotation(180);
params.setPictureSize(SrsEncoder.VWIDTH, SrsEncoder.VHEIGHT);
//设置预览时的大小
params.setPreviewSize(SrsEncoder.VWIDTH, SrsEncoder.VHEIGHT);
//设置帧数
int[] range = findClosestFpsRange(SrsEncoder.VFPS, params.getSupportedPreviewFpsRange());
params.setPreviewFpsRange(range[0], range[1]);
//预览图格式
params.setPreviewFormat(SrsEncoder.VFORMAT);
//闪光灯控制
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
//白平衡控制
params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
//设置情景模式 改变该参数可以覆盖上边的几个参数 例如 最初闪光灯是开启的 在变成夜间模式之后 会关闭
params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
//设置自动对焦 共分两步 这是第一步
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
mCamera.setParameters(params);
//预览图显示的角度
mCamera.setDisplayOrientation(mPreviewRotation);
//缓冲区大小
mCamera.addCallbackBuffer(mYuvFrameBuffer);
//设置自动对焦的第二步
mCamera.cancelAutoFocus();
mCamera.setPreviewCallbackWithBuffer(this);
try {
//设置surfacebview显示摄像头的预览界面
mCamera.setPreviewDisplay(mHolder);
} catch (IOException e) {
e.printStackTrace();
}
mCamera.startPreview();
}
private int[] findClosestFpsRange(int expectedFps, List<int[]> fpsRanges) {
expectedFps *= 1000;
int[] closestRange = fpsRanges.get(0);
int measure = Math.abs(closestRange[0] - expectedFps) + Math.abs(closestRange[1] - expectedFps);
for (int[] range : fpsRanges) {
if (range[0] <= expectedFps && range[1] >= expectedFps) {
int curMeasure = Math.abs(range[0] - expectedFps) + Math.abs(range[1] - expectedFps);
if (curMeasure < measure) {
closestRange = range;
measure = curMeasure;
}
}
}
return closestRange;
}
public void stopCamera() {
if (mCamera != null) {
// need to SET NULL CB before stop preview!!!
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
}
private void onGetYuvFrame(byte[] data) {
mEncoder.onGetYuvFrame(data);
}
@Override
public void onPreviewFrame(byte[] data, Camera c) {
// onGetYuvFrame(data);
//点击推流之后开始推流
if(isPublish){
onGetYuvFrame(data);
}
c.addCallbackBuffer(mYuvFrameBuffer);
}
private void onGetPcmFrame(byte[] pcmBuffer, int size) {
mEncoder.onGetPcmFrame(pcmBuffer, size);
}
//开始录音
private void startAudio() {
if (mic != null) {
return;
}
int bufferSize = 2 * AudioRecord.getMinBufferSize(SrsEncoder.ASAMPLERATE, SrsEncoder.ACHANNEL, SrsEncoder.AFORMAT);
mic = new AudioRecord(MediaRecorder.AudioSource.MIC, SrsEncoder.ASAMPLERATE, SrsEncoder.ACHANNEL, SrsEncoder.AFORMAT, bufferSize);
mic.startRecording();
byte pcmBuffer[] = new byte[4096];
while (isPublish && !Thread.interrupted()) {
int size = mic.read(pcmBuffer, 0, pcmBuffer.length);
if (size <= 0) {
Log.e(TAG, "***** audio ignored, no data to read.");
break;
}
onGetPcmFrame(pcmBuffer, size);
}
}
private void stopAudio() {
isPublish = false;
if (aworker != null) {
Log.i(TAG, "stop audio worker thread");
aworker.interrupt();
try {
aworker.join();
} catch (InterruptedException e) {
e.printStackTrace();
aworker.interrupt();
}
aworker = null;
}
if (mic != null) {
mic.setRecordPositionUpdateListener(null);
mic.stop();
mic.release();
mic = null;
}
}
//停止推流之后 预览状态不应该停 也就是说我们应该在destory中停止摄像头 而不是在这里
public void stopPublish() {
stopAudio();
// stopCamera();
mEncoder.stop();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
public SrsEncoder mEncoder = new SrsEncoder(new RtmpPublisher.EventHandler() {
@Override
public void onRtmpConnecting(String msg) {
mNotifyMsg = msg;
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, mNotifyMsg, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onRtmpConnected(String msg) {
mNotifyMsg = msg;
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, mNotifyMsg, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onRtmpVideoStreaming(String msg) {
}
@Override
public void onRtmpAudioStreaming(String msg) {
}
@Override
public void onRtmpStopped(String msg) {
mNotifyMsg = msg;
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, mNotifyMsg, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onRtmpDisconnected(String msg) {
mNotifyMsg = msg;
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, mNotifyMsg, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onRtmpOutputFps(final double fps) {
Log.i(TAG, String.format("Output Fps: %f", fps));
}
});
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
CameraPreview继承自SurfaceView并且实现了SurfaceHolder.Callback和 Camera.PreviewCallback两个接口。
SurfaceHolder.Callback用于监听SurfaceView的创建、改变、销毁等操作,本来应该在这里完成对摄像头的init和release等操作,这里偷了个懒。
Camera.PreviewCallback用于接收camera的预览,对应onPreviewFrame()方法,我们可以在这里对摄像头传回的数据做一些自己需要的处理,我们在这里调用了另外的类对我们摄像头传回的数据进行了YUV编码。