internal void ProcessVideo(Action <IEnumerable <SourceReaderExtra>, ProcessSample> process) { var readWriteFactory = new ReadWriteClassFactory(); var attributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true }; var readers = VideoFiles.Select(f => f.CreateSourceReader(readWriteFactory, attributes)).ToArray(); try { using (var sinkWriter = readWriteFactory.CreateSinkWriterFromURL(DestinationFile, attributes)) { var writeToSink = ConnectStreams(readers, sinkWriter); using (sinkWriter.BeginWriting()) process(readers, writeToSink); } } finally { if (readers != null) { foreach (var r in readers) { r.Dispose(); } } } }
public void Process() { using (MFSystem.Start()) { var readWriteFactory = new ReadWriteClassFactory(); var attributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true, }; var destAttributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true, MaxKeyFrameSpacing = 3000 }; var shortSourceReader = readWriteFactory.CreateSourceReaderFromURL(shortSourceFile, attributes); var shortSourceReader2 = readWriteFactory.CreateSourceReaderFromURL(shortSourceFile, attributes); var mainSourceReader = readWriteFactory.CreateSourceReaderFromURL(mainSourceFile, attributes); var sinkWriter = readWriteFactory.CreateSinkWriterFromURL(destinationFile, destAttributes); var writeToSink = ConnectStreams(shortSourceReader, shortSourceReader2, mainSourceReader, sinkWriter); ProcessSample progress = sample => { if(!sample.Flags.EndOfStream) Trace.WriteLine(string.Format("sourceTime: {0}, sampleTime: {1}", sample.Timestamp.FromNanoToSeconds(), sample.SampleTime.FromNanoToSeconds())); return writeToSink(sample); }; var fadeSegments = AVOperations.FadeIn(AVOperations.FadeOut(progress)); var editoutMiddle = AVOperations.Cut(9.FromSecondsToNano(), 19.FromSecondsToNano(), fadeSegments); var overlay = AVOperations.Overlay(applyOverlay, editoutMiddle); var first4Seconds = AVOperations.Cut(0.FromSecondsToNano(), 4.FromSecondsToNano(), progress, progress); var readers = AVOperations.Combine(new[] { shortSourceReader, mainSourceReader }, 1.1); using (sinkWriter.BeginWriting()) { AVOperations.StartConcat(readers, overlay, AVOperations.Concat(shortSourceReader, first4Seconds, () => false), () => false); } } }
internal void ProcessVideo(Action<IEnumerable<SourceReaderExtra>, ProcessSample> process) { var readWriteFactory = new ReadWriteClassFactory(); var attributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true }; var readers = VideoFiles.Select(f => f.CreateSourceReader(readWriteFactory, attributes)).ToArray(); var sinkWriter = readWriteFactory.CreateSinkWriterFromURL(DestinationFile, attributes); var writeToSink = ConnectStreams(readers, sinkWriter); using (sinkWriter.BeginWriting()) process(readers, writeToSink); }
internal string TestVideoConversion() { var readWriteFactory = new ReadWriteClassFactory(); var attributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true }; var readers = VideoFiles.Select(f => f.CreateSourceReader(readWriteFactory, attributes)).ToArray(); var testOuputFile = readers.First().FileName + ".tmp.test.wmv"; try { using (var sinkWriter = readWriteFactory.CreateSinkWriterFromURL(testOuputFile, attributes)) { var writeToSink = ConnectStreams(readers, sinkWriter); } } catch (Exception e) { return(e.Message); } finally { if (readers != null) { foreach (var r in readers) { r.Dispose(); } } File.Delete(testOuputFile); } return(null); }
public void Process() { using (MFSystem.Start()) { var readWriteFactory = new ReadWriteClassFactory(); var attributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true, }; var destAttributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true, MaxKeyFrameSpacing = 3000 }; var sourceReader = readWriteFactory.CreateSourceReaderFromURL(sourceFile, attributes); var sinkWriter = readWriteFactory.CreateSinkWriterFromURL(destinationFile, destAttributes); var writeToSink = ConnectStreams(sourceReader, sinkWriter); using (sinkWriter.BeginWriting()) { sourceReader.Samples(sample => { Console.Clear(); Console.WriteLine(TimeSpan.FromSeconds(sample.Timestamp.FromNanoToSeconds())); return writeToSink(sample); }); } } }
internal string TestVideoConversion() { var readWriteFactory = new ReadWriteClassFactory(); var attributes = new Attributes { ReadWriterEnableHardwareTransforms = true, SourceReaderEnableVideoProcessing = true }; var readers = VideoFiles.Select(f => f.CreateSourceReader(readWriteFactory, attributes)).ToArray(); var testOuputFile = readers.First().FileName + ".tmp.test.wmv"; try { using (var sinkWriter = readWriteFactory.CreateSinkWriterFromURL(testOuputFile, attributes)) { var writeToSink = ConnectStreams(readers, sinkWriter); } } catch(Exception e) { return e.Message; } finally { if (readers != null) foreach (var r in readers) r.Dispose(); File.Delete(testOuputFile); } return null; }