How to continuously output screenshots while also outputting hls with ffmpeg - ffmpeg

So I have the following process of ingesting rtsp and output hls.
ffmpeg -fflags nobuffer \
-rtsp_transport udp \
-i rtsp://<source>/ \
-vsync 0 \
-copyts \
-vcodec copy \
-movflags frag_keyframe+empty_moov \
-an \
-hls_flags delete_segments \
-f segment \
-segment_list_flags live \
-segment_time 1 \
-segment_list_size 5 \
-segment_format mpegts \
-segment_list streaming.m3u8 \
-segment_list_type m3u8 \
-segment_list_entry_prefix ./ \
%d.ts
and I want to also output screenshots from the stream at some fixed frequency. Say every second.
I've tried a variety of options including
-vframes 1 -q:v 10 capture.jpeg
and its not working.
Any suggestions?

ffmpeg -fflags nobuffer \
-rtsp_transport udp \
-i rtsp://<source>/ \
-vsync 0 \
-copyts \
-vcodec copy \
-movflags frag_keyframe+empty_moov \
-an \
-hls_flags delete_segments \
-f segment \
-segment_list_flags live \
-segment_time 1 \
-segment_list_size 5 \
-segment_format mpegts \
-segment_list streaming.m3u8 \
-segment_list_type m3u8 \
-segment_list_entry_prefix ./ \
%d.ts \
-q:v 10 -vf fps=1 output_%03d.jpg

Related

ffmpeg: "Warning: data is not aligned! This can lead to a speed loss"

Using ffmpeg, I get the warning
Warning: data is not aligned! This can lead to a speed loss
In my case, speed an cpu consuption matter.
I found two discussions about that. Both are quite old:
https://ffmpeg.org/pipermail/ffmpeg-user/2017-October/037501.html#:~:text=This%20can%20lead%20to%20a%20speedloss.%20%3E,(i.e.%20may%20be%20slower).
https://superuser.com/questions/728795/new-ffmpeg-swscaler-0xa314080-warning-data-is-not-aligned-this-can-lead
Every cropping and also every rescaling process as well as the placement of the pip is a multiple of 16 in my case. Also the input (2560x1920) meets that criteria.
Here is the code:
/usr/bin/ffmpeg \
-fflags nobuffer \
-rtsp_transport tcp \
-i 'rtsp://XXX' \
-timeout 6000000 \
-r 0.5 \
-copyts \
-an \
-hls_flags delete_segments+append_list \
-filter_complex \
"[0:v]split=2[a][b];\
[a]scale=768:576[c];\
[b]crop=256:272:1008:608,scale=320:240[d];\
[d]pad=w=16+iw:h=16+ih:x=16:y=16:color=#ff78a8[e];\
[c][e]overlay=0+16:0+32[f]" \
-map "[f]" \
-c:v libx264 -preset veryfast -r 0.5 -g 0.5 -sc_threshold 0 \
-f segment \
-segment_list_flags live \
-segment_time 3 \
-segment_list_size 3 \
-segment_format mpegts \
-segment_list_type m3u8 \
-segment_list_entry_prefix /XXX/stream/ \
-segment_list /var/www/video_streaming/XXX/index_4.m3u8 \
/var/www/video_streaming/XXX/stream/s4_%d.ts
Any idea how to fix this?

ffmpeg no audio after filter_complex

Could someone help with the disappeared audio?
video_2.mp4 logo3.mp4 - has audio
ffmpeg -i video_2.mp4 -i logo3.mp4 -filter_complex \
"color=black:s=1920x1080:d=24 \
,format=yuv444p \
,geq='lum=X*255/W: \
cr=128: \
cb=128' \
[alpha]; \
[0:v]scale=1920x1080, setsar=1[0v]; \
[1:v]scale=1920x1080, setpts=PTS-STARTPTS+10/TB, setsar=1[1v]; \
[1v][alpha]alphamerge[1v]; \
[0v][1v]overlay=enable='between(t\,11,14)',format=yuv420p [v]" -map "[v]" -map 1:a \
-an out.mp4
In -map 1:a -an, the -an negates the mapping. Remove it.

Issue restreaming with ffmpeg if source/destination drops

I am using the following command to restream a video stream to another server, but if the source/destination momentarily drops, ffmpeg gives up.
ffmpeg \
-i http://source_stream_ip:port \
-reconnect_at_eof 1 \
-reconnect_streamed 1 \
-y \
-shortest \
-c: libx264 \
-crf:v 22 \
-preset:v fast \
-pix_fmt yuv420p \
-x264opts keyint=10:no-scenecut=1 \
-maxrate:v 256k \
-bufsize:v 512k \
-c:a aac \
-ac 2 \
-b:a 96k \
-maxrate:a 96k \
-bufsize:a 192k \
-f flv \
rtmp://destination_stream_ip:port
I've tried this as a batch command, but it also eventually gives up.
#!/bin/bash
while :
do
ffmpeg \
-i http://source_stream_ip:port \
-reconnect_at_eof 1 \
-reconnect_streamed 1 \
-y \
-shortest \
-c: libx264 \
-crf:v 22 \
-preset:v fast \
-pix_fmt yuv420p \
-x264opts keyint=10:no-scenecut=1 \
-maxrate:v 256k \
-bufsize:v 512k \
-c:a aac \
-ac 2 \
-b:a 96k \
-maxrate:a 96k \
-bufsize:a 192k \
-f flv \
rtmp://destination_stream_ip:port
done
Could anyone recommend an improvement to doing this or even another way of doing this even without ffmpeg by using another command line tool? At the moment it is too unreliable to use on a permanent basis.
Try to add:
-reconnect_on_network_error 1 -reconnect_on_http_error 1
The -reconnect_at_eof and -reconnect_streamed options should be put before -i SOURCE:
ffmpeg \
-reconnect_at_eof 1 \
-reconnect_streamed 1 \
-i http://source_stream_ip:port \
...

How to use FFmpeg to record multiple screens on MacOS?

I wanted to record multiple screens simultaneously on MacOS and store them in a video file.Same as the screenshot below.
I found a command to do this, but need to know the size of each screen.
ffmpeg \
-f avfoundation -pix_fmt uyvy422 -i 1 \
-f avfoundation -pix_fmt uyvy422 -i 2 \
-pix_fmt yuv420p -r 30 -preset ultrafast -b:v 5000k -t 15 \
-filter_complex \
"nullsrc=size=3286x1080 [background]; \
[0:v] setpts=PTS-STARTPTS [left]; \
[1:v] setpts=PTS-STARTPTS [right]; \
[background][left] overlay=shortest=1 [background+left]; \
[background+left][right] overlay=shortest=1:x=1366 [left+right]" \
-map [left+right] out.mp4 -y
Is there a way to record a screen without knowing the size of each screen?
You can do it using the new xstack filter.
Use
ffmpeg \
-f avfoundation -pix_fmt uyvy422 -i 1 \
-f avfoundation -pix_fmt uyvy422 -i 2 \
-filter_complex \
[0:v] setpts=PTS-STARTPTS [left]; \
[1:v] setpts=PTS-STARTPTS [right]; \
[left][right] xstack=inputs=2:layout=0_0|w0_0 [left+right]" \
-map [left+right] -pix_fmt yuv420p -r 30 -preset ultrafast -b:v 5000k -t 15 \ out.mp4 -y
Get the latest dated build from https://ffmpeg.zeranoe.com/builds/macos64/static/

FFMpeg : Add audio stream via -filter_complex

In Reference to https://superuser.com/questions/833232/create-video-with-5-images-with-fadein-out-effect-in-ffmpeg
I have a bunch of images. and I want to make a video using these images.
Below is my code for FFMpeg. But the problem is how can I append an audio file to -filter_complex (with bitrate)
ffmpeg \
-loop 1 -i input0.png \
-loop 1 -i input1.png \
-loop 1 -i input2.png \
-loop 1 -i input3.png \
-loop 1 -i input4.png \
-filter_complex \
"[0:v]trim=duration=15,fade=t=out:st=14.5:d=0.5[v0]; \
[1:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v1]; \
[2:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v2]; \
[3:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v3]; \
[4:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v4]; \
[v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4

Resources