- Home /
video media encoder addframe texture format 5 expected to be 4
hello, im trying to load in a bunch of png images and make a video of them but when i try to add the frame to the encoder i get this error: VideoMediaEncoder::AddFrame texture format 5 expected to be 4.
this is the code i use to load in and add the pictures to the encoder:
IEnumerator EncodeImages()
{
VideoTrackAttributes videoAttr = new VideoTrackAttributes
{
frameRate = new MediaRational(30),
width = (uint)equirect.width,
height = (uint)equirect.height,
includeAlpha = false
};
Texture2D tex = new Texture2D(equirect.width, equirect.height, TextureFormat.RGB24, false);
index = 0;
using (MediaEncoder encoder = new MediaEncoder("C:/Users/Lars/Desktop/Images/ " + "my_movie.mp4", videoAttr, null))
{
while(index < amountOfFrames)
{
yield return StartCoroutine(LoadPNG("C:/Users/Lars/Desktop/Images/ " + "photo " + index.ToString() + ".png"));
encoder.AddFrame(loadedTex);
index++;
}
UnityEditor.EditorApplication.isPlaying = false;
yield return null;
}
}
IEnumerator LoadPNG(string filePath)
{
loadedTex = new Texture2D(equirect.width, equirect.height);
byte[] fileData;
if (File.Exists(filePath))
{
fileData = File.ReadAllBytes(filePath);
//tex = new Texture2D(2, 2);
yield return loadedTex.LoadImage(fileData);
}
else
{
Debug.LogError("file at: " + filePath + "doesn't exist");
}
yield return null;
}
i really hope someone can help me, i've been stuck at this for 2 days now.
Answer by KartikNK · Dec 15, 2018 at 04:51 PM
@thecoon14 , I was also facing that issue, this post helped me...
AFAIK that error occurs when we pass a texture with unsupported format to AddFrame method.
So, creating a new texture with RGB24 format and setting pixels of loadedTex to it, worked for me. At last I've passed this newly created texture to AddFrame method.
This post neatly explains how to change Texture2D format.
Texture2D newTexure = new Texture2D(240, 400, TextureFormat.RGBA32, false); //width:240, height:400
newTexure.SetPixels(oldTexture.GetPixels());
newTexure.Apply();
Thanks @$$anonymous$$artikN$$anonymous$$ it works
Your answer
Follow this Question
Related Questions
Image resize and save 0 Answers
Optimizing VideoClip for Linux 0 Answers
On Pointer Enter for semi-transparent UI? 2 Answers
Saving a Texture2D as a PNG 3 Answers
Animated GIF and Audio Instead of Video? 3 Answers