예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        private TimeSpan GetAudioDuration(ProbeModel.Stream audio)
        {
            double   duration      = audio.duration;
            TimeSpan audioDuration = TimeSpan.FromSeconds(duration);

            return(audioDuration);
        }
예제 #4
0
        private TimeSpan GetAudioDuration(ProbeModel.Stream audio)
        {
            double   duration      = audio.duration;
            TimeSpan audioDuration = TimeSpan.FromSeconds(duration);

            audioDuration = audioDuration.Subtract(TimeSpan.FromMilliseconds(audioDuration.Milliseconds));
            return(audioDuration);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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));
            }
        }
예제 #7
0
 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));
 }
예제 #8
0
        private long GetFrameCount(ProbeModel.Stream vid)
        {
            long frameCount = 0;

            return(long.TryParse(vid.nb_frames, out frameCount) ? frameCount : 0);
        }