/// <summary> /// Initializes a new instance of the <see cref="StreamInfo"/> class. /// </summary> /// <param name="stream">The video stream.</param> /// <param name="container">The input container.</param> internal unsafe StreamInfo(AVStream *stream, InputContainer container) { var codec = stream->codec; Metadata = new ReadOnlyDictionary <string, string>(FFDictionary.ToDictionary(stream->metadata)); CodecName = ffmpeg.avcodec_get_name(codec->codec_id); CodecId = codec->codec_id.FormatEnum(12); Index = stream->index; IsInterlaced = codec->field_order != AVFieldOrder.AV_FIELD_PROGRESSIVE && codec->field_order != AVFieldOrder.AV_FIELD_UNKNOWN; FrameSize = new Size(codec->width, codec->height); PixelFormat = codec->pix_fmt.FormatEnum(11); AVPixelFormat = codec->pix_fmt; TimeBase = stream->time_base; RealFrameRate = stream->r_frame_rate; AvgFrameRate = stream->avg_frame_rate.ToDouble(); IsVariableFrameRate = RealFrameRate.ToDouble() != AvgFrameRate; Duration = stream->duration >= 0 ? stream->duration.ToTimeSpan(stream->time_base) : TimeSpan.FromTicks(container.Pointer->duration * 10); var start = stream->start_time.ToTimeSpan(stream->time_base); StartTime = start == TimeSpan.MinValue ? TimeSpan.Zero : start; if (stream->nb_frames > 0) { IsFrameCountProvidedByContainer = true; FrameCount = (int)stream->nb_frames; } else { FrameCount = Duration.ToFrameNumber(stream->avg_frame_rate); } }
/// <summary> /// Initializes a new instance of the <see cref="VideoStreamInfo"/> class. /// </summary> /// <param name="stream">A generic stream.</param> /// <param name="container">The input container.</param> internal unsafe VideoStreamInfo(AVStream *stream, InputContainer container) : base(stream, container) { var codec = stream->codec; AvgFrameRate = stream->avg_frame_rate.ToDouble(); IsVariableFrameRate = RealFrameRate.ToDouble() != AvgFrameRate; RealFrameRate = stream->r_frame_rate; FrameSize = new Size(codec->width, codec->height); PixelFormat = codec->pix_fmt.FormatEnum(11); AVPixelFormat = codec->pix_fmt; }
/// <summary> /// Initializes a new instance of the <see cref="StreamInfo"/> class. /// </summary> /// <param name="stream">A generic stream.</param> /// <param name="type">The media type of the stream.</param> /// <param name="container">The input container.</param> internal unsafe StreamInfo(AVStream *stream, MediaType type, InputContainer container) { var codec = stream->codec; Metadata = new ReadOnlyDictionary <string, string>(FFDictionary.ToDictionary(stream->metadata)); CodecName = ffmpeg.avcodec_get_name(codec->codec_id); CodecId = codec->codec_id.FormatEnum(12); Index = stream->index; Type = type; TimeBase = stream->time_base; RealFrameRate = stream->r_frame_rate; AvgFrameRate = stream->avg_frame_rate.ToDouble(); IsVariableFrameRate = RealFrameRate.ToDouble() != AvgFrameRate; if (stream->duration >= 0) { Duration = stream->duration.ToTimeSpan(stream->time_base); DurationRaw = stream->duration; } else { Duration = TimeSpan.FromTicks(container.Pointer->duration * 10); DurationRaw = Duration.ToTimestamp(TimeBase); } if (stream->start_time >= 0) { StartTime = stream->start_time.ToTimeSpan(stream->time_base); } if (stream->nb_frames > 0) { IsFrameCountProvidedByContainer = true; NumberOfFrames = (int)stream->nb_frames; FrameCount = NumberOfFrames.Value; } else { FrameCount = Duration.ToFrameNumber(stream->avg_frame_rate); if (!IsVariableFrameRate) { NumberOfFrames = FrameCount; } else { NumberOfFrames = null; } } }