Extract a single frame with FFMPEG?
Rick Murray (539) 13384 posts |
How would I extract a single frame from an rtsp stream and save it using FFMPEG, with FFMPEG then quitting? I have tried… *FFmpeg:ffmpeg -y -i rtsp://[USER]:[PASS]@[IPADDRESS]:554/live/ch0 -ss 00:00:01.500 -f image2 -vframes 1 image/jpg …and FFMPEG is doing something (as evidenced by the network light blinking a lot), but nothing appears to happen until I give up (a minute or so later) and press Esc; and there’s no output… Can the RISC OS version of FFMPEG do this? I’ve also tried |
Rick Murray (539) 13384 posts |
After two minutes of thinking, the -msgout option reported: [rtsp @ 0xd66a20] Estimating duration from bitrate, this may be inaccurate Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 1000.00 (1000/1) Input #0, rtsp, from 'rtsp://[USER]:[PASS]@[IPADDRESS]:554/live/ch0': Metadata: title : hysxrtpsion Duration: N/A, start: 0.481000, bitrate: N/A Stream #0.0: Video: h264, yuv420p, 1280x720, 1k tbr, 90k tbn, 180k tbc Stream #0.1: Data: [0][0][0][0] / 0x0000 |
Rick Murray (539) 13384 posts |
Hmm, it DOES work. It just takes two and a half minutes (!) to retrieve a single frame. *Time Sat,15 Jul 2017.20:11:06 *ffmpeg:ffmpeg -y -i rtsp://[USER]:[PASS]@[IPADDRESS]:554/live/ch0 -vframes 1 $.hdipcam/png [rtsp @ 0xd66a20] Estimating duration from bitrate, this may be inaccurate Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 1000.00 (1000/1) Input #0, rtsp, from 'rtsp://[USER]:[PASS]@[IPADDRESS]:554/live/ch0': Metadata: title : hysxrtpsion Duration: N/A, start: 0.545000, bitrate: N/A Stream #0.0: Video: h264, yuv420p, 1280x720, 1k tbr, 90k tbn, 180k tbc Stream #0.1: Data: [0][0][0][0] / 0x0000 [buffer @ 0x14cb340] w:1280 h:720 pixfmt:yuv420p [ffsink @ 0x14dc7f0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out' [scale @ 0x14ddf50] w:1280 h:720 fmt:yuv420p -> w:1280 h:720 fmt:rgb24 flags:0x4 [swscaler @ 0xddd420] No accelerated colorspace conversion found from yuv420p to rgb24. Output #0, image2, to '/hdipcam.png': Metadata: title : hysxrtpsion encoder : Lavf52.93.0 Stream #0.0: Video: png, rgb24, 1280x720, q=2-31, 200 kb/s, 90k tbn, 1k tbc Stream mapping: Stream #0.0 -> #0.0 Press [q] to stop encoding frame= 1 fps= 0 q=0.0 Lsize= -0kB time=0.01 bitrate= -17.6kbits/s dup=1325 drop=0 video:828kB audio:0kB global headers:0kB muxing overhead -100.002595% *Time Sat,15 Jul 2017.20:13:34 * Hmmm… [takes about 2m20s to get from *command to most of the output, and a further ~10s to convert the video frame to PNG] |
Chris Evans (457) 1614 posts |
I know almost nothing about this but IIRC many/most compressed video streams are an initial frame followed by differences. Though from some corruption I sometimes see on the TV if you jump in partway through it looks like it normally sorts itself out within a few seconds. So maybe the software has to decode a minimum of say five seconds worth? |
Rick Murray (539) 13384 posts |
Yes – but it’s a waste of time trying to decode P or B frames – there’s no reference point. Better to just chuck the data away until the next I-frame (wiki explanation).
I frames ought to be sent around once every half second or so? Or are they doing it less in the UK now to squeeze more into less bandwidth? It still seems excessive to take a mite over two minutes to even identify what sort of data it is (and then ~10-15 seconds to grab a frame). |
Chris Evans (457) 1614 posts |
Thanks Rick. I’m suitable enlightened! |