public async Task ConversionTest2() { var path = Res.GetPath(Res.Video_Mp4); var opath = "out-test-v-2.webm"; try { var encoder = new VP9Encoder(); encoder.RowBasedMultithreading = true; encoder.SetCQP(31); using var reader = new VideoReader(path); reader.LoadMetadata(); reader.Load(); using (var writer = new VideoWriter(opath, reader.Metadata.Width, reader.Metadata.Height, reader.Metadata.AvgFramerate, encoder.Create())) { writer.OpenWrite(true); reader.CopyTo(writer); } using var video = new VideoReader(opath); await video.LoadMetadataAsync(); Assert.True(video.Metadata.Codec == "vp9"); Assert.True(video.Metadata.AvgFramerate == reader.Metadata.AvgFramerate); Assert.True(Math.Abs(video.Metadata.Duration - reader.Metadata.Duration) < 0.01); Assert.True(video.Metadata.Width == reader.Metadata.Width); Assert.True(video.Metadata.Height == reader.Metadata.Height); Assert.True(video.Metadata.Streams.Length == 1); // only video } finally { if (File.Exists(opath)) { File.Delete(opath); } } }
static void ConvertVideo(string input, string output) { var encoder = new VP9Encoder(); encoder.RowBasedMultithreading = true; encoder.SetCQP(31); using (var reader = new VideoReader(input)) { reader.LoadMetadata(); reader.Load(); using (var writer = new VideoWriter(output, reader.Metadata.Width, reader.Metadata.Height, reader.Metadata.AvgFramerate, encoder.Create())) { writer.OpenWrite(true); reader.CopyTo(writer); } } }