如何从 TS 视频流中截取屏幕截图?

How to make screenshots from TS video stream?

我想每 1 分钟从视频流中截取一次屏幕截图。视频流提供为 m3u8 file:

#EXTM3U
#EXT-X-TARGETDURATION:6
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:112076
#EXT-X-PROGRAM-DATE-TIME:2019-03-19T16:16:53Z
#EXTINF:6.000, 2019/03/19/16/16/53-06000.ts
#EXTINF:6.000, 2019/03/19/16/16/59-06000.ts
#EXTINF:6.000, 2019/03/19/16/17/05-06000.ts
#EXTINF:6.000, 2019/03/19/16/17/11-06000.ts

我找到了一个库来解析它 - https://github.com/globocom/m3u8。但我不明白如何将此 TS 视频流转换为单个 jpeg 文件。 我应该

  1. 下载TS文件
  2. 找到需要的框架
  3. 提取它
  4. 删除ts文件?

我应该使用 OpenCV 还是有更简单的解决方案?

使用 OpenV

我想你可以使用 VLC 来做到这一点。

编辑:看起来与 https://superuser.com/questions/1379361/vlc-and-m3u8-file. 非常相似 以下答案可能不适用于您的文件格式(除非更高版本的 VLC 可以正常工作...)。可能会看看 this question 这可能会给你更多的见解

据我所知,VLC 可以与 TS 一起工作 files/streams


一旦你有一个 TS 文件,你应该能够使用 vlc 来执行你的屏幕截图。

根据this link and to this SO question and answers,可以启动VLC并使其执行屏幕捕获。 而且根据 VLC documentation,这似乎是可能的。

应该在 win/linux/mac 上工作。

我确实已经测试过了,我需要连接到我的个人电脑才能进行测试。

引用:

With new VLC versions (VLC 1.1.0 and above), the thumbnails are generated with scene video filter

vlc C:\video\to\process.mp4 --rate=1 --video-filter=scene --vout=dummy --start-time=10 --stop-time=11 --scene-format=png --scene-ratio=24 --scene-prefix=snap --scene-path=C:\path\for\snapshots\ vlc://quit

If you want to get rid of the sound you can add "--aout=dummy" next to "--vout=dummy".

For older VLC versions (1.0.0 and below) the same can be done with image output module

vlc C:\video\to\process.mp4 -V image --start-time 0 --stop-time 1 --image-out-format jpg --image-out-ratio 24 --image-out-prefix snap vlc://quit

What it does:

When VLC media player runs it 'plays' the video for one second without actually showing the video on screen, and then quits, leaving us with a file named 'snap000000.jpg', containing an image of the first frame of the video.

这是 ffmpeg 的工作。
要每分钟从 playlist 捕获一帧,您可以使用:

ffmpeg -i "http://cam.l-invest.ru/nagatinskaya4/tracks-v1/index.m3u8" -vf fps=1/60 invest.ru_%04d.jpg -hide_banner

以上将产生:

invest.ru_0001.jpg

invest.ru_0002.jpg

等等...每60″一次


备注:

  1. invest.ru_0002.jpg 是在 invest.ru_0001.jpg 之后恰好 60″ 拍摄的,正如您在右上角的时间戳中所见。

  2. -vf表示ffmpeg使用视频过滤器fps=1/60,所以它会每60″提取一帧(src)。

  3. 如果需要,可以更改输出格式和文件名结构(例如:%Y-%m-%d_%H-%M-%S.jpg). Please check the ffmpeg image2 docs 可用选项。