示例#1
0
        private void SendEventGhostEvent(VideoFormat format)
        {
            var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process";

            using (var searcher = new ManagementObjectSearcher(wmiQueryString))
                using (var results = searcher.Get())
                {
                    var query = from p in Process.GetProcesses()
                                join mo in results.Cast <ManagementObject>()
                                on p.Id equals(int)(uint) mo["ProcessId"]
                                select new
                    {
                        Process     = p,
                        Path        = (string)mo["ExecutablePath"],
                        CommandLine = (string)mo["CommandLine"],
                    };
                    foreach (var item in query)
                    {
                        if (item.Process.ProcessName.Contains("EventGhost"))
                        {
                            Process p = new Process();
                            p.StartInfo.FileName    = item.Path;
                            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            p.StartInfo.Arguments   = "-event Auto3D." + format.ToString();
                            p.Start();
                            return;
                        }
                    }
                }
        }
示例#2
0
        public string MergeAudioSegment(string audioFile, VideoFormat type)
        {
            //ffmpeg -i tmpVideo.mpg -i tmpAudioRB.wav -vcodec copy finalVideow_6.mpg
            string        tempFile = Path.GetTempPath() + Guid.NewGuid() + "." + type.ToString();
            List <string> files    = new List <string>();

            files.Add(audioFile);

            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath        = FilePath,
                DisableAudio         = false,
                AdditionalFileInputs = files,
                OutputOptions        = String.Format("-map 0:0 -map 1:0 -vcodec copy -acodec copy"),
                OutputFilePath       = tempFile,
            };

            string output = FFMpegService.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            return(tempFile);
        }
示例#3
0
        public string ExtractVideoSegment(long ticksToExtract, long ticksTimeLapse, VideoFormat type, Size dimensions)
        {
            string tempFile = Path.GetTempPath() + Guid.NewGuid() + "." + type.ToString();
            var    span     = TimeSpan.FromTicks(ticksToExtract);
            var    spanTo   = TimeSpan.FromTicks(ticksTimeLapse - ticksToExtract);

            if (span > Duration)
            {
                throw new Exception("Time is larger than actual video");
            }

            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath  = FilePath,
                DisableAudio   = false,
                OutputOptions  = String.Format("-ss {0} -t {1}", span.Hours.ToString("D2") + ":" + span.Minutes.ToString("D2") + ":" + span.Seconds.ToString("D2") + "." + span.Milliseconds.ToString("D3"), spanTo.Hours.ToString("D2") + ":" + spanTo.Minutes.ToString("D2") + ":" + spanTo.Seconds.ToString("D2") + "." + spanTo.Milliseconds.ToString("D3")),
                Size           = dimensions,
                OutputFilePath = tempFile,
            };

            string output = FFMpegService.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            return(tempFile);
        }
示例#4
0
        public void WriteXml(XmlWriter w)
        {
            w.WriteElementString("LeftImageRoot", LeftImageRoot);
            w.WriteElementString("LeftImageSubdir", LeftImageSubdir);
            w.WriteElementString("LeftImageFile", LeftImageFile);
            w.WriteElementString("LeftVideoRoot", LeftVideoRoot);
            w.WriteElementString("LeftVideoSubdir", LeftVideoSubdir);
            w.WriteElementString("LeftVideoFile", LeftVideoFile);
            w.WriteElementString("RightImageRoot", RightImageRoot);
            w.WriteElementString("RightImageSubdir", RightImageSubdir);
            w.WriteElementString("RightImageFile", RightImageFile);
            w.WriteElementString("RightVideoRoot", RightVideoRoot);
            w.WriteElementString("RightVideoSubdir", RightVideoSubdir);
            w.WriteElementString("RightVideoFile", RightVideoFile);

            w.WriteElementString("ImageFormat", ImageFormat.ToString());
            w.WriteElementString("VideoFormat", VideoFormat.ToString());
            w.WriteElementString("UncompressedVideoFormat", UncompressedVideoFormat.ToString());
        }
        public override void OnStart(EncoderOption option)
        {
            this.option = option;

            var audio_file = StoryboardInstanceManager.ActivityInstance?.Info?.audio_file_path;

            audio_reader = new MediaReader(audio_file);

            audio_decoder = audio_reader.Decoders.OfType <AudioDecoder>().FirstOrDefault();

            #region Video Init

            var video_format = new VideoFormat(option.Width, option.Height, AVPixelFormat.Bgr24);
            var video_param  = new VideoEncoderParameters()
            {
                FrameRate = new Fraction(option.FPS), BitRate = option.BitRate
            };

            video_encoder = new VideoEncoder(option.EncoderName, video_format, video_param);

            #endregion Video Init

            writer = new MediaWriter(option.OutputPath, false).AddEncoder(video_encoder);

            if (audio_decoder != null)
            {
                audio_encoder = new AudioEncoder(audio_decoder.ID, audio_decoder.OutFormat, BitRate._192Kbps);
                writer.AddEncoder(audio_encoder);
            }

            writer.Initialize();

            Log.User($"Format :{video_format.ToString()}\nVideo Encoder :{video_encoder.ToString()}");

            video_frame = new VideoFrame(video_format);
            audio_frame = new AudioFrame(audio_decoder.OutFormat);

            audio_encoding_thread      = new Thread(AudioEncoding);
            audio_encoding_thread.Name = "Audio Encoder Thread";
            audio_encoding_thread.Start();
        }
示例#6
0
        public string GetLocation(VideoFormat format, VideoVersion videoVersion)
        {
            string strFormat = "flv";

            if (format == VideoFormat._3gp)
            {
                strFormat = "3gp";
            }
            else
            {
                strFormat = format.ToString().ToLower();
            }
            string location = string.Format("/{0}/{1}/{2}", this.UserID, Helper.GetMediaFolder(Helper.GetObjectType("Video").NumericId), strFormat);

            if (videoVersion != VideoVersion.None)
            {
                location += string.Format(@"/{0}", videoVersion);
            }
            location += string.Format("/{0}.{1}", ObjectID, strFormat);
            return(location.ToLower());
        }
示例#7
0
        private void doCompression(VideoFormat videoFormat, string tmpAviFilePath, DicomElement dicomElement)
        {
            string format           = videoFormat.ToString().ToLower();
            string outputFileName   = Path.GetFileNameWithoutExtension(dicomElement.FilePath) + "." + format;
            string outputFolderPath = Settings.Default.ExportPath + dicomElement.GetSubFolderPath(format);

            Directory.CreateDirectory(outputFolderPath);
            string outputFilePath = Path.Combine(outputFolderPath, outputFileName);

            if (File.Exists(outputFilePath))
            {
                outputFilePath = renameToNonExistentFileName(outputFilePath);
            }

            if (videoFormat == VideoFormat.M4V)
            {
                executeMultiPassesCommandsForM4v(tmpAviFilePath, outputFilePath);
            }
            else
            {
                executeFFmpegCommand(createDefaultArguments(videoFormat, tmpAviFilePath, outputFilePath, dicomElement));
            }
        }
示例#8
0
        private string createDefaultArguments(VideoFormat videoFormat, string inputFilePath, string outputFilePath, DicomElement dicomElement)
        {
            // for ffmpeg testing
            //ffmpeg -i test-video.avi -r 2 -qscale 31 -f m4v m5.mpg
            // mpeg1 supports only specific fps values, see mpeg12data.c from ffmpeg source
            string format = videoFormat.ToString().ToLower();

            int    originalFps;
            string strOriginalFps = dicomElement.DicomFile.DataSet[DicomTags.CineRate].GetString(0, "");

            if (int.TryParse(strOriginalFps, out originalFps) == false)
            {
                originalFps = Settings.Default.Fps;
            }

            int fps = (videoFormat == VideoFormat.MPEG) ? 24 : originalFps;

            return(@"-i " + inputFilePath
                   + " -r " + fps
                   + " -qscale " + Settings.Default.Quality
                   + " -f " + format
                   + " \"" + outputFilePath + "\"");
        }
示例#9
0
        public string MergeAudioSegments(List <string> audioFiles, VideoFormat type)
        {
            string        tempFile = Path.GetTempPath() + Guid.NewGuid() + "." + type.ToString();
            List <string> files    = audioFiles;

            string outputOptions = string.Empty;

            string copyAll = " -c:v copy -c:a copy";

            for (int i = 0; i < files.Count; i++)
            {
                outputOptions += "-map " + (i + 1) + ":0";
                if (i + files.Count < files.Count)
                {
                    outputOptions += " ";
                }
            }

            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath        = FilePath,
                DisableAudio         = false,
                AdditionalFileInputs = files,
                OutputOptions        = outputOptions + copyAll,
                OutputFilePath       = tempFile,
            };

            string output = FFMpegService.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            return(tempFile);
        }
示例#10
0
        public override List <String> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false)
        {
            if (request.Proxy == null)
            {
                video.PlaybackOptions = Hoster.HosterFactory.GetHoster("Youtube").GetPlaybackOptions(video.VideoUrl);
            }
            else
            {
                video.PlaybackOptions = Hoster.HosterFactory.GetHoster("Youtube").GetPlaybackOptions(video.VideoUrl /*, request.Proxy*/);
            }

            if (video.PlaybackOptions != null && video.PlaybackOptions.Count > 0)
            {
                if (video.PlaybackOptions.Count == 1)
                {
                    // nothing to chose from, only one options available
                    return(new List <string>()
                    {
                        video.PlaybackOptions.First().Value
                    });
                }
                else
                {
                    KeyValuePair <string, string> foundQuality = default(KeyValuePair <string, string>);
                    switch (videoQuality)
                    {
                    case VideoQuality.Low:                                      //use first available option
                        foundQuality = video.PlaybackOptions.First(); break;

                    case VideoQuality.Medium:                                   //first above 320 that is not 3D
                        foundQuality = video.PlaybackOptions.FirstOrDefault(q => !q.Key.Contains("320") && !q.Key.Contains("3D")); break;

                    case VideoQuality.High:                                     //highest below the HD formats that is not 3D
                        foundQuality = video.PlaybackOptions.LastOrDefault(q => !q.Key.Contains("1920") && !q.Key.Contains("1280") && !q.Key.Contains("3D")); break;

                    case VideoQuality.HD:                                       //first below full HD that is not 3D
                        foundQuality = video.PlaybackOptions.LastOrDefault(q => !q.Key.Contains("1920") && !q.Key.Contains("3D")); break;

                    case VideoQuality.FullHD:                                   //use highest available quality that is not 3D
                        foundQuality = video.PlaybackOptions.Last(q => !q.Key.Contains("3D")); break;
                    }
                    if (!string.IsNullOrEmpty(foundQuality.Key))
                    {
                        string resolution = foundQuality.Key.Substring(0, foundQuality.Key.IndexOf('|'));
                        // try to find one that has the same resolution and the preferred format
                        var bestMatch = video.PlaybackOptions.FirstOrDefault(q => q.Key.Contains(resolution) && !q.Key.Contains("3D") && q.Key.Contains(preferredFormat.ToString()));
                        // try to find one that has the same resolution and not the undesired format
                        if (string.IsNullOrEmpty(bestMatch.Key))
                        {
                            bestMatch = video.PlaybackOptions.FirstOrDefault(q => q.Key.Contains(resolution) && !q.Key.Contains("3D") && !q.Key.Contains(undesiredFormat.ToString()));
                        }
                        if (!string.IsNullOrEmpty(bestMatch.Key))
                        {
                            foundQuality = bestMatch;
                        }
                    }
                    // fallback when no match was found -> use first choice
                    if (string.IsNullOrEmpty(foundQuality.Key))
                    {
                        foundQuality = video.PlaybackOptions.First();
                    }
                    if (inPlaylist)
                    {
                        video.PlaybackOptions = null;
                    }
                    return(new List <string>()
                    {
                        foundQuality.Value
                    });
                }
            }
            return(null);            // no playback options
        }
示例#11
0
        private string createDefaultArguments(VideoFormat videoFormat, string inputFilePath, string outputFilePath, DicomElement dicomElement)
        {
            // for ffmpeg testing
            //ffmpeg -i test-video.avi -r 2 -qscale 31 -f m4v m5.mpg
            // mpeg1 supports only specific fps values, see mpeg12data.c from ffmpeg source
            string format = videoFormat.ToString().ToLower();

            int originalFps;
            string strOriginalFps = dicomElement.DicomFile.DataSet[DicomTags.CineRate].GetString(0, "");
            if (int.TryParse(strOriginalFps, out originalFps) == false)
            {
                originalFps = Settings.Default.Fps;
            }

            int fps = (videoFormat == VideoFormat.MPEG) ? 24 : originalFps;

            return @"-i " + inputFilePath
                + " -r " + fps
                + " -qscale " + Settings.Default.Quality
                + " -f " + format
                + " \"" + outputFilePath + "\"";
        }
示例#12
0
        private void doCompression(VideoFormat videoFormat,string tmpAviFilePath, DicomElement dicomElement)
        {
            string format = videoFormat.ToString().ToLower();
            string outputFileName = Path.GetFileNameWithoutExtension(dicomElement.FilePath) + "." + format;
            string outputFolderPath = Settings.Default.ExportPath + dicomElement.GetSubFolderPath(format);
            Directory.CreateDirectory(outputFolderPath);
            string outputFilePath = Path.Combine(outputFolderPath, outputFileName);
            if (File.Exists(outputFilePath))
            {
                outputFilePath = renameToNonExistentFileName(outputFilePath);
            }

            if (videoFormat == VideoFormat.M4V)
            {
                executeMultiPassesCommandsForM4v(tmpAviFilePath, outputFilePath);

            }
            else
            {
                executeFFmpegCommand(createDefaultArguments(videoFormat, tmpAviFilePath, outputFilePath, dicomElement));
            }
        }
示例#13
0
        /// <summary>
        /// 开始下载
        /// </summary>
        private async void Btn_ok_Click(object sender, RoutedEventArgs e)
        {
            int i = 0;

            flyout_download.Hide();
            foreach (Pages item in ReadyList.SelectedItems)
            {
                try
                {
                    cid = item.Cid;
                    VideoURL url = await ContentServ.GetVedioURL(cid, quality, format);

                    string        name   = StringDeal.RemoveSpecial(title.Text);
                    string        part   = StringDeal.RemoveSpecial(item.Part);
                    StorageFolder folder = await DownloadHelper.GetMyFolderAsync();

                    StorageFolder f1 = await folder.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists);

                    List <DownloadOperation> list = new List <DownloadOperation>();
                    for (int j = 0; j < url.Ps.Count; j++)
                    {
                        list.Add(await DownloadHelper.Download(url.Ps[j].Url, $"{part}_{j}.{format.ToString()}", f1));
                    }
                    // 如果await,那么执行完第一个StartAsync()后即退出循环.GetCurrentDownloadsAsync()方法同样会遇到此问题.(Download页)
                    IAsyncOperationWithProgress <DownloadOperation, DownloadOperation> start;
                    for (int k = 0; k < list.Count; k++)
                    {
                        start = list[k].StartAsync();
                    }
                    i++;
                    await DownloadHelper.AddVideoInfo(part, cid, details.Sid);

                    await popup.Show(i.ToString() + "个视频已加入下载队列");

                    if (SettingHelper.ContainsKey("_downdanmu"))
                    {
                        if ((bool)SettingHelper.GetValue("_downdanmu") == false)
                        {
                            continue;
                        }
                    }
                    await DownloadHelper.DownloadDanmakuAsync(cid, part, f1);
                }
                catch (Exception err)
                {
                    await popup.Show(err.Message);
                }
            }
            SwitchCommandBar(false);
        }
示例#14
0
 private void SendEventGhostEvent(VideoFormat format)
 {
     var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process";
       using (var searcher = new ManagementObjectSearcher(wmiQueryString))
       using (var results = searcher.Get())
       {
     var query = from p in Process.GetProcesses()
             join mo in results.Cast<ManagementObject>()
             on p.Id equals (int)(uint)mo["ProcessId"]
             select new
             {
               Process = p,
               Path = (string)mo["ExecutablePath"],
               CommandLine = (string)mo["CommandLine"],
             };
     foreach (var item in query)
     {
       if (item.Process.ProcessName.Contains("EventGhost"))
       {
     Process p = new Process();
     p.StartInfo.FileName = item.Path;
     p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     p.StartInfo.Arguments = "-event Auto3D." + format.ToString();
     p.Start();
     return;
       }
     }
       }
 }
示例#15
0
 string GetVideoFormatName(VideoFormat videoFormat)
 {
     return("." + videoFormat.ToString().ToLower());
 }
示例#16
0
        public string ExtractVideoSegment(long ticksToExtract, long ticksTimeLapse, VideoFormat type, Size dimensions)
        {
            
            string tempFile = Path.GetTempPath() + Guid.NewGuid() + "." + type.ToString();
            var span = TimeSpan.FromTicks(ticksToExtract);
            var spanTo = TimeSpan.FromTicks(ticksTimeLapse - ticksToExtract);

            if (span > Duration)
                throw new Exception("Time is larger than actual video");

            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath = FilePath,
                DisableAudio = false,
                OutputOptions = String.Format("-ss {0} -t {1}", span.Hours.ToString("D2") + ":" + span.Minutes.ToString("D2") + ":" + span.Seconds.ToString("D2") + "." + span.Milliseconds.ToString("D3"), spanTo.Hours.ToString("D2") + ":" + spanTo.Minutes.ToString("D2") + ":" + spanTo.Seconds.ToString("D2") + "." + spanTo.Milliseconds.ToString("D3")),
                Size = dimensions,
                OutputFilePath = tempFile,
            };

            string output = FFMpegService.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            return tempFile;
        }
示例#17
0
        public string MergeAudioSegment(string audioFile, VideoFormat type)
        {
            //ffmpeg -i tmpVideo.mpg -i tmpAudioRB.wav -vcodec copy finalVideow_6.mpg
            string tempFile = Path.GetTempPath() + Guid.NewGuid() + "." + type.ToString();
            List<string> files = new List<string>();
            files.Add(audioFile);

            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath = FilePath,
                DisableAudio = false,
                AdditionalFileInputs = files,
                OutputOptions = String.Format("-map 0:0 -map 1:0 -vcodec copy -acodec copy"),
                OutputFilePath = tempFile,
            };

            string output = FFMpegService.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            return tempFile;
        }
示例#18
0
        public string MergeAudioSegments(List<string> audioFiles, VideoFormat type)
        {
            string tempFile = Path.GetTempPath() + Guid.NewGuid() + "." + type.ToString();
            List<string> files = audioFiles;

            string outputOptions = string.Empty;

            string copyAll = " -c:v copy -c:a copy";

            for (int i = 0; i < files.Count; i++)
            {
                outputOptions += "-map " + (i + 1) + ":0";
                if (i + files.Count < files.Count)
                    outputOptions += " ";
            }

            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath = FilePath,
                DisableAudio = false,
                AdditionalFileInputs = files,
                OutputOptions = outputOptions + copyAll,
                OutputFilePath = tempFile,
            };

            string output = FFMpegService.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            return tempFile;
        }
示例#19
0
        /// <summary>
        /// Formatiert den Wert der aktuellen Instanz unter Verwendung des angegebenen Formats.
        /// </summary>
        /// <returns>
        /// Der Wert der aktuellen Instanz im angegebenen Format.
        /// </returns>
        /// <param name="format">Das zu verwendende Format.– oder – Ein NULL-Verweis (Nothing in Visual Basic),
        ///  wenn das für den Typ der <see cref="T:System.IFormattable"/> -Implementierung definierte Standardformat verwendet werden soll. </param>
        /// <param name="formatProvider">Der zum Formatieren des Werts zu verwendende Anbieter.– oder – Ein NULL-Verweis (Nothing in Visual Basic),
        ///  wenn die Informationen über numerische Formate dem aktuellen Gebietsschema des Betriebssystems entnommen werden sollen. </param>
        /// <filterpriority>2</filterpriority>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            string result = string.Empty;

            result += string.Format(AppSettings.CInfo, "VideoInfo.FPS:              {0:g} {1:s}", FPS,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.Format:           {0:s} {1:s}", Format,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.FormatProfile:    {0:s} {1:s}", FormatProfile,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.StreamID:         {0:g} {1:s}", StreamId,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.VTS_ID:           {0:g} {1:s}", VtsId,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.TrackID:          {0:g} {1:s}", TrackId,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.TempFile:         {0:s} {1:s}", TempFile,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.Interlaced:       {0:s} {1:s}",
                                    Interlaced.ToString(AppSettings.CInfo), Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.PicSize:          {0:s} {1:s}", PicSize.ToString("F"),
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.DemuxStreamID:    {0:g} {1:s}", DemuxStreamId,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.DemuxStreamNames: {0:s} {1:s}",
                                    string.Join(",", DemuxStreamNames.ToArray()), Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.DemuxPlayList:    {0:g} {1:s}", DemuxPlayList,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.Width:            {0:g} {1:s}", Width,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.Height:           {0:g} {1:s}", Height,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.FrameCount:       {0:g} {1:s}", FrameCount,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.encoded:          {0:s} {1:s}",
                                    Encoded.ToString(AppSettings.CInfo), Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.isRawStream:      {0:s} {1:s}",
                                    IsRawStream.ToString(AppSettings.CInfo), Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.StreamSize:       {0:g} {1:s}", StreamSize,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.Length:           {0:g} {1:s}", Length,
                                    Environment.NewLine);
            result += string.Format(AppSettings.CInfo, "VideoInfo.AspectRatio:      {0:g} {1:s}", AspectRatio,
                                    Environment.NewLine);
            return(result);
        }
示例#20
0
        /// <summary>
        /// Get a hash representing the standard identifier for this format.
        /// Currently supported are the DVD/Bluray Disc ID and the OpenSubtitles.org Movie Hash.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="videoPath">path to the main video file</param>
        /// <returns>Hexadecimal string representing the identifier or NULL</returns>
        public static string GetIdentifier(this VideoFormat self, string videoPath)
        {
            string hashID = null;

            if (self == VideoFormat.DVD)
            {
                // get the path to the video_ts folder
                string vtsPath = videoPath.ToLower().Replace(@"\video_ts.ifo", @"\");
                // This will get the microsoft generated DVD Disc ID
                try {
                    // get the disc id using the DirectShowLib method
                    IDvdInfo2 dvdInfo = (IDvdInfo2) new DVDNavigator();
                    long      discID  = 0;
                    dvdInfo.GetDiscID(vtsPath, out discID);
                    // if we got a disc id, we convert it to a hexadecimal string
                    if (discID != 0)
                    {
                        hashID = Convert.ToString(discID, 16);
                    }
                }
                catch (Exception e) {
                    if (e.GetType() == typeof(ThreadAbortException))
                    {
                        throw e;
                    }

                    logger.DebugException("Disc ID: Failed, Path='" + vtsPath + "', Format='" + self.ToString() + "' ", e);
                }
            }
            else if (self == VideoFormat.Bluray)
            {
                // Standard for the Bluray Disc ID is to compute a SHA1 hash from the key file (will only work for retail disks)
                string path = videoPath.ToLower();
                if (path.EndsWith(@"bdmv\index.bdmv"))
                {
                    string keyFilePath = path.Replace(@"bdmv\index.bdmv", @"AACS\Unit_Key_RO.inf");
                    if (File.Exists(keyFilePath))
                    {
                        FileInfo keyFile = new FileInfo(keyFilePath);
                        hashID = keyFile.ComputeSHA1Hash();
                    }
                    else if (File.Exists(videoPath))
                    {
                        hashID = string.Empty;
                    }
                }
            }
            else if (self == VideoFormat.File)
            {
                FileInfo file = new FileInfo(videoPath);
                hashID = file.ComputeSmartHash();
            }

            // Log the result
            if (String.IsNullOrEmpty(hashID))
            {
                logger.Debug("Failed Identifier: Path='{0}', Format='{1}' ", videoPath, self);
            }
            else
            {
                logger.Debug("Identifier: Path='{0}', Format='{1}', Hash='{2}' ", videoPath, self, hashID);
            }

            // Return the result
            return(hashID);
        }
示例#21
0
        public static string ToFormatString(this VideoFormat format)
        {
            switch (format)
            {
            case VideoFormat.Rgbx:
                return("RGBx");

            case VideoFormat.Bgrx:
                return("BGRx");

            case VideoFormat.Xrgb:
                return("xRGB");

            case VideoFormat.Xbgr:
                return("xBGR");

            case VideoFormat.Gray16Be:
                return("GRAY16_BE");

            case VideoFormat.Gray16Le:
                return("GRAY16_LE");

            case VideoFormat.V308:
                return("v308");

            case VideoFormat.R210:
                return("r210");

            case VideoFormat.I42010be:
                return("I420_10BE");

            case VideoFormat.I42010le:
                return("I420_10LE");

            case VideoFormat.I42210be:
                return("I422_10BE");

            case VideoFormat.I42210le:
                return("I422_10LE");

            case VideoFormat.Y44410be:
                return("I444_10BE");

            case VideoFormat.Y44410le:
                return("I444_10LE");

            case VideoFormat.Gbr10be:
                return("GBR_10BE");

            case VideoFormat.Gbr10le:
                return("GBR_10LE");

            case VideoFormat.Nv1264z32:
                return("NV12_64Z32");

            case VideoFormat.A42010be:
                return("A420_10BE");

            case VideoFormat.A42010le:
                return("A420_10LE");

            case VideoFormat.A42210be:
                return("A422_10BE");

            case VideoFormat.A42210le:
                return("A422_10LE");

            case VideoFormat.A44410be:
                return("A444_10BE");

            case VideoFormat.A44410le:
                return("A444_10LE");

            case VideoFormat.P01010be:
                return("P010_10BE");

            case VideoFormat.P01010le:
                return("P010_10LE");

            case VideoFormat.Gbra10be:
                return("GBRA_10BE");

            case VideoFormat.Gbra10le:
                return("GBRA_10LE");

            case VideoFormat.Gbr12be:
                return("GBR_12BE");

            case VideoFormat.Gbr12le:
                return("GBR_12LE");

            case VideoFormat.Gbra12be:
                return("GBRA_12BE");

            case VideoFormat.Gbra12le:
                return("GBRA_12LE");

            case VideoFormat.I42012be:
                return("I420_12BE");

            case VideoFormat.I42012le:
                return("I420_12LE");

            case VideoFormat.I42212be:
                return("I422_12BE");

            case VideoFormat.I42212le:
                return("I422_12LE");

            case VideoFormat.Y44412be:
                return("I444_12BE");

            case VideoFormat.Y44412le:
                return("I444_12LE");

            default:
                return(format.ToString().ToUpperInvariant());
            }
        }