DDVTECH / mistserver

The official mistserver source repository - www.mistserver.com
The Unlicense
383 stars 133 forks source link

[feat] Generate live thumbnail image #210

Open irg1008 opened 1 month ago

irg1008 commented 1 month ago

Hi!, (yes, me again sorry)

Just wondering how could we do this, should ge maybe generate a clip 0.1 seconds long and extract a frame? Maybe is there some sort of better way to do this? Is this possible and I am not aware of it??

Thank you as always

Thulinma commented 1 month ago

Yeah, the newest release (3.4) actually supports this natively. You do, however, need to compile your own build - and specifically set the WITH_AV flag to true. (e.g.: meson setup build -DWITH_AV=true or meson configure BUILD_DIR_HERE -DWITH_AV=true to reconfigure an existing build directory). This enables the native libav (ffmpeg) integration, and adds the new MistProcAV stream process. You can set this process on a live stream and have it generate a JPEG track with an interval of your choice. Requesting STREAMNAME.jpg from the HTTP(S) port(s) will then serve the newest frame from the JPEG track, or requesting STREAMNAME.mjpg will even get you an old-school MJPEG feed (auto-updating image using a long-running HTTP GET request). In addition, you can add the ?start= (and the unix time based variant) parameter to request a frame from a specific point in time.

Without compiling yourself it's also possible: but then you need to provide the binary and command to transcode and use the MistProcMKVExec binary instead. This binary lets you hook up any system to generate practically any track, and if you generate an (M)JPEG track (through any method, e.g. gstreamer, ffmpeg - whatever you may prefer) it will "merge" it back into the original stream and provide the same functionality.

We do plan to write a small tutorial on how to set this all up with examples, but haven't had the time to get around to it yet. 😅

irg1008 commented 1 month ago

Wow you are always two steps ahead hah. By enabling the AV flag: Could I use stream processes with ffmpeg without downloading ffmepg to my custom docker image?

I will try compiling my self but I have seen that doing so generates a bigger image than using binaries directly (even in multisep docker builds)

Rokamun commented 1 month ago

Well... There's sort of been the time for a draft.

https://hedgedoc.ddvtech.com/4YGxESCISkKGMOqpN406lw

This is the first draft I made to note down all the important parts to do this and use this. I've made the quick notes I made somewhat more readable, but it's not a proper guide yet. I also have to add a gstreamer example still. It might give some help however.

You can use MistProcAV without installing FFmpeg, I believe if you compile with the AV option it'll pull in the libraries it'll need to compile the MistProcAV itself, but not the entirety of FFmpeg. Though in all honestly you're probably close to downloading ffmpeg at that point. If I remember correctly you'll at least have almost all the libraries.

You can still reduce the size of everything by stripping the binaries. Removing the debug information does save some space.

irg1008 commented 1 month ago

Okay I made it work with a custom image and geting 800MB image size (yikes). How could I strip the binaries to reduce the size?? I haven't touch meson since college!

Dockerfile:

FROM ubuntu:22.04 as builder

RUN apt-get -y update && apt-get -y install build-essential git python3-pip pkg-config libavutil-dev libavcodec-dev libswscale-dev libavformat-dev
RUN python3 -m pip install meson ninja

RUN git clone https://github.com/DDVTECH/mistserver.git
RUN cd mistserver && git checkout development && meson setup build -DWITH_AV=true --default-library static && cd build && ninja install && meson compile -C .

FROM ubuntu:22.04

COPY --from=builder /mistserver/build /mistserver

RUN apt-get -y update && apt-get -y install curl openssl coreutils

CMD /mistserver/MistController -c /config/config.json
irg1008 commented 1 month ago

I am also not seeing the options on stream processes:

image

Rokamun commented 1 month ago

Hey there,

You're quite close! The current process removes the libraries necessary though! Add the following to your 2nd RUN apt-get: libavutil libavcodec libswscale libavformat You don't need the dev versions, but you do need the libraries themselves in order to run the MistProcAV binary. Since it cannot run without these libraries, it is not detected and not in the list.

"easiest" is to just install ffmpeg, it would 100% install the correct packages. But I also get if that isn't what you want.