bump
This commit is contained in:
parent
d4a3e9355e
commit
7f75b31176
@ -66,20 +66,21 @@ public class RT3script : MonoBehaviour
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
void LateUpdate()
|
||||
{
|
||||
float expectedFrames = Time.timeSinceLevelLoad * targetFrameRate;
|
||||
if (frameCount < expectedFrames) {
|
||||
// Graphics.CopyTexture(colorImage, 0, 0, 0, 0, 256, 256, outputImage, 0, 0, 0, 0);
|
||||
// Graphics.CopyTexture(depthImage, 0, 0, 0, 0, 256, 256, outputImage, 0, 0, 256, 0);
|
||||
|
||||
RenderTexture.active = colorImage;
|
||||
outputImage.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
outputImage.Apply();
|
||||
// RenderTexture.active = colorImage;
|
||||
// outputImage.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
// outputImage.Apply();
|
||||
|
||||
RenderTexture.active = depthImage;
|
||||
outputImage.ReadPixels(new Rect(0, 0, 256, 256), 256, 0);
|
||||
outputImage.ReadPixels(new Rect(0, 0, depthImage.width, depthImage.height), 0, 0);
|
||||
outputImage.Apply();
|
||||
RenderTexture.active = null;
|
||||
|
||||
// Get the raw pixel data and write it to FFmpeg's input stream
|
||||
byte[] frameBytes = outputImage.GetRawTextureData();
|
||||
|
129
Assets/RT3script.cs.newbak
Normal file
129
Assets/RT3script.cs.newbak
Normal file
@ -0,0 +1,129 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class FFmpegVideoRecorder : MonoBehaviour
|
||||
{
|
||||
public Camera targetCamera; // Assign your camera in the Inspector
|
||||
public int outputWidth = 1920; // Output video width
|
||||
public int outputHeight = 1080; // Output video height
|
||||
public int outputFrameRate = 30; // Output video frame rate
|
||||
public string ffmpegPath = "ffmpeg"; // Path to the FFmpeg binary
|
||||
public string outputFilePath = "output.mp4"; // Path to save the video
|
||||
|
||||
private RenderTexture renderTexture;
|
||||
private Texture2D frameTexture;
|
||||
private Process ffmpegProcess;
|
||||
private BinaryWriter ffmpegInputStream;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Setup FFmpeg process
|
||||
StartFFmpeg();
|
||||
|
||||
// Create a RenderTexture and Texture2D for capturing frames
|
||||
renderTexture = new RenderTexture(outputWidth, outputHeight, 24);
|
||||
frameTexture = new Texture2D(outputWidth, outputHeight, TextureFormat.RGB24, false);
|
||||
|
||||
// Set the camera's target texture to render to the RenderTexture
|
||||
targetCamera.targetTexture = renderTexture;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
// Capture the camera's current frame
|
||||
RenderTexture currentRT = RenderTexture.active;
|
||||
RenderTexture.active = renderTexture;
|
||||
targetCamera.Render();
|
||||
|
||||
// Read the pixels from the RenderTexture into the Texture2D
|
||||
frameTexture.ReadPixels(new Rect(0, 0, outputWidth, outputHeight), 0, 0);
|
||||
frameTexture.Apply();
|
||||
|
||||
// Write the frame's raw RGB data to the FFmpeg input stream
|
||||
byte[] frameData = frameTexture.GetRawTextureData();
|
||||
if (ffmpegInputStream != null)
|
||||
{
|
||||
ffmpegInputStream.Write(frameData);
|
||||
}
|
||||
|
||||
// Restore the previous active RenderTexture
|
||||
RenderTexture.active = currentRT;
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
StopFFmpeg();
|
||||
|
||||
// Clean up temporary objects
|
||||
if (renderTexture != null)
|
||||
{
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
}
|
||||
if (frameTexture != null)
|
||||
{
|
||||
Destroy(frameTexture);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartFFmpeg()
|
||||
{
|
||||
var ffmpegStartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = ffmpegPath,
|
||||
Arguments = $"-y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s {outputWidth}x{outputHeight} -r {outputFrameRate} -i - -an -vcodec libx264 -pix_fmt yuv420p \"{outputFilePath}\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = false,
|
||||
RedirectStandardError = true, // Optional: Redirect standard error for debugging
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
ffmpegProcess = new Process
|
||||
{
|
||||
StartInfo = ffmpegStartInfo
|
||||
};
|
||||
|
||||
ffmpegProcess.Start();
|
||||
|
||||
// Attach the input stream
|
||||
ffmpegInputStream = new BinaryWriter(ffmpegProcess.StandardInput.BaseStream);
|
||||
}
|
||||
|
||||
private void StopFFmpeg()
|
||||
{
|
||||
if (ffmpegInputStream != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Close the input stream
|
||||
ffmpegInputStream.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore any errors when closing the stream
|
||||
}
|
||||
ffmpegInputStream = null;
|
||||
}
|
||||
|
||||
if (ffmpegProcess != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Wait for the FFmpeg process to exit
|
||||
ffmpegProcess.WaitForExit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore any errors when waiting for the process
|
||||
}
|
||||
finally
|
||||
{
|
||||
ffmpegProcess.Close();
|
||||
}
|
||||
|
||||
ffmpegProcess = null;
|
||||
}
|
||||
}
|
||||
}
|
7
Assets/RT3script.cs.newbak.meta
Normal file
7
Assets/RT3script.cs.newbak.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64763bbc0a4c16443a107fefed83ff75
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -154,7 +154,8 @@ PlayerSettings:
|
||||
resetResolutionOnWindowResize: 0
|
||||
androidSupportedAspectRatio: 1
|
||||
androidMaxAspectRatio: 2.1
|
||||
applicationIdentifier: {}
|
||||
applicationIdentifier:
|
||||
Standalone: com.DefaultCompany.DNN-Depth-Capture
|
||||
buildNumber:
|
||||
Standalone: 0
|
||||
iPhone: 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user