2

I would like to make screenshots each 1 minutes from the video stream. The video stream is provided as 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

I found a library to parse it - https://github.com/globocom/m3u8. But I don't understand how I can convert this TS video stream to single jpeg file. Am I supposed to

  1. download TS file
  2. find needed frame
  3. extract it
  4. delete ts file?

Should I use OpenCV or is there any easier solution?

use OpenV

LA_
  • 19,823
  • 58
  • 172
  • 308

2 Answers2

5

This is a job for ffmpeg.
To capture a frame from a playlist every minute, you can use:

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

The above will produce:

invest.ru_0001.jpg

invest.ru_0001.jpg

invest.ru_0002.jpg

invest.ru_0002.jpg

and so on... once every 60″


Notes:

  1. invest.ru_0002.jpg was taken exactly 60″ after invest.ru_0001.jpg, as you can see in the upper-right timestamp.

  2. -vf indicates ffmpeg to use a video filter fps=1/60, so it will extract one frame every 60″ (src).

  3. The output format and filename structure can be changed if needed (ex: %Y-%m-%d_%H-%M-%S.jpg). Please check the ffmpeg image2 docs for available options.
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • Thank you! Can I do the same with ffmpeg version 2.0.2? This is the version pre-installed on my old Synology NAS. It doesn't support hide_banner argument and if I remove it, it says `Unable to find a suitable output format for 'invest.ru_%04d.jpg'. invest.ru_%04d.jpg: Invalid argument`. – LA_ Apr 03 '19 at 20:08
  • You're very welcome @LA_. The version of ffmpeg (windows) I used for the answer is **4.1**: `ffmpeg -v ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers`. You can grab the latest version at https://ffmpeg.org/download.html. If possible, use the latest, it should work as expected. – Pedro Lobito Apr 03 '19 at 22:09
  • 1
    I am afraid I can not upgrade built-in utility. Or, if I can, I will have to compile it for my NAS. But anyway - you helped me a lot, many thanks! – LA_ Apr 04 '19 at 06:27
  • `ffmpeg` is very flexible regarding installation, by this I mean that you can compile it from source with just the *plugins* you want, this way it doesn't get heavy on the system, also, because you aren't doing conversion to another format, the cpu load should be insignificant. GL. – Pedro Lobito Apr 04 '19 at 10:02
0

I think you can use VLC to do that.

EDIT: looks very similar to https://superuser.com/questions/1379361/vlc-and-m3u8-file. The following answer might not work for your file format (unless higher versions of VLC work correctly ...). May be have a look to this question which might give you some more insight

To my knowledge, VLC works fines with TS files/streams


Once you have a TS file, you should be able to use vlc to perform your screenshots.

According to this link and to this SO question and answers, one can launch VLC and make it perform screen captures. And according to VLC documentation, it seems possible.

Should work on win/linux/mac.

I do have tested it yet, I need to reach my personal computer to do that.

Quoting:

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.

LoneWanderer
  • 3,058
  • 1
  • 23
  • 41