2017-09-15 86 views

回答

0

取决于你如何使用它。如果您使用的是Unity3D或虚幻,那么可能的话。

统一的例子有RenderTexture。请检查下面的教程来创建一个渲染纹理:

https://www.youtube.com/watch?v=pA7ZC8owaeo

运行一个脚本,并在其更新循环,使用下面的代码:

int i = 0; // in Start() 

int width = Screen.width; 
int height = Screen.height; 
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); 

// Read screen contents into the texture 
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); 
tex.Apply(); 

// Encode texture into PNG 
byte[] bytes = tex.EncodeToPNG(); 
File.WriteAllBytes(Application.dataPath + "/../pic" + i + ".png", bytes); 
i++; 

上面的代码已经从here

现在您可以使用ffmpeg将这些PNG转换为MP4文件,使用以下命令:

ffmpeg -r 60 -f image2 -s 1920x1080 -i pic%04d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4 

希望有帮助。