by rgovostes · 4y ago · 0 comments
Currently I extract the frame at each interesting timestamp and serve them as JPEGs. I have a web-based playback UI that includes a scrubber and list of events to jump to a particular timestamp.
I would love to upgrade to a real video player that streams the underlying video, allowing the user to replay footage surrounding a timestamp. I have to be able to reliably seek to an exact frame from the event list, though.
I've been looking for something web-based, self-hostable, that doesn't require I transcode my media up front (e.g., break down into HLS chunks). I have few users accessing it at a time so I can transcode on the fly with some caching (though I think it is already H.262 or H.264). Is there anything suitable out there?
That said, ffmpeg is going to be the best tool (IMO) to handle this. You may also look at a tool like Vapoursynth or AviSynth if you want to do any sort of preprocessing to the images.
If the video is H.262 (or it is H.264 at a insane bitrate like 50Mbps), I'd encourage transcoding to something not as bitrate heavy. AV1 and HEVC are 2 of the best in class targets (but require a LOT of computational horsepower... OK there is also technically VVC, but nothing really supports that).
If time is of the essence, then I'd suggest looking into what sort of codecs are supported by your CPU/GPU. They won't give you great quality but they will give you very fast transcoding. You'll want to target the latest codec possible.
H.264 is pretty old at this point, H.265 (HEVC) or vp9 will do a better job at a lower bitrate if your card supports either. They are also relatively well supported. VP9 is royalty free.
If your GPU or CPU do not support any recent codec, you might look into the SVT encoders for AV1/VP9, and x264/5 for H.264 or H.265.
All this said, if the codec is fine and at a streamable bitrate, ffmpeg totally supports copying the stream from timeslices. You'll have to play around with buffering some of the stream so you can have ffmpeg do the slicing, but it's not too hard. That's the best option if the stream is streamable (transcoding will always hurt quality).
Oh, and you'll very likely want to compile ffmpeg from source. The version of ffmpeg bundled with your OS is (likely) really old and may not have the encoders you are after. It's a huge PITA, but worth it, IMO. Alternatively you can likely find a build with all the stuff you want... but you'll need a level of trust in the provider of that binary.
For the rest of it, I would suggest an ffmpeg solution on a server. You can have it re-encode just the requested times while encoding to a streaming friendly format. There are JS libraries available that allow you to use HLS in the native <video> tag.