예제 #1
0
        public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
        {
            _codec.Quality = Args.VideoQuality;

            return(new AviWriter(Args.FileName, _codec, Args.ImageProvider, Args.FrameRate, Args.AudioProvider));
        }
예제 #2
0
 public abstract void Apply(FFmpegSettings Settings, VideoWriterArgs WriterArgs, FFmpegOutputArgs OutputArgs);
예제 #3
0
 public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
 {
     return(new FFmpegGifWriter(Args));
 }
예제 #4
0
        public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
        {
            Args.FrameRate = 1;

            return(_writerItem.GetVideoFileWriter(Args));
        }
예제 #5
0
        public MfWriter(VideoWriterArgs Args, Device Device)
        {
            var inputFormat = Args.ImageProvider.DummyFrame is Texture2DFrame
                ? VideoFormatGuids.NV12
                : VideoFormatGuids.Rgb32;

            _device = Device;

            _frameDuration = TenPower7 / Args.FrameRate;

            var attr = GetSinkWriterAttributes(Device);

            _writer = MediaFactory.CreateSinkWriterFromURL(Args.FileName, null, attr);

            var w = Args.ImageProvider.Width;
            var h = Args.ImageProvider.Height;

            _bufferSize = w * h * 4;

            using (var mediaTypeOut = new MediaType())
            {
                mediaTypeOut.Set(MediaTypeAttributeKeys.MajorType, MediaTypeGuids.Video);
                mediaTypeOut.Set(MediaTypeAttributeKeys.Subtype, _encodingFormat);
                mediaTypeOut.Set(MediaTypeAttributeKeys.AvgBitrate, BitRate);
                mediaTypeOut.Set(MediaTypeAttributeKeys.InterlaceMode, (int)VideoInterlaceMode.Progressive);
                mediaTypeOut.Set(MediaTypeAttributeKeys.FrameSize, PackLong(w, h));
                mediaTypeOut.Set(MediaTypeAttributeKeys.FrameRate, PackLong(Args.FrameRate, 1));
                mediaTypeOut.Set(MediaTypeAttributeKeys.PixelAspectRatio, PackLong(1, 1));
                _writer.AddStream(mediaTypeOut, out _);
            }

            using (var mediaTypeIn = new MediaType())
            {
                mediaTypeIn.Set(MediaTypeAttributeKeys.MajorType, MediaTypeGuids.Video);
                mediaTypeIn.Set(MediaTypeAttributeKeys.Subtype, inputFormat);
                mediaTypeIn.Set(MediaTypeAttributeKeys.InterlaceMode, (int)VideoInterlaceMode.Progressive);
                mediaTypeIn.Set(MediaTypeAttributeKeys.FrameSize, PackLong(w, h));
                mediaTypeIn.Set(MediaTypeAttributeKeys.FrameRate, PackLong(Args.FrameRate, 1));
                mediaTypeIn.Set(MediaTypeAttributeKeys.PixelAspectRatio, PackLong(1, 1));
                mediaTypeIn.Set(MediaTypeAttributeKeys.AllSamplesIndependent, 1);

                var encoderParams = new MediaAttributes(2);
                encoderParams.Set(RateControlModeKey, RateControlMode.Quality);
                encoderParams.Set(QualityKey, Args.VideoQuality);
                _writer.SetInputMediaType(VideoStreamIndex, mediaTypeIn, encoderParams);
            }

            if (Args.AudioProvider != null)
            {
                var wf = Args.AudioProvider.WaveFormat;
                _audioInBytesPerSecond = wf.SampleRate * wf.Channels * wf.BitsPerSample / 8;

                using (var audioTypeOut = GetMediaType(wf))
                {
                    audioTypeOut.Set(MediaTypeAttributeKeys.Subtype, _encodedAudioFormat);
                    audioTypeOut.Set(MediaTypeAttributeKeys.AudioAvgBytesPerSecond, GetAacBitrate(Args.AudioQuality));
                    _writer.AddStream(audioTypeOut, out _);
                }

                using var audioTypeIn = GetMediaType(wf);
                audioTypeIn.Set(MediaTypeAttributeKeys.Subtype, AudioFormatGuids.Pcm);
                _writer.SetInputMediaType(AudioStreamIndex, audioTypeIn, null);
            }

            _writer.BeginWriting();

            _copyTexture = new Texture2D(Device, new Texture2DDescription
            {
                CpuAccessFlags    = CpuAccessFlags.Read,
                BindFlags         = BindFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = w,
                Height            = h,
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1,
                ArraySize         = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage             = ResourceUsage.Staging
            });

            _sample = MediaFactory.CreateVideoSampleFromSurface(null);

            // Create the media buffer from the texture
            MediaFactory.CreateDXGISurfaceBuffer(typeof(Texture2D).GUID, _copyTexture, 0, false, out _mediaBuffer);

            using (var buffer2D = _mediaBuffer.QueryInterface <Buffer2D>())
                _mediaBuffer.CurrentLength = buffer2D.ContiguousLength;

            // Attach the created buffer to the sample
            _sample.AddBuffer(_mediaBuffer);
        }
예제 #6
0
 public virtual IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
 {
     return(new FFmpegWriter(FFmpegVideoWriterArgs.FromVideoWriterArgs(Args, this)));
 }
예제 #7
0
 public override void Apply(FFmpegSettings Settings, VideoWriterArgs WriterArgs, FFmpegOutputArgs OutputArgs)
 {
     OutputArgs.AddArg("c:v", _fFmpegCodecName)
     .AddArg("pixel_format", "yuv444p")
     .AddArg("preset", "fast");
 }
예제 #8
0
 public FFmpegRollingWriter(VideoWriterArgs VideoWriterArgs, int Duration)
 {
     _videoWriterArgs = VideoWriterArgs;
     _duration        = Duration;
     _frameCount      = _videoWriterArgs.FrameRate * Duration;
 }
예제 #9
0
        public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
        {
            _previewWindow.Show();

            return(new DiscardWriter());
        }
예제 #10
0
 public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
 {
     return(new DiscardWriter());
 }
예제 #11
0
 public IVideoFileWriter GetVideoFileWriter(VideoWriterArgs Args)
 {
     return(new ImageFolderWriter(Args.FileName));
 }