public MediaProperties GetProperties(string videoPath) { var videoProperties = new MediaProperties(); ProbeModel.Stream[] streams = GetStream(videoPath); ProbeModel.Stream videoStream = streams[0]; ProbeModel.Stream audioStream = streams[1]; FormatModel.Format format = GetFormat(videoPath); videoProperties.Size = long.Parse(format.size); if (videoStream != null) { videoProperties.VideoFormat = videoStream.codec_name; videoProperties.VideoDuration = GetVideoDuration(format, videoStream); videoProperties.Width = videoStream.width; videoProperties.Height = videoStream.height; videoProperties.FrameRate = GetVideoFramerate(videoStream); videoProperties.Ratio = GetVideoAspectRatio(videoProperties.Width, videoProperties.Height); } if (audioStream != null) { videoProperties.AudioFormat = audioStream.codec_name; videoProperties.AudioDuration = GetAudioDuration(audioStream); } videoProperties.Duration = TimeSpan.FromSeconds(Math.Max(videoProperties.VideoDuration.TotalSeconds, videoProperties.AudioDuration.TotalSeconds)); return(videoProperties); }
private TimeSpan GetVideoDuration(ProbeModel.Stream video, FormatModel.Format format) { double duration = video.duration > 0.01 ? video.duration : format.duration; TimeSpan videoDuration = TimeSpan.FromSeconds(duration); return(videoDuration); }
private TimeSpan GetAudioDuration(ProbeModel.Stream audio) { double duration = audio.duration; TimeSpan audioDuration = TimeSpan.FromSeconds(duration); return(audioDuration); }
private TimeSpan GetAudioDuration(ProbeModel.Stream audio) { double duration = audio.duration; TimeSpan audioDuration = TimeSpan.FromSeconds(duration); audioDuration = audioDuration.Subtract(TimeSpan.FromMilliseconds(audioDuration.Milliseconds)); return(audioDuration); }
private TimeSpan GetVideoDuration(FormatModel.Format format, ProbeModel.Stream video) { video.duration = format.duration; // ReSharper disable once CompareOfFloatsByEqualityOperator video.bit_rate = format.bitRate == 0 ? video.bit_rate : format.bitRate; double duration = video.duration; TimeSpan videoDuration = TimeSpan.FromSeconds(duration); videoDuration = videoDuration.Subtract(TimeSpan.FromMilliseconds(videoDuration.Milliseconds)); return(videoDuration); }
private double GetVideoFramerate(ProbeModel.Stream vid) { long frameCount = GetFrameCount(vid); double duration = vid.duration; string[] fr = vid.r_frame_rate.Split('/'); if (frameCount > 0) { return(Math.Round(frameCount / duration, 3)); } else { return(Math.Round(double.Parse(fr[0]) / double.Parse(fr[1]), 3)); } }
private double GetVideoFramerate(ProbeModel.Stream vid) { string[] fr = vid.r_frame_rate.Split('/'); return(Math.Round(double.Parse(fr[0]) / double.Parse(fr[1]), 3)); }
private long GetFrameCount(ProbeModel.Stream vid) { long frameCount = 0; return(long.TryParse(vid.nb_frames, out frameCount) ? frameCount : 0); }