'FFMPEG: Recording a video stream to disk real-time
I made a video recording with ffmpeg
var inputArgs = string.Format(CultureInfo.InvariantCulture, "-framerate {0} -f rawvideo -pix_fmt {3} -video_size {1}x{2} -i -", VideoFPS, VideoXRes, VideoYRes, VideoPXLFormat);
var outputArgs = string.Format(CultureInfo.InvariantCulture, "-vcodec mpeg4 -crf {2} -pix_fmt yuv420p -preset {3} -shortest -r {1} \"{0}\"", outputPath, VideoFPS, VideoCRFValue, CompressionRate);
var ffmpegProcess = new Process
{
StartInfo =
{
FileName = ffmpegPath,
Arguments = $"{inputArgs} {outputArgs}",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true
}
};
ffmpegProcess .Start();
var VideoRecordingFFmpegInput = VideoRecordingFFmpegProcces.StandardInput.BaseStream;
Now I write data bytes from the image into the stream from time to time
VideoRecordingFFmpegInput.Write(framesByteArray, 0, sizeOfpack);
When I finished recording the frames:
VideoRecordingFFmpegInput.Flush();
VideoRecordingFFmpegInput.Close();
ffmpegProcess.WaitForExit();
Everything works fine, and it creates the file I want.
When the process starts, it creates a file that has a very small size

And during the recording of image bytes in the video stream - this size does not change (Probably it is written to RAM?)
But as soon as the ffmpeg process finishes - flush / close the file size becomes normal.
The problem is that if I record for several hours it can cause an OutOfMemory exception
Is there any way to have the frames record and immediately increase the file size? (Without infinitely filling RAM?)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

