Commit be58a4d2 authored by shujianhe's avatar shujianhe

1 修复分组颜色的问题

2 提交回放的部分代码
3 添加RGB转YNV格式函数
parent fbbfc364
......@@ -290,7 +290,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.8396226, g: 0.34456214, b: 0.34456214, a: 1}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
......
......@@ -28,7 +28,7 @@ RectTransform:
m_GameObject: {fileID: 5397047662947055783}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.025, y: 0.025, z: 0}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
......@@ -55,6 +55,7 @@ MonoBehaviour:
centerY: 0
runR: 300
tim: 0.25
maxDotR: 45
baseColor: {r: 0.083667114, g: 0.7264151, b: 0, a: 1}
--- !u!222 &7631582618795455591
CanvasRenderer:
......
This diff is collapsed.
......@@ -26,7 +26,7 @@ public class gameSceneLogic : MonoBehaviour, IEventHandler
public bool showAreaId = true;
private List<TempGroupInfos> groupInfos = null;
private Vector2 pos1 = new Vector2(-10000, -10000);
private int rvalue = -1;
//private int rvalue = -1;
private DateTime dtime;
private bool autoSwitchGroup = false;
private bool vibration = true;
......@@ -126,8 +126,9 @@ public class gameSceneLogic : MonoBehaviour, IEventHandler
bool isSelect = idx == nowidx;
item.IsSelect = isSelect;
item.index = idx;
item.UseColor = group.rgb;
item.IdName = (group.gid).ToString();
item.UseColor = group.rgb;
item.NowProgress = group.Jindu;
if(lvbType == ListViewBackTypeEnum.create || isSelect != oldIsSelect)
{
......
......@@ -64,7 +64,8 @@ public class Native : MonoBehaviour
{
#if UNITY_EDITOR
Debug.Log("JSON:" + json);
json = "{\"append\":\"\",\"classId\":\"1,8,10,14\",\"displayDate\":\"20221102\",\"enterType\":\"0\",\"extraJson\":\"{\\\"cut_height\\\": 0, \\\"refer_drawer\\\": \\\"DoMyzu\\\"}\",\"extraType\":0,\"file\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H.zip\",\"highImg\":\"https://d21z6ifg4bbv2v.cloudfront.net/tspng/cc--EDgRpc_nHQru7H.png\",\"hybridType\":64,\"id\":\"cc--EDgRpc_nHQru7H\",\"originalJson\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsjson/cc--EDgRpc_nHQru7H.json\",\"picAssets\":\"{\\\"pictureBin\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/zsD2ySwS4pJ25frj.p\\\", \\\"pictureThn4\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/V8ZvUuDlOEB7mifd.png\\\", \\\"pictureColorThn4\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc400\\\", \\\"pictureWallThn8\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/oWqHjCo5mQvXIVP_.png\\\", \\\"pictureWallColorThn8\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc800\\\"}\",\"pictureBin\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureBin.p\",\"pictureColorThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureColorThn4.jpg\",\"pictureThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureThn4.png\",\"schedule\":0,\"seriesName\":\"\",\"sid\":2967,\"sort\":80,\"type\":6}";
//json = "{\"append\":\"\",\"classId\":\"1,8,10,14\",\"displayDate\":\"20221102\",\"enterType\":\"0\",\"extraJson\":\"{\\\"cut_height\\\": 0, \\\"refer_drawer\\\": \\\"DoMyzu\\\"}\",\"extraType\":0,\"file\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H.zip\",\"highImg\":\"https://d21z6ifg4bbv2v.cloudfront.net/tspng/cc--EDgRpc_nHQru7H.png\",\"hybridType\":64,\"id\":\"cc--EDgRpc_nHQru7H\",\"originalJson\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsjson/cc--EDgRpc_nHQru7H.json\",\"picAssets\":\"{\\\"pictureBin\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/zsD2ySwS4pJ25frj.p\\\", \\\"pictureThn4\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/V8ZvUuDlOEB7mifd.png\\\", \\\"pictureColorThn4\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc400\\\", \\\"pictureWallThn8\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/oWqHjCo5mQvXIVP_.png\\\", \\\"pictureWallColorThn8\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc800\\\"}\",\"pictureBin\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureBin.p\",\"pictureColorThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureColorThn4.jpg\",\"pictureThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureThn4.png\",\"schedule\":0,\"seriesName\":\"\",\"sid\":2967,\"sort\":80,\"type\":6}";
json = "{\"append\":\"\",\"classId\":\"1,8,10,14\",\"displayDate\":\"20221102\",\"enterType\":\"0\",\"extraJson\":\"{\\\"cut_height\\\": 0, \\\"refer_drawer\\\": \\\"DoMyzu\\\"}\",\"extraType\":0,\"file\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/ccnKNH1bTLS-_Mg7A2.zip\",\"highImg\":\"https://d21z6ifg4bbv2v.cloudfront.net/tspng/ccnKNH1bTLS-_Mg7A2.png\",\"hybridType\":64,\"id\":\"ccnKNH1bTLS-_Mg7A2\",\"originalJson\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsjson/ccnKNH1bTLS-_Mg7A2.json\",\"picAssets\":\"{\\\"pictureBin\\\": \\\"ccv1/production-pic/20221027/ccnKNH1bTLS-_Mg7A2/zsD2ySwS4pJ25frj.p\\\", \\\"pictureThn4\\\": \\\"ccv1/production-pic/20221027/ccnKNH1bTLS-_Mg7A2/V8ZvUuDlOEB7mifd.png\\\", \\\"pictureColorThn4\\\": \\\"ccv1/production-pic/20221027/ccnKNH1bTLS-_Mg7A2/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc400\\\", \\\"pictureWallThn8\\\": \\\"ccv1/production-pic/20221027/ccnKNH1bTLS-_Mg7A2/oWqHjCo5mQvXIVP_.png\\\", \\\"pictureWallColorThn8\\\": \\\"ccv1/production-pic/20221027/ccnKNH1bTLS-_Mg7A2/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc800\\\"}\",\"pictureBin\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/ccnKNH1bTLS-_Mg7A2_pictureBin.p\",\"pictureColorThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/ccnKNH1bTLS-_Mg7A2_pictureColorThn4.jpg\",\"pictureThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/ccnKNH1bTLS-_Mg7A2_pictureThn4.png\",\"schedule\":0,\"seriesName\":\"\",\"sid\":2967,\"sort\":80,\"type\":6}";
#endif
utilsTools.setGDataByKey("NativeGameData", JsonUtility.FromJson<netLableImageItem>(json));
SceneManager.LoadScene(utilsTools.getGameSceneName());
......
......@@ -13,6 +13,7 @@ public class replayerBack : MonoBehaviour, IEventHandler
protected GameScenUserInfo nowGameScenUser = null;
private bool showAd = false;
int playIdx = -1;
private int mp4OperNext = -1;
void onEvent(string name, EventChildItemBack func)
{
utilsTools.onEvent(this, name);
......@@ -25,6 +26,7 @@ public class replayerBack : MonoBehaviour, IEventHandler
{
onEvent("initViewShowData", onInitViewShowDataEvent);
onEvent("gameViewOnInitEnd", onGameViewOnInitEndEvent);
onEvent("onClick_saveOptions_msg", onClick_saveOptions_msg_Event);
string json = "{\"append\":\"\",\"classId\":\"1,8,10,14\",\"displayDate\":\"20221102\",\"enterType\":\"0\",\"extraJson\":\"{\\\"cut_height\\\": 0, \\\"refer_drawer\\\": \\\"DoMyzu\\\"}\",\"extraType\":0,\"file\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H.zip\",\"highImg\":\"https://d21z6ifg4bbv2v.cloudfront.net/tspng/cc--EDgRpc_nHQru7H.png\",\"hybridType\":64,\"id\":\"cc--EDgRpc_nHQru7H\",\"originalJson\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsjson/cc--EDgRpc_nHQru7H.json\",\"picAssets\":\"{\\\"pictureBin\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/zsD2ySwS4pJ25frj.p\\\", \\\"pictureThn4\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/V8ZvUuDlOEB7mifd.png\\\", \\\"pictureColorThn4\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc400\\\", \\\"pictureWallThn8\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/oWqHjCo5mQvXIVP_.png\\\", \\\"pictureWallColorThn8\\\": \\\"ccv1/production-pic/20221027/cc--EDgRpc_nHQru7H/IDdMO8yT0fPPhUtU.jpg?x-oss-process\\u003dstyle/cc800\\\"}\",\"pictureBin\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureBin.p\",\"pictureColorThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureColorThn4.jpg\",\"pictureThn4\":\"https://d21z6ifg4bbv2v.cloudfront.net/tsgame/cc--EDgRpc_nHQru7H_pictureThn4.png\",\"schedule\":0,\"seriesName\":\"\",\"sid\":2967,\"sort\":80,\"type\":6}";
utilsTools.setGDataByKey("NativeGameData", JsonUtility.FromJson<netLableImageItem>(json));
utilsTools.addTimer_Update(gameObject, "_", (string n) =>
......@@ -43,6 +45,7 @@ public class replayerBack : MonoBehaviour, IEventHandler
onTuiJianBack(tuijian);
return false;
}, 4);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/saveOptions").gameObject.SetActive(false);
}
//GroupByAreaPtInfos.mapAllDatas
protected void onTuiJianBack(string data)
......@@ -200,8 +203,8 @@ public class replayerBack : MonoBehaviour, IEventHandler
Vector2 offsetOutSize = new Vector2(10, 10);//new Vector2(7,7))
RectTransform baseTransform = rectTransform.transform.parent.GetComponent<RectTransform>();
Color[] colors = image.sprite.texture.GetPixels();
transform.Find("gameEndOperBase/gameShowBase/downButton/ad").gameObject.SetActive(showAd);
transform.Find("gameEndOperBase/gameShowBase/shareButton/ad").gameObject.SetActive(showAd);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/downButton/ad").gameObject.SetActive(showAd);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/shareButton/ad").gameObject.SetActive(showAd);
if (width.Equals(height))
{
utilsTools.addTimer_Update(gameObject, "_1", (String na) =>
......@@ -289,18 +292,7 @@ public class replayerBack : MonoBehaviour, IEventHandler
public void onContinue()
{
}
public void onDownButton()
{
if (showAd)
{
utilsTools.showAd("inter", gameObject.name, "onShareBunttionNativeHandler");
string key = nowGameScenUser.id + "_showAd";
utilsDB.setDBBoolDataByKey(key, false);
transform.Find("gameEndOperBase/gameShowBase/downButton/ad").gameObject.SetActive(false);
transform.Find("gameEndOperBase/gameShowBase/shareButton/ad").gameObject.SetActive(false);
return;
}
}
public void onPlayButton(bool isfirst = false)
{
mainGameOneImageView mgoiv = transform.Find("gameEndOperBase/gameShowBase").GetComponent<mainGameOneImageView>();
......@@ -329,7 +321,7 @@ public class replayerBack : MonoBehaviour, IEventHandler
int aa1 = utilsTools.getTotalMillisecond();
utilsTools.addTimer_Update(gameObject, "play_123", (String _) =>
{
int setp = 8;
int setp = 6;
for (int i = 0; i < setp; i++)
{
playIdx++;
......@@ -350,6 +342,21 @@ public class replayerBack : MonoBehaviour, IEventHandler
public void onShareBunttionNativeHandler(string json)
{
}
public void onDownButton()
{
if (showAd)
{
utilsTools.showAd("inter", gameObject.name, "onShareBunttionNativeHandler");
string key = nowGameScenUser.id + "_showAd";
utilsDB.setDBBoolDataByKey(key, false);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/downButton/ad").gameObject.SetActive(false);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/shareButton/ad").gameObject.SetActive(false);
return;
}
transform.Find("gameEndOperBase/gameShowBase/btnsBase/saveOptions").gameObject.SetActive(true);
mp4OperNext = 1;
}
public void onShareButton()
{
......@@ -358,11 +365,54 @@ public class replayerBack : MonoBehaviour, IEventHandler
utilsTools.showAd("inter",gameObject.name, "onShareBunttionNativeHandler");
string key = nowGameScenUser.id + "_showAd";
utilsDB.setDBBoolDataByKey(key, false);
transform.Find("gameEndOperBase/gameShowBase/downButton/ad").gameObject.SetActive(false);
transform.Find("gameEndOperBase/gameShowBase/shareButton/ad").gameObject.SetActive(false);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/downButton/ad").gameObject.SetActive(false);
transform.Find("gameEndOperBase/gameShowBase/btnsBase/shareButton/ad").gameObject.SetActive(false);
return;
}
transform.Find("gameEndOperBase/gameShowBase/btnsBase/saveOptions").gameObject.SetActive(true);
mp4OperNext = 2;
}
private void onSaveToMp4Handler()
{
mainGameOneImageView mgoiv = transform.Find("gameEndOperBase/gameShowBase").GetComponent<mainGameOneImageView>();
utilsTools.delTimeHandler(gameObject, "play_123");
playIdx = -1;
mgoiv.showAreaPrveClear(false);
int idxflg = 0;
float size = (float)nowGameScenUser.areaInfoUseData.Count;
utilsTools.addTimer_Update(gameObject, "saveToMp4", (string name) =>
{
int aid = nowGameScenUser.areaInfoUseData[idxflg].id;
float jindu = idxflg / size;
idxflg++;
mgoiv.showArea(aid, null);
//gameObject.transform.Find("inSaveProgress/progress").GetComponent<Image>().fillAmount = jindu;
if (idxflg == nowGameScenUser.areaInfoUseData.Count)
{
onCloseMp4Save(true);
}
return true;
}, 5, nowGameScenUser.areaInfoUseData.Count);
}
public void onCloseMp4Save(bool isSuccesss = false)
{
if (isSuccesss == false)
{
mp4OperNext = -1;
}
else
{
if (mp4OperNext == 1)
{
Debug.Log("分享中");
}
else
{
Debug.Log("保存完成");
}
}
}
public void onEventHandler(string eventName, List<UnityEngine.Object> uobjects, List<System.Object> objects)
{
if (childEventHandlers.ContainsKey(eventName))
......@@ -370,4 +420,18 @@ public class replayerBack : MonoBehaviour, IEventHandler
childEventHandlers[eventName](uobjects, objects);
}
}
public void onClick_saveOptions_msg_Event(List<UnityEngine.Object> uobjects,List<System.Object> objects)
{
int typeId = (int)objects[0];
if (typeId.Equals(0))
{
transform.Find("gameEndOperBase/gameShowBase/btnsBase/saveOptions").gameObject.SetActive(false);
}else if (typeId.Equals(1))
{
}else if(typeId.Equals(2))
{
onSaveToMp4Handler();
}
}
}
......@@ -18,7 +18,7 @@ public class waterfallFlowView : gridView
{
}
virtual public void setData(int size, gradViewBack back, bool useVec = true, GetGradViewInfo getGradViewInfo = null)
override public void setData(int size, gradViewBack back, bool useVec = true, GetGradViewInfo getGradViewInfo = null)
{
base.setData(size, back, useVec, getGradViewInfo);
}
......
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class LightEffectAreaInfos
{
public float width = 0.1f;//0 -- 1
public float duijiaoLen = 0.2f;
}
public class LightEffect : MonoBehaviour
{
//暂时用C# 编写使用CPU 擅长shader的人自己改成GPU
// Start is called before the first frame update
public Color selectColor = Color.white;
public float speed = 20;
public float angle = 0;
public Vector2 size = new Vector2(100,100);
public List<LightEffectAreaInfos> lightEffectAreaInfos = new List<LightEffectAreaInfos>();
private float time = 0;
private Texture2D texture2D = null;
private int width = 0;
private int height = 0;
void Start()
{
if(texture2D == null)initMember();
}
private void initMember()
{
}
void updateTexture()
{
}
// Update is called once per frame
void Update()
{
if (texture2D == null) initMember();
}
}
fileFormatVersion: 2
guid: df8c6fb1290f8f34a923eb4d5e12e3f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -231,6 +231,7 @@ public class mainGameView : MonoBehaviour
if (keyValuePairs.ContainsKey(item.id))
{
Debug.Log("重复----" + item.id);
return ret.ToArray();
}
keyValuePairs.Add(item.id, true);
}
......@@ -498,7 +499,7 @@ public class mainGameView : MonoBehaviour
}
GameObject idGameObject = Instantiate(areaIdperfabObj);
idValueTran = idGameObject.transform;
idValueTran.parent = areaIdBase.transform;
idValueTran.SetParent(areaIdBase.transform, false);
idGameObject.name = item.tempExKey;
}
//怎么转换坐标
......
......@@ -130,6 +130,7 @@ public class colorItem : MonoBehaviour
Color color1 = Color.HSVToRGB(h, s, v);
effectImg.color2 = color1;
effectImg.color1 = useColor;
Debug.Log("id = " + idName + " color1 = " + (color1 * 255).ToString() + " color2 = " + (useColor * 255));
}
get
{
......
......@@ -8,25 +8,201 @@ using UnityEngine;
namespace Assets.scripts.utils
{
public class VideoInfo
{
public int width;
public int height;
public int fps;
public string path;
public IntPtr intPtr;
}
class AVPacket
{
/**
* A reference to the reference-counted buffer where the packet data is
* stored.
* May be NULL, then the packet data is not reference-counted.
*/
IntPtr buf;
/**
* Presentation timestamp in AVStream->time_base units; the time at which
* the decompressed packet will be presented to the user.
* Can be AV_NOPTS_VALUE if it is not stored in the file.
* pts MUST be larger or equal to dts as presentation cannot happen before
* decompression, unless one wants to view hex dumps. Some formats misuse
* the terms dts and pts/cts to mean something different. Such timestamps
* must be converted to true pts/dts before they are stored in AVPacket.
*/
Int64 pts;
/**
* Decompression timestamp in AVStream->time_base units; the time at which
* the packet is decompressed.
* Can be AV_NOPTS_VALUE if it is not stored in the file.
*/
Int64 dts;
IntPtr data;
int size;
int stream_index;
/**
* A combination of AV_PKT_FLAG values
*/
int flags;
/**
* Additional packet data that can be provided by the container.
* Packet can contain several types of side information.
*/
IntPtr side_data;
int side_data_elems;
/**
* Duration of this packet in AVStream->time_base units, 0 if unknown.
* Equals next_pts - this_pts in presentation order.
*/
Int64 duration;
Int64 pos; ///< byte position in stream, -1 if unknown
}
public class VideoHelp
{
public enum AVCodecID
{
AV_CODEC_ID_NONE = -1,
AV_CODEC_ID_H264 = 28,
// 其他编码器...
}
static Dictionary<string,VideoInfo> videoPools = new Dictionary<string, VideoInfo>();
// 导入FFmpeg的C/C++库
[DllImport("libavcodec", CallingConvention = CallingConvention.Cdecl)]
private static extern int avcodec_register_all();
[DllImport("libavcodec", CallingConvention = CallingConvention.Cdecl)]
private static extern int avcodec_find_encoder(AVCodecID id);
[DllImport("libavcodec", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr avcodec_alloc_context3(IntPtr codec);
[DllImport("libavcodec.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int avcodec_encode_video2(IntPtr avctx, IntPtr avpkt, IntPtr frame, out int got_packet_ptr);
//[DllImport("avcodec", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
//private static extern int avcodec_encode_video2(IntPtr codecContext, IntPtr avPacket, IntPtr frame, ref int gotPacket);
extern static uint avcodec_version();
public static bool Open(string path, int id, int width, int height, int fps)
public static IntPtr InitializeEncoder(AVCodecID codecId, int width, int height, int fps)
{
IntPtr codecPtr = (IntPtr)avcodec_find_encoder(codecId);
if (codecPtr == IntPtr.Zero)
{
Debug.LogError("Failed to find encoder");
return IntPtr.Zero;
}
IntPtr codecContextPtr = avcodec_alloc_context3(codecPtr);
// 设置编码器参数...
return codecContextPtr;
}
public static bool Open(string id,string path, int width, int height, int fps)
{
if(videoPools.ContainsKey(id) == false)
{
IntPtr intPtr = InitializeEncoder(AVCodecID.AV_CODEC_ID_H264,width,height, fps);
if (intPtr == IntPtr.Zero) return false;
VideoInfo videoInfo = new VideoInfo();
videoInfo.width = width;
videoInfo.height = height;
videoInfo.fps = fps;
videoInfo.path = path;
videoInfo.intPtr = intPtr;
videoPools.Add(id, videoInfo);
}
return false;
}
public static bool PushColors(int id, Color[] colors)
public static IntPtr ConvertToIntPtr(byte[] data)
{
IntPtr intPtr = Marshal.AllocHGlobal(data.Length);
Marshal.Copy(data, 0, intPtr, data.Length);
return intPtr;
}
public static bool PushColors(string id, Color[] colors)
{
if (videoPools.ContainsKey(id) == false) return false;
var temp = videoPools[id];
int width = temp.width;
int height = temp.height;
Byte[] bytes = new byte[(int)((width + height) * 2.5)];
utilsTools.RGBtoYUV(colors, bytes, width, height);
int isOk = 0;
IntPtr data = ConvertToIntPtr(bytes);
IntPtr avpkt = Marshal.AllocHGlobal(Marshal.SizeOf<AVPacket>());
avcodec_encode_video2(temp.intPtr, avpkt, data,out isOk);
Marshal.FreeHGlobal(avpkt);
return false;
}
public static bool Close(int id)
{
return false;
}
public static string getDllVersion()
//public static string getDllVersion()
//{
// return avcodec_version().ToString();
//}
}
}
/*
* using System.Runtime.InteropServices;
public class FFmpegEncoder
{
// 导入FFmpeg的C/C++库
[DllImport("libavcodec", CallingConvention = CallingConvention.Cdecl)]
private static extern int avcodec_register_all();
[DllImport("libavcodec", CallingConvention = CallingConvention.Cdecl)]
private static extern int avcodec_find_encoder(AVCodecID id);
[DllImport("libavcodec", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr avcodec_alloc_context3(IntPtr codec);
// 声明其他FFmpeg函数...
// 枚举类型AVCodecID定义
public enum AVCodecID
{
AV_CODEC_ID_NONE = -1,
AV_CODEC_ID_H264 = 28,
// 其他编码器...
}
// 初始化FFmpeg
public static void InitializeFFmpeg()
{
avcodec_register_all();
}
// 初始化编码器
public static IntPtr InitializeEncoder(AVCodecID codecId, int width, int height, int fps)
{
IntPtr codecPtr = avcodec_find_encoder(codecId);
if (codecPtr == IntPtr.Zero)
{
return avcodec_version().ToString();
Debug.LogError("Failed to find encoder");
return IntPtr.Zero;
}
IntPtr codecContextPtr = avcodec_alloc_context3(codecPtr);
// 设置编码器参数...
return codecContextPtr;
}
// 其他编码相关的函数...
// 释放编码器资源
public static void ReleaseEncoder(IntPtr codecContextPtr)
{
// 释放资源...
}
}
*/
\ No newline at end of file
......@@ -826,5 +826,20 @@ public class utilsTools
}
return readPath;
}
public static void RGBtoYUV(Color[] rgbData, byte[] yuvData, int width, int height)
{
int size = width * height;
for (int i = 0; i < size; i++)
{
Color32 rgb = rgbData[i];
byte y = (byte)(0.299 * rgb.r * 255 + 0.587 * rgb.g * 255 + 0.114 * rgb.b * 255);
byte u = (byte)(128 - 0.168736 * rgb.r * 255 - 0.331264 * rgb.g * 255 + 0.5 * rgb.b * 255);
byte v = (byte)(128 + 0.5 * rgb.r * 255 - 0.418688 * rgb.g * 255 - 0.081312 * rgb.b * 255);
yuvData[i] = y;
yuvData[size + i / 4] = u;
yuvData[size + size / 4 + i / 4] = v;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment