Skip to content

Commit

Permalink
Update sample code in the README (#43).
Browse files Browse the repository at this point in the history
  • Loading branch information
radek-k committed Dec 21, 2020
1 parent 1b96e2f commit ee0f1e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion FFMediaToolkit/Decoding/VideoStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public ImageData ReadNextFrame()
/// </summary>
/// <param name="bitmap">The decoded video frame.</param>
/// <returns><see langword="false"/> if reached end of the stream.</returns>
public bool TryReadFrameNextFrame(out ImageData bitmap)
public bool TryReadNextFrame(out ImageData bitmap)
{
lock (syncLock)
{
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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}");
Expand Down

0 comments on commit ee0f1e6

Please sign in to comment.