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;
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?