desc:java方式水印适配视频分辨率,考虑旋转

main
xiaowusky 2 years ago
parent 73004fe84d
commit be26453cfe

@ -3,12 +3,14 @@ package org.easydarwin.push;
import android.app.Activity;
import android.app.Application;
import android.app.Service;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.OnLifecycleEvent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@ -30,9 +32,11 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Process;
import android.preference.PreferenceManager;
import androidx.annotation.MainThread;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.Surface;
@ -186,6 +190,7 @@ public class MediaStream extends Service implements LifecycleObserver {
boolean hevcEncode = false;
public String mime = "";
}
public CodecInfo info = new CodecInfo();
@ -403,32 +408,30 @@ public class MediaStream extends Service implements LifecycleObserver {
}
public void onPreviewFrame2(byte[] data, Object camera) {
boolean enableOverlay = PreferenceManager.getDefaultSharedPreferences(mApplicationContext).getBoolean("key_enable_video_overlay", true);
if (camera instanceof Camera) {
if (PreferenceManager.getDefaultSharedPreferences(mApplicationContext).getBoolean("key_enable_video_overlay", true)) {
overlay.javaOverlay(data, "EasyPusher");
}
if (mDgree == 0) {
Camera.CameraInfo camInfo = new Camera.CameraInfo();
Camera.getCameraInfo(mCameraId, camInfo);
int cameraRotationOffset = camInfo.orientation;
if (enableOverlay) {
overlay.javaOverlay(data, width, height, cameraRotationOffset, "EasyPusher");
}
if (mDgree == 0) {
if (cameraRotationOffset % 180 != 0) {
yuvRotate(data, 1, width, height, cameraRotationOffset);
}
save2file(data, String.format("/sdcard/yuv_%d_%d.yuv", height, width));
}
if (PreferenceManager.getDefaultSharedPreferences(mApplicationContext).getBoolean("key_enable_video_overlay", true)) {
String txt;// = String.format("drawtext=fontfile=" + mApplicationContext.getFileStreamPath("SIMYOU.ttf") + ": text='%s%s':x=(w-text_w)/2:y=H-60 :fontcolor=white :box=1:boxcolor=0x00000000@0.3", "EasyPusher", new SimpleDateFormat("yyyy-MM-ddHHmmss").format(new Date()));
txt = "EasyPusher " + new SimpleDateFormat("yy-MM-dd HH:mm:ss SSS").format(new Date());
if (enableOverlay) {
String txt = "EasyPusher " + new SimpleDateFormat("yy-MM-dd HH:mm:ss SSS").format(new Date());
overlay.overlay(data, txt);
}
mVC.onVideo(data, NV21);
mCamera.addCallbackBuffer(data);
} else {
if (PreferenceManager.getDefaultSharedPreferences(mApplicationContext).getBoolean("key_enable_video_overlay", true)) {
String txt;// = String.format("drawtext=fontfile=" + mApplicationContext.getFileStreamPath("SIMYOU.ttf") + ": text='%s%s':x=(w-text_w)/2:y=H-60 :fontcolor=white :box=1:boxcolor=0x00000000@0.3", "EasyPusher", new SimpleDateFormat("yyyy-MM-ddHHmmss").format(new Date()));
txt = "EasyPusher " + new SimpleDateFormat("yy-MM-dd HH:mm:ss SSS").format(new Date());
overlay.javaOverlay(data, txt);
if (enableOverlay) {
String txt = "EasyPusher " + new SimpleDateFormat("yy-MM-dd HH:mm:ss SSS").format(new Date());
overlay.javaOverlay(data, width, height, 0, txt);
overlay.overlay(data, txt);
}
mVC.onVideo(data, NV21);
@ -989,7 +992,6 @@ public class MediaStream extends Service implements LifecycleObserver {
}
/**
*
* @param cameraId 0,1,2uvc,-1(.).-1,ID,.
*/
public Publisher<Object> switchCamera(final int cameraId) {
@ -1245,7 +1247,6 @@ public class MediaStream extends Service implements LifecycleObserver {
}
public static ArrayList<CodecInfo> listEncoders(String mime) {
// 可能有多个编码库,都获取一下。。。
ArrayList<CodecInfo> codecInfos = new ArrayList<CodecInfo>();

@ -22,8 +22,8 @@ public class TxtOverlay {
private final Context context;
int startY = 100;//水印Y轴的位置
int startX = 100;//水印X轴的位置
int startY = 50;//水印Y轴的位置
int startX = 10;//水印X轴的位置
Bitmap bmp;
byte[] mark;
@ -55,15 +55,23 @@ public class TxtOverlay {
txtOverlay(ctx, data, txt);
}
public void javaOverlay(byte[] data,
public void javaOverlay(byte[] data, int width, int height, int cameraRotationOffset,
String txt) {
if (ctx == 0) return;
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
if (cameraRotationOffset == 90) {
startY = height - 50 - bmpHeight;
startX = 10;
} else if (cameraRotationOffset == 270) {
startY = 50;
startX = width - 50 - bmpWidth;
}
int j = 0;
for (int i = startY; i < bmp.getHeight() + startY; i++) {
for (int c = 0; c < bmp.getWidth(); c++) {
for (int i = startY; i < bmpHeight + startY; i++) {
for (int c = 0; c < bmpWidth; c++) {
//去掉PNG水印的黑边
if (mark[j * bmp.getWidth() + c] != 0x10 && mark[j * bmp.getWidth() + c] != 0x80 && mark[j * bmp.getWidth() + c] != 0xeb) {
System.arraycopy(mark, j * bmp.getWidth() + c, data, startX + i * 1280 + c, 1);
if (mark[j * bmpWidth + c] != 0x10 && mark[j * bmpWidth + c] != 0x80 && mark[j * bmpWidth + c] != 0xeb) {
System.arraycopy(mark, j * bmpWidth + c, data, startX + i * width + c, 1);
}
}
j++;

Loading…
Cancel
Save