/// <summary> /// Adds media informations to FileObjects. /// </summary> /// <param name="file">The FileObject processed by InfoDumper.ffInfoDump.</param> /// <returns>The FileObject with processed media informations.</returns> public FileObject mediaDump(FileObject file) { List<string> tracklists = new List<string>(); Match inputInfo = Regex.Match(file.ffInfo, @"Input #\d?, .*\r*\n([\s\S]*)(?:At least one.+)"); file.mediaInfo.mediaStreams = new List<MediaStream>(); file.mediaInfo.inputInfo = inputInfo.Value.Replace("\r",""); file.mediaInfo.duration = Regex.Match(file.mediaInfo.inputInfo, @" Duration\: (\d\d\:\d\d\:\d\d\.\d\d)(.*)").Groups[1].Value; file.mediaInfo.bitratekb = int.Parse(Regex.Match(file.mediaInfo.inputInfo, @"bitrate: (\d+) kb\/s").Groups[1].Value); MatchCollection streams = Regex.Matches(file.mediaInfo.inputInfo, @" Stream #\d?\:\d?(?:(?:\S+)*)\: (.+)\: (.+)\r*\n((?: Metadata:\r*\n(?: .*)*)*)"); foreach (Match stream in streams) { MediaStream mediastream = new MediaStream(); mediastream.mediaType = (MediaType) Enum.Parse(typeof(MediaType), stream.Groups[1].Value, true); mediastream.codecInfo = stream.Groups[2].Value; mediastream.codec = stream.Groups[2].Value.Split(',')[0]; mediastream.metaData = stream.Groups[3].Value; file.mediaInfo.mediaStreams.Add(mediastream); } if (!Config.Configure.includeMediaInfoOnFiles) file.mediaInfo.inputInfo = null; return file; }
/// <summary> /// Deprecated. Adds media informations to FileObjects using FFprobe. /// </summary> /// <param name="file">The FileObject processed by InfoDumper.ffProbeDump.</param> /// <returns>The FileObject with processed media informations.</returns> public FileObject probeMediaDump(FileObject file) { List<string> tracklists = new List<string>(); Match inputInfo = Regex.Match(file.ffInfo, @"Input #\d?, .*\r*\n([\s\S]*)"); file.mediaInfo.mediaStreams = new List<MediaStream>(); file.mediaInfo.inputInfo = file.ffInfo.Replace("\r", ""); //file.mediaInfo.duration = Regex.Match(file.mediaInfo.inputInfo, @" Duration\: (\d\d\:\d\d\:\d\d\.\d\d)(.*)").Groups[1].Value; //file.mediaInfo.bitratekb = int.Parse(Regex.Match(file.mediaInfo.inputInfo, @"bitrate: (\d+) kb\/s").Groups[1].Value); MatchCollection streams = Regex.Matches(file.mediaInfo.inputInfo, @"\[STREAM\]\n([\s\S]+?)\n\[.+STREAM\]"); foreach (Match stream in streams) { MediaStream mediastream = new MediaStream(); mediastream.mediaType = (MediaType)Enum.Parse(typeof(MediaType), Regex.Match(stream.Value, @"codec_type=(.*)").Groups[1].Value, true); mediastream.codecInfo = stream.Groups[1].Value; mediastream.codec = Regex.Match(stream.Value, @"codec_long_name=(.*)").Groups[1].Value; //mediastream.metaData = stream.Groups[3].Value; //to be removed; metadata is no longer provided as is, as ffprobe is used. file.mediaInfo.mediaStreams.Add(mediastream); } return file; }