powershell - 正则表达式匹配时Powershell卡住了
问题描述
我真的不明白为什么当我匹配正则表达式时,powershell 会卡在这一行。
$failedlist = [regex]::Matches((Get-Content -Path log.txt -raw),"(?m)^-+(?:\r?\n(?!-|Input #\d).*)*\r?\nInput #(?<number>\d+).*?from '(?<filename>[^'\r\n]+)':(?:\r?\n(?!-).*)*\r?\n[Ff]ailed to")
这是log.txt
:
--------------------------------------------------------------------------------
D:\output\123.mp4
--------------------------------------------------------------------------------
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\users\somefolder\123.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: isomiso2avc1mp41mp423gp5
date : 2013-04-20T09:00:01+1000
encoder : Lavf54.59.106
Duration: 00:04:51.83, start: 0.000000, bitrate: 931 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 864x480 [SAR 1:1 DAR 9:5], 802 kb/s, 24.51 fps, 24.51 tbr, 12257 tbn, 49.03 tbc (default)
Metadata:
rotate : 90
handler_name : VideoHandler
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:2(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)
Metadata:
creation_time : 2013-04-29T15:28:49.000000Z
handler_name : GPAC MPEG-4 OD Handler
Stream #0:3(und): Data: none (mp4s / 0x7334706D), 0 kb/s (default)
Metadata:
creation_time : 2013-04-29T15:28:49.000000Z
handler_name : GPAC MPEG-4 Scene Description Handler
Stream #0:4(und): Data: none (rtp / 0x20707472), 39 kb/s (default)
Metadata:
creation_time : 2013-04-29T15:28:49.000000Z
handler_name : GPAC ISO Hint Handler
Stream #0:5(und): Data: none (rtp / 0x20707472), 7 kb/s (default)
Metadata:
creation_time : 2013-04-29T15:28:49.000000Z
handler_name : GPAC ISO Hint Handler
avcuvid: --sub-copy/--vpp-subburn is set, but no subtitle stream found.
Max B frames are 0 frames.
NVEncC (x64) 5.01 (r1507) by rigaya, May 7 2020 12:04:16 (VC 1916/Win/avx2)
OS Version Windows 10 x64 (18363)
CPU Intel Core i7-7700HQ @ 2.80GHz [TB: 3.49GHz] (4C/8T)
GPU #0: GeForce GTX 1080 with Max-Q Design (2560 cores, 1468 MHz)[PCIe3x16][442.19]
NVENC / CUDA NVENC API 9.1, CUDA 10.2, schedule mode: auto
Input Buffers CUDA, 17 frames
Input Info avcuvid: H.264/AVC, 864x480, 25/1 fps
Vpp Filters cspconv(nv12 -> p010)
Output Info H.265/HEVC main10 @ Level auto
864x480p 1:1 25.000fps (25/1fps)
avwriter: hevc, aac => mp4
Encoder Preset default
Rate Control CQP I:23 P:23 B:23
Lookahead off
GOP length 250 frames
B frames 0 frames [ref mode: disabled]
Ref frames 3 frames
AQ off
CU max / min auto / auto
Others mv:auto
Output #0, mp4, to 'D:\Done\123.mp4':
Metadata:
encoding_tool : NVEncC (x64) 5.01
encoder : Lavf58.35.101
Stream #0:0(und): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(progressive), 864x480 [SAR 1:1 DAR 9:5], q=2-31, 200 kb/s, 12800 tbn (default)
Side data:
displaymatrix: rotation of -90.00 degrees
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 75 kb/s (default)
Metadata:
handler_name : SoundHandler
[mp4 @ 00000271e1ac5340] Starting second pass: moving the moov atom to the beginning of the file
encoded 7154 frames, 1251.79 fps, 1080.82 kbps, 36.87 MB
encode time 0:00:05, CPU: 13.4%, GPU: 13.9%, VE: 80.1%, VD: 42.6%, GPUClock: 1648MHz, VEClock: 1479MHz
frame type IDR 29
frame type I 29, avgQP 23.00, total size 0.25 MB
frame type P 7125, avgQP 23.00, total size 36.62 MB
--------------------------------------------------------------------------------
D:\output\456.mp4
--------------------------------------------------------------------------------
[wmv3 @ 0000015b661b7a80] Extra data: 8 bits left, value: 0
Input #0, asf, from 'C:\Users\users\somefolder\456.mp4':
Metadata:
WMFSDKNeeded : 0.0.0.0000
DeviceConformanceTemplate: M1
WM/WMADRCPeakReference: 32767
WM/WMADRCPeakTarget: 32767
WM/WMADRCAverageReference: 6067
WM/WMADRCAverageTarget: 6067
WMFSDKVersion : 11.0.6000.6346
IsVBR : 0
Duration: 00:29:48.19, start: 0.000000, bitrate: 2628 kb/s
Stream #0:0(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 720x480, 2500 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc
Stream #0:1(eng): Audio: wmapro (b[1][0][0] / 0x0162), 48000 Hz, stereo, fltp, 128 kb/s
avcuvid: --sub-copy/--vpp-subburn is set, but no subtitle stream found.
avcuvid: codec wmv3(yuv420p) unable to decode by cuvid.
failed to initialize file reader(s).
Failed to open input file.
该日志由两个视频转换日志组成,由连续虚线分隔。正则表达式将从日志中找到任何失败的转换视频,并将它们放入filename
和number
列。在这种情况下456.mp4
是失败的。但是,如果log.txt
不包含 的日志123.mp4
,powershell 将不会停留在该代码行。知道为什么吗?
编辑:
似乎没有-raw
标志,它没有被卡住,但它不会匹配任何东西。
解决方案
推荐阅读
- ubuntu - 无法通过 SSH、面板和浏览器的 SSH 访问我的 Google Cloud 实例
- php - XCRUD:如何插入 html?
- java - 括号匹配算法java
- java - 使用 Java 13 的 Liquibase:org.hibernate.boot.registry.classloading.spi.ClassLoadingException
- java - 如何使用 JSP 检索整数 URL 参数?
- javascript - 获取角度延迟加载的浏览器模块错误
- javascript - 根据选择的多个选项重定向到不同的页面
- mongodb - Mongodb如何强制执行唯一的数据库参考ID?
- xpath - Scrapy如何在for循环中使用xpaths
- nsis - NSIS错误安装位置