Exemplo n.º 1
0
 public static Video Create(string filePath)
 {
     if (File.Exists(filePath))
     {
         ffprobeType metaData = RawFFmpeg.GetRawMetadata(filePath);
         return(new Video(filePath, metaData));
     }
     else
     {
         Utilities.Error(28641);
         return(null);
     }
 }
Exemplo n.º 2
0
 public MediaInfo(string xml)
 {
     try {
         using (TextReader ms = new StringReader(xml)) {
             XmlSerializer xs = new XmlSerializer(typeof(ffprobeType));
             ffprobeType   ff = xs.Deserialize(ms) as ffprobeType;
             if (ff == null || ff.streams == null || ff.format == null)
             {
                 throw new CoreException(I18n.Get("ErrorInvalidFormat"));
             }
             if (ff.streams.Length > 2)
             {
                 throw new CoreException(I18n.Get("ErrorNoMore2Streams"));
             }
             FormatInfo = ff.format;
             foreach (streamType st in ff.streams)
             {
                 if ("video".Equals(st.codec_type))
                 {
                     if (VideoInfo != null)
                     {
                         throw new CoreException(I18n.Get("ErrorNoMore1Video"));
                     }
                     VideoInfo = st;
                 }
                 else
                 {
                     if (AudioInfo != null)
                     {
                         throw new CoreException(I18n.Get("ErrorNoMore1Audio"));
                     }
                     AudioInfo = st;
                 }
             }
         }
     } catch (Exception ex) {
         FormatInfo = null;
         VideoInfo  = null;
         AudioInfo  = null;
         ex.PreserveStackTrace();
         throw new CoreException(ex.Message, ex);
     }
 }
Exemplo n.º 3
0
        private Video(string filePath, ffprobeType metaData)
        {
            FilePath = filePath;
            if (File.Exists(filePath))
            {
                RawMetadata = metaData;

                Duration = TimeSpan.FromSeconds(
                    (double)RawVideoMetadata.duration_ts * (double)Utilities.DivideString(RawVideoMetadata.time_base)
                    );
                if (Duration == TimeSpan.Zero)
                {
                    Duration = RawFFmpeg.GetDuration(FilePath);
                }

                Geometry = new Geometry(RawVideoMetadata.width, RawVideoMetadata.height);
            }
            else
            {
                throw new FileNotFoundException();
            }
        }