Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End of Stream Exception before end of video is reached #72

Closed
jrz371 opened this issue Mar 8, 2021 · 4 comments
Closed

End of Stream Exception before end of video is reached #72

jrz371 opened this issue Mar 8, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@jrz371
Copy link
Contributor

jrz371 commented Mar 8, 2021

Decoding a video with ffmpeg.exe results in 101 images and every frame is there. Here's the command I use.

.\ffmpeg.exe -i ".\Rotate Around.MP4" "out-%03d.jpg"

When decoding with FFMediaToolkit there is only 86 resulting images. It claims to be reaching the end of stream before the video is actually completed. When viewing the images they also seem to stop early without all the images.

using System;
using System.Drawing;
using System.IO;

namespace Decode
{
    internal static class Program
    {
        public static unsafe Bitmap ToBitmap(this FFMediaToolkit.Graphics.ImageData bitmap)
        {
            fixed (byte* p = bitmap.Data)
            {
                return new Bitmap(bitmap.ImageSize.Width, bitmap.ImageSize.Height, bitmap.Stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, new IntPtr(p));
            }
        }

        static void Main(string[] args)
        {
            FFMediaToolkit.FFmpegLoader.FFmpegPath = "./ffmpeg/";

            string path = @"C:\Users\joshu\Documents\fftest\Rotate Around.MP4";

            string directory = Path.GetDirectoryName(path);

            using(FFMediaToolkit.Decoding.MediaFile mediaFile = FFMediaToolkit.Decoding.MediaFile.Open(path))
            {
                int i = 0;
                while(mediaFile.Video.TryGetNextFrame(out FFMediaToolkit.Graphics.ImageData data))
                {
                    Bitmap bmp = data.ToBitmap();
                    bmp.Save(directory + Path.DirectorySeparatorChar + i++.ToString() + ".png");
                }
            }
        }
    }
}

Here's the video file
https://user-images.githubusercontent.com/16514346/110321321-30226e80-801a-11eb-9f8a-9f7669451127.MP4

This video was originally encoded with FFMediaToolkit and I'm a big fan of the library. Thanks for making it!

@IsaMorphic
Copy link
Contributor

Hey there! One question, does this media file contain audio data?

@jrz371
Copy link
Contributor Author

jrz371 commented Mar 10, 2021

No, it does not

@IsaMorphic
Copy link
Contributor

IsaMorphic commented Mar 10, 2021

Hmm, okay, interesting, I only ask because I thought the issue might be with how the library reads the file when reading both video and audio. To disable this functionality you'd just set the StreamsToLoad property of a MediaOptions instance to MediaMode.Video and pass the instance to the MediaFile constructor.
Not sure this will help, or if this is the exact issue, but its worth a shot.

@jrz371
Copy link
Contributor Author

jrz371 commented Mar 10, 2021

I gave it a shot but no dice. Thanks for the suggestion though!

@radek-k radek-k added bug Something isn't working help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Jun 12, 2021
@radek-k radek-k closed this as completed in bebe7d9 Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants