Reputation: 404
Target: capture rtsp stream with sound from intercom camera and save it as 1hour duration video
URL for rtsp stream is updаting every 2 minutes, but i need to get parts with 1hour duration. So i see only solution to concatenate 2 minutes videos. It's required time between capturing stream parts to get response from server and reconnect with another url
First i tried opencv
. It's not working with sound
Then i started using ffmpeg
:
Capturing stream:
ffmpeg -rtsp_transport tcp -i <rtsp_url> 2min_part.mp4
ffmpeg -safe 0 -f concat -i parts_list.txt -c copy concatenated_1.mp4
in stdout getting Non-monotonous DTS in output stream
:
[mp4 @ 0x560c12d80bc0] Non-monotonous DTS in output stream 0:0; previous: 57400952, current: 41462297; changing to 57400953. This may result in incorrect timestamps in the output file.
[mp4 @ 0x560c12d80bc0] Non-monotonous DTS in output stream 0:0; previous: 57400953, current: 41462809; changing to 57400954. This may result in incorrect timestamps in the output file.
[mp4 @ 0x560c12d80bc0] Non-monotonous DTS in output stream 0:0; previous: 57400954, current: 41463321; changing to 57400955. This may result in incorrect timestamps in the output file.
...
After opening video in media players i see that from one second video is stopped, but sound is going on. Interesting part that with every new opening this second (starting from video stops) changes
Then i tried this solution:
ffmpeg -safe 0 -f concat -segment_time_metadata 1 -i parts_list.txt -vf select=concatdec_select -af aselect=concatdec_select,aresample=async=1 concatenated_2.mp4
No Non-monotonous DTS
wаrnings, but video is still corrupted like first. Also this solution requires a lot of CPU while first concatenating method is very fast.
Question: How to do concatenating and get not corrupted video? May be i need to configure capturing options to simply use concatenating with -c copy
?
parts of videos and concatenated
using exiftool concatenated_1.mp4
i see that:
Duration : 1:17:44
Track Duration : 1:17:44
Media Duration : 0:53:59
Upvotes: 0
Views: 545
Reputation: 864
In your particular case, fixing the timestamps (-avoid_negative_ts make_zero
) and setting the same timebase (-video_track_timescale 90000) help to avoid Non-monotonous DTS in output
errors in case of using the concat demuxer. This command does the job without re-encoding (-c copy
):
for f in Подъезд*.mp4; do
num=${f##*_}
num=${num%.*}
num=$(printf "%02d" $num)
ffmpeg -hide_banner -y -i $f \
-avoid_negative_ts make_zero \
-video_track_timescale 90000 \
-c copy \
part_${num}.mp4
done
Then you can use concat demuxer (without any error):
ffmpeg -hide_banner -y \
-f concat -safe 0 \
-i <(for f in part*.mp4; do echo "file '$PWD/$f'"; done) \
-c copy \
output.mp4
Upvotes: 1