我正在使用AviManager我在Bitmap列表中有一个图像列表,我正在创建一个未压缩的流,如下所示:
// 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;
}
这会生成一个AVI文件,现在当我去压缩该视频并添加这样的音频时:
/// <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();
}
}
它是否会压缩或遗漏错误;
有时视频会达到3MB,然后会出现错误,有时会达到12MB然后会出现错误,有时它实际上会压缩整个视频,我该如何解决?