Проблема с обработкой частоты кадров ffmpeg.exeC#

Место общения программистов C#
Anonymous
Проблема с обработкой частоты кадров ffmpeg.exe

Сообщение Anonymous »

Видеозаписи экрана в формате .mp4 извлекается с помощью внешнего процесса исполняемого файла ffmpeg.exe.
При извлечении видео продолжительность видео сокращается, поскольку оно перематывается вперед, в отличие от прошедшего времени. время фактической записи.
После проверки частота кадров, которую я установил, равна 15, но выходной fps равен 11. Даже если уменьшить частоту кадров, значение выходного fps также уменьшается.
Я не знаю, что делать, чтобы правильно извлечь его по времени.
Ниже приведен код, который я написал.

Код: Выделить всё

string arguments = $"-r {frameRate} -y -f rawvideo -pix_fmt bgr24 -s {width}x{height} -i pipe:0 -c:v libx264 -preset ultrafast -crf 18 -tune zerolatency -threads 4 -pix_fmt yuv420p -b:v 1000k -vf \"scale=trunc(iw/2)*2:trunc(ih/2)*2\" -r {frameRate} \"{outputPath}\"";

// FFmpeg 프로세스 시작
ffmpegProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = ffmpegPath,
Arguments = arguments,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardError = true
},
EnableRaisingEvents = true
};

public void StartRecording(IntPtr handle)
{
string videoName = string.Format("{0}-{1}.mp4", rootNodeName, DateTime.Now.ToString("yyyyMMddHHmmss"));

string outputPath = Path.Combine(OutputPath, videoName);
string ffmpegPath = FFmpegPath;

Utility.ScreenCapture.User32.RECT rect = new Utility.ScreenCapture.User32.RECT();
Utility.ScreenCapture.User32.GetWindowRect(handle, ref rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;

ffmpegProcess = ffmpegHelper.StartFFmpegProcess(ffmpegPath, outputPath, handle, width, height, 15);
stopwatch = new Stopwatch();
stopwatch.Start();

Thread captureThread = new Thread(() => CaptureFrames(handle));
captureThread.IsBackground = true;
captureThread.Start();
}

private void CaptureFrames(IntPtr handle)
{
const int targetFrameRate = 15; // FPS를 15으로 설정
const int captureInterval = 1000 / targetFrameRate; // milliseconds

while (isRecording)
{
while (isPaused)
{
Thread.Sleep(100);
stopwatch.Stop();
}
`your text`

if (stopwatch.ElapsedMilliseconds >= captureInterval)
{
try
{
using (Bitmap frame = new Bitmap(screenCapture.CaptureWindow(handle)))
{
ffmpegHelper.SendImageToFFmpeg(frame);
}
stopwatch.Restart();
}
catch (Exception ex)
{
MessageBox.Show($"frame capture error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Thread.Sleep(Math.Max(0, captureInterval - (int)stopwatch.ElapsedMilliseconds));
}
}
Также были скорректированы значения частоты кадров и fps.
Не знаю, в чем проблема.
Надеюсь, видео извлекается с нормальной скоростью .

Подробнее здесь: https://stackoverflow.com/questions/790 ... ling-issue

Вернуться в «C#»