Reputation: 414
I am using ffmepg to stream via RTSP from a webcam to my server.
This stream comes in at a high resolution (2560 x 1980) at only 2fps.
I want to create two hls streams:
So it's basically that I want one output of the stream in reduced fps and resolution and secondly and output showing only a close up part of the original stream.
I am using the following commands:
sudo ffmpeg \
-fflags nobuffer \
-rtsp_transport tcp \
-i 'rtsp://XXXXXX' \
-timeout 6000000 \
-r 0.5 \
-copyts \
-an \
-hls_flags delete_segments+append_list \
-filter_complex "[0:v]split=2[in1][in2];[in2]crop=640:360:800:600[out2]" \
-map "[in1]" \
-s:v 800x600 -c:v libx264 -preset slower -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 /stream/ \
-segment_list /var/www/website/statisch/stream/index_s1.m3u8 \
/var/www/website/statisch/stream/s1_%d.ts \
-map "[out2]" \
-f segment \
-segment_list_flags live \
-segment_time 3 \
-segment_list_size 3 \
-segment_format mpegts \
-segment_list_type m3u8 \
-segment_list_entry_prefix /stream/ \
-segment_list /var/www/website/statisch/stream/index_s2.m3u8 \
/var/www/website/statisch/stream/s2_%d.ts
My problem is: When I switch from
-map "[out2]" \
-f segment \
to
-map "[out2]" \
-c:v libx264 -preset slower -g 0.5 -sc_threshold 0 \
-f segment \
I would expect that the second output will be at the specified dimensions at 0.5fps.
For the first output I get:
Stream #0:0: Video: h264 (libx264), yuv420p, 800x600, q=-1--1, 0.50 fps, 90k tbn, 0.50 tbc
This is fine. But for the second output I get:
Stream #1:0: Video: h264 (libx264), yuv420p, 640x360, q=-1--1, 90k fps, 90k tbn, 90k tbc
Frame rate very high for a muxer not efficiently supporting it.
More than 1000 frames duplicated
So it seems the conversion is not properly done or my statematens are not parsed as I would expect it. I've been searching for hours for a solution...
Also checking here did not bring me to a solution: https://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs
Any idea?
And by the way: Any idea how to write it nicer?
Upvotes: 0
Views: 1861
Reputation: 5463
Output options are applied per output.
As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file. Exceptions from this rule are the global options (e.g. verbosity level), which should be specified first.
So, the first -r
(and -an
) only applies to the first output. You need to repeat all the common options for each output url.
Upvotes: 2