recording video file with 2 video tracks of two live cams

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

recording video file with 2 video tracks of two live cams

sekret
Hi guys,

I'm new to this mailing list and I just subscribed because for the first time I have a problem with ffmpeg I cannot solve by myself. Hope I'll get some ideas, maybe solutions here.

What I need to do is record a video with 2 video tracks of two live surveillance cameras, connected by ethernet. Both can be accessed with rtsp. The first of the two cameras has a mic connected. The command line I've come up with so far looks like this:

ffmpeg -i "rtsp://$USERNAME:$PASSWORD@192.168.234.34:554" -i "rtsp://$USERNAME:$PASSWORD@192.168.234.33:554" -map 0:0 -map 1:0 -map 0:1 -c copy "$(date +%Y%m%d%H%M%S)".mkv (I don't think I need to explain, right?)

This works very well, both on my Linux laptop (Archlinux) and a Windows 10 desktop. Both have version 4.1.2 of ffmpeg installed.

BUT: The videos aren't in sync. The audio and video of the first camera are perfectly in sync (obviously, since the mic is connected to the first camera), but the second camera's video track is about 1.3 seconds ahead.

So, my questions are:
- Is this command line of mine too primitive for this to work properly?
- Is there a way to sync the video tracks? Maybe to delay the first one by those 1.3 seconds?
- Is there a different approach which potentionally works better?
(- Does maybe one of you guys happen to know a perfectly working software for this?) (I've searched and searched ... It's not a typical use case for surveillance cameras, so no success)

Best
sekret
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: recording video file with 2 video tracks of two live cams

kumowoon1025
> BUT: The videos aren't in sync. The audio and video of the first camera are perfectly in sync (obviously, since the mic is connected to the first camera), but the second camera's video track is about 1.3 seconds ahead.
>
> So, my questions are:
> - Is this command line of mine too primitive for this to work properly?
> - Is there a way to sync the video tracks? Maybe to delay the first one by those 1.3 seconds?
> - Is there a different approach which potentionally works better?
> (- Does maybe one of you guys happen to know a perfectly working software for this?) (I've searched and searched ... It's not a typical use case for surveillance cameras, so no success)

I think the difference comes from which stream connects first and starts receiving packets first, since there’s no reference time to sync both streams to.

Many (most?) devices of this kind also transmit the absolute timestamps separately from the video stream, so if you have the system time synchronized on both cameras, perhaps using ntp, maybe it would be possible to use this information to sync the two streams up but i don’t know if it is possible to do this automatically using ffmpeg alone.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: recording video file with 2 video tracks of two live cams

Carl Eugen Hoyos-2
In reply to this post by sekret
2019-04-10 10:23 GMT+02:00, [hidden email] <[hidden email]>:

> ffmpeg -i "rtsp://$USERNAME:$PASSWORD@192.168.234.34:554"
> -i "rtsp://$USERNAME:$PASSWORD@192.168.234.33:554"
> -map 0:0 -map 1:0 -map 0:1 -c copy
> "$(date +%Y%m%d%H%M%S)".mkv

Complete, uncut console output missing.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: recording video file with 2 video tracks of two live cams

sekret
>Complete, uncut console output missing.

Crap, you're right, thanks for pointing it out! I'll deliver asap, will most probably be there again tomorrow.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: recording video file with 2 video tracks of two live cams

sekret
In reply to this post by Carl Eugen Hoyos-2
>> ffmpeg -i "rtsp://$USERNAME:$PASSWORD@192.168.234.34:554" -i "rtsp://$USERNAME:$PASSWORD@192.168.234.33:554" -map 0:0 -map 1:0 -map 0:1 -c copy "$(date +%Y%m%d%H%M%S)".mkv
>
>Complete, uncut console output missing.

Here's the complete output: https://pastebin.com/Y1ZuMJ2L (run on the Windows 10 machine, where it's supposed to be running once it's perfected)

I've added the options -re and -thread_queue_size 1024 to my first commandline. However the problem of videos out of sync remains, so it's not caused by buffering problems etc. The warnings about circular_buffer_size not being supported don't do any harm, right?

>I think the difference comes from which stream connects first and starts receiving packets first, since there’s no reference time to sync both streams to.
>
>Many (most?) devices of this kind also transmit the absolute timestamps separately from the video stream, so if you have the system time synchronized on both cameras, perhaps using ntp, maybe it would be possible to use this information to sync the two streams up but i don’t know if it is possible to do this automatically using ffmpeg alone.

I'm also pretty sure that this is the reason. Is it perhapt possible to tell ffmpeg to handle both inputs equally, so both start at the same time?

I kinda like the idea of syncing them based on the system time, which, in case it works, should be in sync well enough for this purpose. But I fear implementing this is over my head. Still, I'll keep this in mind in case nothing else works, so Ted, thanks a lot for this idea!

Since I'll run this command by a bat file on this Windows machine (it's supposed to be idiot proof unfortunately), a workaround could be to re-merge the video with mkvmerge and then just delay the second video track. I don't really like this idea all too much, since the length of this delay could e.g. depend on the cpu load when the commandline gets executed.


Hope you guys have even better ideas than me, being kind of an ffmpeg noob to be honest...


Thanks a lot so far!
sekret
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".