0

I am using AviManager I have a list of images in a Bitmap list, which I am creating an uncompressed stream from like so:

        // create the file
        WaveFileReader wf = new WaveFileReader(VideoLocation);
        AviManager aviManager = new AviManager(VideoLocation, false);

        // Get the time of the audio and divide by images
        double time = wf.TotalTime.TotalSeconds;
        var co = (int)Math.Ceiling(time) * 2;
        var mimtime = co / urls.Count;

        //add a new video stream and one frame to the new file
        Images[0].RotateFlip(RotateFlipType.RotateNoneFlipY);
        VideoStream aviStream = aviManager.AddVideoStream(false, 2, Images[0]);

        for (var i = 0; i < Images.Count; i++)
        {
            if (i != 0) // fix flipped looping bug for first image
            {
                Images[i].RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            int n = 0;
            while (n < mimtime)
            {
                aviStream.AddFrame(Images[i]);
                n++;
            }
            n = 0;
        }

This generates an AVI file fine, now when I go to compress that video and add an audio like so:

    /// <summary>
    /// Compress the video, and add the audio stream
    /// </summary>
    /// <returns></returns>
    private async Task CompressVideo()
    {
        // Compressing Video
        StatusTextChanged?.Invoke(this, $"Compressing video");

        // Compress
        AviManager avManager = new AviManager(VideoLocation, true);
        VideoStream avStream = avManager.GetVideoStream();

        VideoStream newStream;
        AviManager newManager = avStream.DecompressToNewFile(CompressedVideo, true, out newStream);

        avManager.Close();
        newManager.Close();

        // Adding audio to video
        StatusTextChanged?.Invoke(this, $"Adding audio to video");

        // Add the audio
        //System.Threading.Thread.Sleep(30000);
        if (CompressedVideo != null && ArticleAudio != null)
        {
            AviManager audiovideo = new AviManager(CompressedVideo, true);
            audiovideo.AddAudioStream(ArticleAudio, 0);
            audiovideo.Close();
        }
    }

it's hit or miss whether it compresses or gets the error;

enter image description here

Sometimes the video gets up to 3MB, then gets the error, Sometimes it gets to 12MB then gets the error, sometimes it actually compresses the whole video, how can I fix this?

Alexei Levenkov
  • 94,391
  • 12
  • 114
  • 159
4334738290
  • 363
  • 1
  • 16
  • Since you are getting NRE you should read through standard answer first and provide [MCVE]. In current state of the post does not show what steps you've already taken to resolve the issue. – Alexei Levenkov May 18 '17 at 22:49
  • There's nothing to try to resolve this, by their documents, the code I am using should work, but it doesn't hence why I am asking here to see if anybody has experienced this – 4334738290 May 18 '17 at 22:54

0 Answers0