Ejemplo n.º 1
0
    private static bool GetIdetInfoFromText(string text, out FfMpegIdetInfo idetInfo)
    {
        if (string.IsNullOrEmpty(text))
        {
            throw new ArgumentNullException(nameof(text));
        }

        // Init
        idetInfo = new FfMpegIdetInfo();

        // Parse the text
        try
        {
            // Example:
            // frame= 2048 fps=294 q=-0.0 Lsize= 6220800kB time=00:01:21.92 bitrate=622080.0kbits/s speed=11.8x
            // video:6220800kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
            // [Parsed_idet_0 @ 00000234e42d0440] Repeated Fields: Neither:  2049 Top:     0 Bottom:     0
            // [Parsed_idet_0 @ 00000234e42d0440] Single frame detection: TFF:     0 BFF:     0 Progressive:  1745 Undetermined:   304
            // [Parsed_idet_0 @ 00000234e42d0440] Multi frame detection: TFF:     0 BFF:     0 Progressive:  2021 Undetermined:    28

            // Pattern
            const string repeatedFields = @"\[Parsed_idet_0\ \@\ (.*?)\]\ Repeated\ Fields:\ Neither:(?<repeated_neither>.*?)Top:(?<repeated_top>.*?)Bottom:(?<repeated_bottom>.*?)$";
            const string singleFrame    = @"\[Parsed_idet_0\ \@\ (.*?)\]\ Single\ frame\ detection:\ TFF:(?<single_tff>.*?)BFF:(?<single_bff>.*?)Progressive:(?<single_prog>.*?)Undetermined:(?<single_und>.*?)$";
            const string multiFrame     = @"\[Parsed_idet_0\ \@\ (.*?)\]\ Multi\ frame\ detection:\ TFF:(?<multi_tff>.*?)BFF:(?<multi_bff>.*?)Progressive:(?<multi_prog>.*?)Undetermined:(?<multi_und>.*?)$";

            // We need to match in LF not CRLF mode else $ does not work as expected
            const string pattern = $"{repeatedFields}\n{singleFrame}\n{multiFrame}";
            string       textLf  = text.Replace("\r\n", "\n", StringComparison.Ordinal);

            // Match
            Regex regex = new(pattern, RegexOptions.Multiline | RegexOptions.IgnoreCase);
            Match match = regex.Match(textLf);
            Debug.Assert(match.Success);

            // Get the frame counts
            idetInfo.RepeatedFields.Neither = int.Parse(match.Groups["repeated_neither"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.RepeatedFields.Top     = int.Parse(match.Groups["repeated_top"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.RepeatedFields.Bottom  = int.Parse(match.Groups["repeated_bottom"].Value.Trim(), CultureInfo.InvariantCulture);

            idetInfo.SingleFrame.Tff          = int.Parse(match.Groups["single_tff"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.SingleFrame.Bff          = int.Parse(match.Groups["single_bff"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.SingleFrame.Progressive  = int.Parse(match.Groups["single_prog"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.SingleFrame.Undetermined = int.Parse(match.Groups["single_und"].Value.Trim(), CultureInfo.InvariantCulture);

            idetInfo.MultiFrame.Tff          = int.Parse(match.Groups["multi_tff"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.MultiFrame.Bff          = int.Parse(match.Groups["multi_bff"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.MultiFrame.Progressive  = int.Parse(match.Groups["multi_prog"].Value.Trim(), CultureInfo.InvariantCulture);
            idetInfo.MultiFrame.Undetermined = int.Parse(match.Groups["multi_und"].Value.Trim(), CultureInfo.InvariantCulture);
        }
        catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name))
        {
            return(false);
        }
        return(true);
    }
Ejemplo n.º 2
0
 public bool GetIdetInfo(string filename, out FfMpegIdetInfo idetInfo)
 {
     idetInfo = null;
     return(GetIdetInfoText(filename, out string text) &&
            GetIdetInfoFromText(text, out idetInfo));
 }