Vidka.Core.VideoMeta.VideoMetadataUseful.GetVideoDurationSec C# (CSharp) Method

GetVideoDurationSec() public method

public GetVideoDurationSec ( double projFps ) : double
projFps double
return double
        public double GetVideoDurationSec(double projFps)
        {
            if (videoStream == null)
                return 0;
            // hack to use
            if (projFps == 30
                && videoStream.r_frame_rate == "1000000/33333"
                && videoStream.avg_frame_rate == "1000000/33333")
                return (double)videoStream.nb_read_frames / projFps;
            return (double)videoStream.duration;
        }

Usage Example

 private void metaGenerator_MetaReady(string filename, VideoMetadataUseful meta)
 {
     lock (this)
     {
         // 2 cases: meta is ready for one of the draggies, or for one of the outstanding media
         var draggyMaybe = _draggies.FirstOrDefault(x => x.Filename == filename);
         if (draggyMaybe != null)
         {
             draggyMaybe.Meta = meta;
             if (MetaReadyForDraggy != null)
                 MetaReadyForDraggy(filename, meta);
             return;
         }
         // at this point it could be one of outstanding media (video or audio)
         var outstandingMaybeVid = outstandingVideo.FirstOrDefault(x => x.FileName == filename);
         if (outstandingMaybeVid != null)
         {
             // TODO: handle variable fps, fps == proj.fps and counted frames for PENTAX avis
             outstandingMaybeVid.FileLengthSec = meta.GetVideoDurationSec(Proj.FrameRate);
             // remember, this clip could be different fps, we need proj's fps
             var projFramesThisOne = Proj.SecToFrame(outstandingMaybeVid.FileLengthSec ?? 0);
             outstandingMaybeVid.FileLengthFrames = projFramesThisOne;
             outstandingMaybeVid.FrameEnd = projFramesThisOne;
             if (outstandingMaybeVid is VidkaClipVideo)
             {
                 var outstandingMaybeVidVVV = (VidkaClipVideo)outstandingMaybeVid;
                 outstandingMaybeVidVVV.HasAudioXml = meta.HasAudio;
             }
             outstandingMaybeVid.IsNotYetAnalyzed = false;
             outstandingVideo.Remove(outstandingMaybeVid);
             if (MetaReadyForOutstandingVideo != null)
                 MetaReadyForOutstandingVideo(outstandingMaybeVid, meta);
             return;
         }
         var outstandingMaybeAud = outstandingAudio.FirstOrDefault(x => x.FileName == filename);
         if (outstandingMaybeAud != null)
         {
             outstandingMaybeAud.FileLengthSec = meta.AudioDurationSec;
             var projFramesThisOne = Proj.SecToFrame(outstandingMaybeAud.FileLengthSec ?? 0);
             outstandingMaybeAud.FileLengthFrames = projFramesThisOne;
             outstandingMaybeAud.FrameEnd = projFramesThisOne;
             outstandingAudio.Remove(outstandingMaybeAud);
             if (MetaReadyForOutstandingAudio != null)
                 MetaReadyForOutstandingAudio(outstandingMaybeAud, meta);
             return;
         }
     }
 }