From ee0f1e625333dc5bd074ac71184c0b5f7d77ba35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kmiotek?= Date: Mon, 21 Dec 2020 11:48:49 +0100 Subject: [PATCH] Update sample code in the README (#43). --- FFMediaToolkit/Decoding/VideoStream.cs | 2 +- README.md | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/FFMediaToolkit/Decoding/VideoStream.cs b/FFMediaToolkit/Decoding/VideoStream.cs index 52a2fc6..4656388 100644 --- a/FFMediaToolkit/Decoding/VideoStream.cs +++ b/FFMediaToolkit/Decoding/VideoStream.cs @@ -224,7 +224,7 @@ public ImageData ReadNextFrame() /// /// The decoded video frame. /// if reached end of the stream. - public bool TryReadFrameNextFrame(out ImageData bitmap) + public bool TryReadNextFrame(out ImageData bitmap) { lock (syncLock) { diff --git a/README.md b/README.md index cff5b9c..0316700 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,11 @@ _____ - Extract all video frames as PNG files ```c# + int i = 0; var file = MediaFile.Open(@"C:\videos\movie.mp4"); - for (int i = 0; i < file.Video.Info.FrameCount; i++) + while(file.Video.TryReadNextFrame(out var imageData)) { - file.Video.ReadFrame(i).ToBitmap().Save($@"C:\images\frame_{i}.png"); + imageData.ToBitmap().Save($@"C:\images\frame_{i++}.png"); // See the #Usage details for example .ToBitmap() implementation // The .Save() method may be different depending on your graphics library } @@ -43,9 +44,7 @@ _____ Console.WriteLine($"Bitrate: {file.Info.Bitrate / 1000.0} kb/s"); var info = file.Video.Info; Console.WriteLine($"Duration: {info.Duration}"); - var isFrameCountAccurate = info.IsFrameCountProvidedByContainer || !info.IsVariableFrameRate; - var frameCount = isFrameCountAccurate ? info.FrameCount.ToString() : "N/A"; - Console.WriteLine($"Frames count: {frameCount}"); + Console.WriteLine($"Frames count: {info.NumberOfFrames ?? "N/A"}"); var frameRateInfo = info.IsVariableFrameRate ? "average" : "constant"; Console.WriteLine($"Frame rate: {info.AvgFrameRate} fps ({frameRateInfo})"); Console.WriteLine($"Frame size: {info.FrameSize}");