private static IContainer LoadMetadataFromFFprobe(this IContainer resource) { var mediaLoader = new MediaLoader(resource); if (mediaLoader.HasAudio) { resource.Streams.AddRange(mediaLoader.BaseData.Streams .OfType <AudioStreamMetadata>() .Select(audioMetadata => AudioStream.Create(MetadataInfo.Create(audioMetadata)))); } if (mediaLoader.HasVideo) { resource.Streams.AddRange(mediaLoader.BaseData.Streams .OfType <VideoStreamMetadata>() .Select(videoMetadata => VideoStream.Create(MetadataInfo.Create(videoMetadata)))); } if (mediaLoader.HasData) { resource.Streams.AddRange(mediaLoader.BaseData.Streams .OfType <DataStreamMetadata>() .Select(dataMetadata => DataStream.Create(MetadataInfo.Create(dataMetadata)))); } return(resource); }
public MetadataInfoTreeContainer EditInfo(MetadataInfoTreeContainer infoToUpdate, List <MetadataInfoTreeContainer> suppliedInfo) { var emptyMetadataInfo = MetadataInfo.Create(); emptyMetadataInfo.VideoMetadata = new VideoStreamMetadata { Width = Size.HasValue ? Size.Value.Width : 320, Height = Size.HasValue ? Size.Value.Height : 240, AverageFrameRate = Fraction.Create(FrameRate ?? 25, 1), RFrameRate = Fraction.Create(FrameRate ?? 25, 1), Duration = Duration ?? TimeSpan.MaxValue, DurationTs = long.MaxValue, }; return(MetadataInfoTreeContainer.Create(VideoStream.Create(emptyMetadataInfo))); }
public void Initialize(params Encoder[] encoders) { if (encoders is null) { throw new ArgumentNullException(nameof(encoders)); } var streams = new MediaStream[encoders.Length]; for (var i = 0; i < streams.Length; i++) { var encoder = encoders[i]; // Ensure a stream was intilized... if (encoder.Stream is null) { MediaStream stream; switch (encoder) { case AudioEncoder _: stream = VideoStream.Create(this, encoder); break; case VideoEncoder _: stream = AudioStream.Create(this, encoder); break; default: throw new Exception("Invalid encoder type:" + encoder.GetType().Name); } stream.TimeBase = encoder.Context.TimeBase; } if (Context.OutputFormat.Flags.HasFlag(OutputFormatFlags.GlobalHeader)) { encoder.Context.Flags |= (int)OutputFormatFlags.GlobalHeader; } streams[i] = encoder.Stream; encoder.Open(); ffmpeg.avcodec_parameters_from_context(encoder.Stream.Pointer->codecpar, encoder.Context.Pointer); } this.Context.Streams = streams; }
private static IContainer LoadMetadataFromFFprobe(this IContainer resource) { var mediaLoader = new Metadata.FFprobe.MediaLoader(resource); if (mediaLoader.HasAudio) { var audioStreamMetadata = MetadataInfo.Create(mediaLoader.AudioStream); resource.Streams.Add(AudioStream.Create(audioStreamMetadata)); } if (mediaLoader.HasVideo) { var videoStreamMetadata = MetadataInfo.Create(mediaLoader.VideoStream); resource.Streams.Add(VideoStream.Create(videoStreamMetadata)); } return(resource); }