[FFmpeg-user] FFMPEG producing multiple outputs (one streaming and one snapshot)
Devin Heitmueller
dheitmueller at kernellabs.com
Sun Sep 8 17:14:34 EEST 2019
Hi Thomas,
On Sun, Sep 8, 2019 at 9:33 AM Thomas Chen <tchen61 at gmail.com> wrote:
>
>
> i am trying to capture video from a camera and produce to two outputs
> 1) streaming (h264)
> 2) taking periodic snapshot of the image (jpg)
>
> is this possible ? i read
> https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs that
> ffmpeg can have multiple outputs but i am not sure how to handle when
> one output is just
> snapshot of image (and triggered by an external signal or a periodic
> timer ?)
Here's a pipeline I've been using in development to stream to Akamai
via HLS push while simultaneously pushing JPGs to a webserver which
hosts thumbnails updated once per second:
ffmpeg -y -i udp://@227.1.1.4:6001?localaddr=192.168.1.200&overrun_nonfatal=1&fifo_size=1048576
-filter_complex
pad=x=-1:y=-2:aspect=16/9:color=yellow,drawtext=fontfile=/home/devin/fonts/DejaVuLGCSans.ttf:text=%{localtime}_%{frame_num}:fontsize=32:x=10:y=200:fontcolor=white:box=1:boxborderw=10:boxcolor=black,split=2[out1][out2],[out1]fps=30000/1001[vid],[out2]fps=1/1[jpg];
aresample -ac 2 -s 320x180 -map [vid] -c:v libx264 -deinterlace
-preset ultrafast -x264-params nal-hrd=cbr -profile:v high -level 4.1
-8x8dct 1 -g 60 -bf 2 -b:v 240k -minrate 240k -maxrate 240k -bufsize
240k -max_muxing_queue_size 1024 -c:a aac -ar 24000 -b:a 32k -f hls
-hls_time 4 -hls_list_size 3 -hls_flags delete_segments -method PUT
-master_pl_publish_rate 15 -hls_start_number_source epoch
https://post.redacted.akamaihd.net/12345678/hls/master_240p.m3u8 -map
[jpg] -s 320x180 -q 8
https://redacteduser@redactedpw:www.redacted.com/thumbupload/upload.php/foo/869618_%03d.jpg
So the pipeline above basically does a single encode, runs it through
a complex filter graph to pad to 16/9 and burn in some text, then
takes the output of that pipeline and routes it to one output where it
gets encoded as H.264/HLS, and the second output encodes as jpeg and
uploads to a webserver. In the above example both outputs are 320x180
but they don't have to be the same resolution (in fact, in many use
cases you might want the H.264 to be higher resolution and the jpeg
image to be a very small thumbnail).
The filter which burns in the text would be removed from the pipeline
in production (but in fact it's *really* helpful when getting the
pipeline up and running). And of course the filter which pads
standard definition video to 16/9 can be removed too if you're just
doing HD content.
So, yes, it can be done, and I hope this gives you a reasonable
starting point to play with.
Devin
--
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
More information about the ffmpeg-user
mailing list