python格式化整数

发布于 2025-01-21 19:54:30 字数 411 浏览 2 评论 0原文

这是我从BMD Hyperdeck中获得的请求,它包含SD卡上的视频文件和视频的长度。我需要每个文件的长度,在我的代码列表中分开。这样的方法是什么?

b'206 disk list:\r\nslot id: 1\r\n1: Timecode.mp4 H.264 1080p25 00:01:00:00\r\n2: Video_1.mp4 H.264 1080p25 00:00:09:07\r\n3: Video_2.mp4 H.264 1080p25 00:00:07:04\r\n4: Video_3.mp4 H.264 1080p25 00:00:10:19\r\n5: Video_4.mp4 H.264 1080p25 00:00:04:16\r\n6: Video_5.mp4 H.264 1080p25 00:00:05:21\r\n\r\n'

This is the Request I get from an BMD Hyperdeck, it contains the Video-files on the SD-Cards an the lengths of the Videos. I need the lengths of every file, separate in a List for my Code. What would be the right way to something like this?

b'206 disk list:\r\nslot id: 1\r\n1: Timecode.mp4 H.264 1080p25 00:01:00:00\r\n2: Video_1.mp4 H.264 1080p25 00:00:09:07\r\n3: Video_2.mp4 H.264 1080p25 00:00:07:04\r\n4: Video_3.mp4 H.264 1080p25 00:00:10:19\r\n5: Video_4.mp4 H.264 1080p25 00:00:04:16\r\n6: Video_5.mp4 H.264 1080p25 00:00:05:21\r\n\r\n'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫离伤花 2025-01-28 19:54:30

这可以使用正则表达式和Findall来实现:

import re

a = b"206 disk list:\r\nslot id: 1\r\n1: Timecode.mp4 H.264 1080p25 00:01:00:00\r\n2: Video_1.mp4 H.264 1080p25 00:00:09:07\r\n3: Video_2.mp4 H.264 1080p25 00:00:07:04\r\n4: Video_3.mp4 H.264 1080p25 00:00:10:19\r\n5: Video_4.mp4 H.264 1080p25 00:00:04:16\r\n6: Video_5.mp4 H.264 1080p25 00:00:05:21\r\n\r\n"
str_a = str(a)
length = re.findall(r"[0-9]{2}:[0-9]{2}:[0-9]{2}:[0:9]{2}", str_a)
print(length)

This can be achieved using the regular expressions and findall:

import re

a = b"206 disk list:\r\nslot id: 1\r\n1: Timecode.mp4 H.264 1080p25 00:01:00:00\r\n2: Video_1.mp4 H.264 1080p25 00:00:09:07\r\n3: Video_2.mp4 H.264 1080p25 00:00:07:04\r\n4: Video_3.mp4 H.264 1080p25 00:00:10:19\r\n5: Video_4.mp4 H.264 1080p25 00:00:04:16\r\n6: Video_5.mp4 H.264 1080p25 00:00:05:21\r\n\r\n"
str_a = str(a)
length = re.findall(r"[0-9]{2}:[0-9]{2}:[0-9]{2}:[0:9]{2}", str_a)
print(length)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文