/// <summary>
 /// Initializes a new instance of the <see cref="VideoStream"/> class.
 /// </summary>
 /// <param name="video">The video stream.</param>
 /// <param name="options">The decoder settings.</param>
 internal VideoStream(InputStream <VideoFrame> video, MediaOptions options)
 {
     stream       = video;
     mediaOptions = options;
     frame        = VideoFrame.CreateEmpty();
     scaler       = new Scaler();
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VideoStream"/> class.
 /// </summary>
 /// <param name="video">The video stream.</param>
 /// <param name="options">The decoder settings.</param>
 internal VideoStream(InputStream <VideoFrame> video, MediaOptions options)
 {
     stream       = video;
     mediaOptions = options;
     frame        = VideoFrame.CreateEmpty();
     converter    = new ImageConverter();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaStream"/> class.
        /// </summary>
        /// <param name="stream">The associated codec.</param>
        /// <param name="options">Extra options.</param>
        internal MediaStream(Decoder stream, MediaOptions options)
        {
            Stream  = stream;
            Options = options;

            Threshold = TimeSpan.FromSeconds(0.5).ToTimestamp(Info.TimeBase);
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VideoStream"/> class.
 /// </summary>
 /// <param name="video">The video stream.</param>
 /// <param name="options">The decoder settings.</param>
 internal VideoStream(Decoder <VideoFrame> video, MediaOptions options)
 {
     stream          = video;
     mediaOptions    = options;
     frame           = VideoFrame.CreateEmpty();
     outputFrameSize = options.TargetVideoSize ?? video.Info.FrameSize;
     converter       = new Lazy <ImageConverter>(() => new ImageConverter(video.Info.FrameSize, video.Info.AVPixelFormat, outputFrameSize, (AVPixelFormat)options.VideoPixelFormat));
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VideoStream"/> class.
 /// </summary>
 /// <param name="video">The video stream.</param>
 /// <param name="options">The decoder settings.</param>
 internal VideoStream(Decoder <VideoFrame> video, MediaOptions options)
 {
     stream          = video;
     mediaOptions    = options;
     outputFrameSize = options.TargetVideoSize ?? video.Info.FrameSize;
     converter       = new Lazy <ImageConverter>(() => new ImageConverter(video.Info.FrameSize, video.Info.AVPixelFormat, outputFrameSize, (AVPixelFormat)options.VideoPixelFormat));
     threshold       = TimeSpan.FromSeconds(0.5).ToTimestamp(Info.TimeBase);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="VideoStream"/> class.
        /// </summary>
        /// <param name="stream">The video stream.</param>
        /// <param name="options">The decoder settings.</param>
        internal VideoStream(Decoder stream, MediaOptions options)
            : base(stream, options)
        {
            OutputFrameSize = options.TargetVideoSize ?? Info.FrameSize;
            Converter       = new Lazy <ImageConverter>(() => new ImageConverter(Info.FrameSize, Info.AVPixelFormat, OutputFrameSize, (AVPixelFormat)options.VideoPixelFormat));

            outputFrameStride  = ImageData.EstimateStride(OutputFrameSize.Width, Options.VideoPixelFormat);
            requiredBufferSize = outputFrameStride * OutputFrameSize.Height;
        }
Example #7
0
        private unsafe MediaFile(InputContainer container, MediaOptions options)
        {
            this.container = container;

            if (container.Video != null)
            {
                Video = new VideoStream(container.Video, options);
            }

            Info = new MediaInfo(container.Pointer);
        }
Example #8
0
        private unsafe MediaFile(InputContainer container, MediaOptions options)
        {
            this.container = container;

            var video = container.Decoders.Where(codec => codec?.Info.Type == MediaType.Video);
            var audio = container.Decoders.Where(codec => codec?.Info.Type == MediaType.Audio);

            VideoStreams = video.Select(codec => new VideoStream(codec, options)).ToArray();
            AudioStreams = audio.Select(codec => new AudioStream(codec, options)).ToArray();

            Info = new MediaInfo(container.Pointer);
        }
Example #9
0
 /// <summary>
 /// Opens a media stream.
 /// </summary>
 /// <param name="stream">A stream of the multimedia file.</param>
 /// <param name="options">The decoder settings.</param>
 /// <returns>The opened <see cref="MediaFile"/>.</returns>
 public static MediaFile Open(Stream stream, MediaOptions options)
 {
     try
     {
         var container = InputContainer.LoadStream(stream, options);
         return(new MediaFile(container, options));
     }
     catch (Exception ex)
     {
         throw new Exception("Failed to open the media stream", ex);
     }
 }
Example #10
0
 /// <summary>
 /// Opens a media file from the specified path.
 /// </summary>
 /// <param name="path">A path to the media file.</param>
 /// <param name="options">The decoder settings.</param>
 /// <returns>The opened <see cref="MediaFile"/>.</returns>
 public static MediaFile Open(string path, MediaOptions options)
 {
     try
     {
         var container = InputContainer.LoadFile(path, options);
         return(new MediaFile(container, options));
     }
     catch (DirectoryNotFoundException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new Exception("Failed to open the media file", ex);
     }
 }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AudioStream"/> class.
        /// </summary>
        /// <param name="stream">The audio stream.</param>
        /// <param name="options">The decoder settings.</param>
        internal AudioStream(Decoder stream, MediaOptions options)
            : base(stream, options)
        {
            swrContext = ffmpeg.swr_alloc_set_opts(
                null,
                Info.ChannelLayout,
                (AVSampleFormat)SampleFormat.SingleP,
                Info.SampleRate,
                Info.ChannelLayout,
                (AVSampleFormat)Info.SampleFormat,
                Info.SampleRate,
                0,
                null);

            ffmpeg.swr_init(swrContext);
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AudioStream"/> class.
 /// </summary>
 /// <param name="audio">The Audio stream.</param>
 /// <param name="options">The decoder settings.</param>
 internal AudioStream(Decoder <AudioFrame> audio, MediaOptions options)
 {
     stream       = audio;
     mediaOptions = options;
     frame        = AudioFrame.CreateEmpty();
 }