[FFmpeg-user] Merge two RTSP inputs into one TS stream
Wu-bin Zhen
vvubin at gmail.com
Thu May 26 20:20:31 CEST 2016
Hello,
I need a TS stream containing two camera angles from two IP encoders
supporting RTSP. Both encoders share the same time by using a local NTP
server.
I used ffmpeg command like "ffmpeg -i rtsp://<encoder1> -i
rtsp://<encoder2> -c copy -y filename.ts", and noticed that the second
track in the ts file is always 2-3 seconds behind. I even tried multiple
tracks with the same encoder as the command and logs below, but still far
away to be synchronized.
Please advise if there is a way to obtain synchronized video tracks from IP
encoders. Thanks!
----------------- command & log ----------------------
$ ffmpeg -v debug -thread_queue_size 512 -rtsp_transport tcp -i rtsp://
192.168.1.20/stream -thread_queue_size 512 -rtsp_transport tcp
-allowed_media_types video -i rtsp://192.168.1.20/stream -map 0 -map 1 -c
copy -t 15 -y twovideotracks.ts
ffmpeg version 3.0.1-static http://johnvansickle.com/ffmpeg/ Copyright (c)
2000-2016 the FFmpeg developers
built with gcc 5.3.1 (Debian 5.3.1-13) 20160323
configuration: --enable-gpl --enable-version3 --enable-static
--disable-debug --enable-libmp3lame --enable-libx264 --enable-libx265
--enable-libwebp --enable-libspeex --enable-libvorbis --enable-libvpx
--enable-libfreetype --enable-fontconfig --enable-libxvid
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora
--enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --enable-libopus
--enable-libass --enable-gnutls --enable-libvidstab --enable-libsoxr
--enable-frei0r --enable-libfribidi --disable-indev=sndio
--disable-outdev=sndio --enable-librtmp --enable-libmfx --enable-libzimg
--cc=gcc
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with
argument 'debug'.
Reading option '-thread_queue_size' ... matched as option
'thread_queue_size' (set the maximum number of queued packets from the
demuxer) with argument '512'.
Reading option '-rtsp_transport' ... matched as AVOption 'rtsp_transport'
with argument 'tcp'.
Reading option '-i' ... matched as input file with argument 'rtsp://
192.168.1.20/stream'.
Reading option '-thread_queue_size' ... matched as option
'thread_queue_size' (set the maximum number of queued packets from the
demuxer) with argument '512'.
Reading option '-rtsp_transport' ... matched as AVOption 'rtsp_transport'
with argument 'tcp'.
Reading option '-allowed_media_types' ... matched as AVOption
'allowed_media_types' with argument 'video'.
Reading option '-i' ... matched as input file with argument 'rtsp://
192.168.1.20/stream'.
Reading option '-map' ... matched as option 'map' (set input stream
mapping) with argument '0'.
Reading option '-map' ... matched as option 'map' (set input stream
mapping) with argument '1'.
Reading option '-c' ... matched as option 'c' (codec name) with argument
'copy'.
Reading option '-t' ... matched as option 't' (record or transcode
"duration" seconds of audio/video) with argument '15'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with
argument '1'.
Reading option 'twovideotracks.ts' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument debug.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file rtsp://192.168.1.20/stream.
Applying option thread_queue_size (set the maximum number of queued packets
from the demuxer) with argument 512.
Successfully parsed a group of options.
Opening an input file: rtsp://192.168.1.20/stream.
[tcp @ 0x4471480] No default whitelist set
[rtsp @ 0x446f600] SDP:
v=0
o=- -2670153692969325330 -2670153692968316012 IN IP4 192.168.1.20
c=IN IP4 0.0.0.0
a=tool: RtpRtspServer
a=range:npt=0-
m=audio 0 RTP/AVP 98
a=rtpmap:98 mpeg4-generic/48000/2
a=fmtp:98 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1190;
SizeLength=13;IndexLength=3; IndexDeltaLength=3; Profile=1;
a=control:rtsp://192.168.1.20:554/stream/trackID=0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96
packetization-mode=1;profile-level-id=42001e;sprop-parameter-sets=Z2QAKK2wpDBSAgFxQWKQPQRWFIYKQEAuKCxSB6CKwpDBSAgFxQWKQPQRTDoUKQNC4oJHMGIemHQoUgaFxQSOYMQ9MOhQpA0LigkcwYh6xEQmIVilsQRWUURJsogxOU4QITKUIEVlCCTYQVhBMJQhMIjGggWQJFaIGBJZBAaEnaMIDwsSWQQKCwsrRBQYOWQweO0YEBZASNAogszlAeAIn5cBEAAAu4AAK/IOAAADA9CQAAA7msr//4wAAAehIAAAdzWV//8K,aP48sA==;
a=control:rtsp://192.168.1.20:554/stream/trackID=1
Failed to parse interval end specification ''
[rtsp @ 0x446f600] audio codec set to: aac
[rtsp @ 0x446f600] audio samplerate set to: 48000
[rtsp @ 0x446f600] audio channels set to: 2
[rtsp @ 0x446f600] video codec set to: h264
[rtsp @ 0x446f600] RTP Packetization Mode: 1
[rtsp @ 0x446f600] RTP Profile IDC: 42 Profile IOP: 0 Level: 1e
[rtsp @ 0x446f600] Extradata set to 0x4475930 (size: 210)
[NULL @ 0x44723a0] setting jitter buffer size to 0
[NULL @ 0x4475280] setting jitter buffer size to 0
[rtsp @ 0x446f600] hello state=0
[h264 @ 0x4475280] Frame num gap 13 8
[h264 @ 0x4475280] Frame num gap 13 9
[h264 @ 0x4475280] Frame num gap 13 10
[h264 @ 0x4475280] Frame num gap 13 11
[rtsp @ 0x446f600] All info found
Input #0, rtsp, from 'rtsp://192.168.1.20/stream':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0, 46, 1/48000: Audio: aac (LC), 48000 Hz, stereo, fltp
Stream #0:1, 29, 1/90000: Video: h264 (High), 4 reference frames,
yuv420p(left), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 1/60, 30 fps, 30
tbr, 90k tbn, 60 tbc
Successfully opened the file.
Parsing a group of options: input file rtsp://192.168.1.20/stream.
Applying option thread_queue_size (set the maximum number of queued packets
from the demuxer) with argument 512.
Successfully parsed a group of options.
Opening an input file: rtsp://192.168.1.20/stream.
[tcp @ 0x44a69c0] No default whitelist set
[rtsp @ 0x44c04e0] SDP:
v=0
o=- -2670153688428557055 -2670153688427642227 IN IP4 192.168.1.20
c=IN IP4 0.0.0.0
a=tool: RtpRtspServer
a=range:npt=0-
m=audio 0 RTP/AVP 98
a=rtpmap:98 mpeg4-generic/48000/2
a=fmtp:98 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1190;
SizeLength=13;IndexLength=3; IndexDeltaLength=3; Profile=1;
a=control:rtsp://192.168.1.20:554/stream/trackID=0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96
packetization-mode=1;profile-level-id=42001e;sprop-parameter-sets=Z2QAKK2wpDBSAgFxQWKQPQRWFIYKQEAuKCxSB6CKwpDBSAgFxQWKQPQRTDoUKQNC4oJHMGIemHQoUgaFxQSOYMQ9MOhQpA0LigkcwYh6xEQmIVilsQRWUURJsogxOU4QITKUIEVlCCTYQVhBMJQhMIjGggWQJFaIGBJZBAaEnaMIDwsSWQQKCwsrRBQYOWQweO0YEBZASNAogszlAeAIn5cBEAAAu4AAK/IOAAADA9CQAAA7msr//4wAAAehIAAAdzWV//8K,aP48sA==;
a=control:rtsp://192.168.1.20:554/stream/trackID=1
Failed to parse interval end specification ''
[rtsp @ 0x44c04e0] video codec set to: h264
[rtsp @ 0x44c04e0] RTP Packetization Mode: 1
[rtsp @ 0x44c04e0] RTP Profile IDC: 42 Profile IOP: 0 Level: 1e
[rtsp @ 0x44c04e0] Extradata set to 0x45e6df0 (size: 210)
[NULL @ 0x44c0e40] setting jitter buffer size to 0
[rtsp @ 0x44c04e0] hello state=0
[rtsp @ 0x44c04e0] All info found
Input #1, rtsp, from 'rtsp://192.168.1.20/stream':
Duration: N/A, start: 0.200000, bitrate: N/A
Stream #1:0, 28, 1/90000: Video: h264 (High), 4 reference frames,
yuv420p(left), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 1/60, 30 fps, 30
tbr, 90k tbn, 60 tbc
Successfully opened the file.
Parsing a group of options: output file twovideotracks.ts.
Applying option map (set input stream mapping) with argument 0.
Applying option map (set input stream mapping) with argument 1.
Applying option c (codec name) with argument copy.
Applying option t (record or transcode "duration" seconds of audio/video)
with argument 15.
Successfully parsed a group of options.
Opening an output file: twovideotracks.ts.
[file @ 0x45e6f20] Setting default whitelist 'file,crypto'
Successfully opened the file.
[mpegts @ 0x44be9c0] muxrate VBR, pcr every 9000 pkts, sdt every 200,
pat/pmt every 40 pkts
Output #0, mpegts, to 'twovideotracks.ts':
Metadata:
encoder : Lavf57.25.100
Stream #0:0, 0, 1/90000: Audio: aac (LC), 48000 Hz, stereo
Stream #0:1, 0, 1/90000: Video: h264, 1 reference frame, yuv420p(left),
1920x1080 (0x0) [SAR 1:1 DAR 16:9], 1/90000, q=2-31, 30 fps, 30 tbr, 90k
tbn, 90k tbc
Stream #0:2, 0, 1/90000: Video: h264, 1 reference frame, yuv420p(left),
1920x1080 (0x0) [SAR 1:1 DAR 16:9], 1/90000, q=2-31, 30 fps, 30 tbr, 90k
tbn, 90k tbc
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Stream #1:0 -> #0:2 (copy)
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per
stream)
Last message repeated 13 times
[mpegts @ 0x44be9c0] Non-monotonous DTS in output stream 0:2; previous: 0,
current: -15000; changing to 1. This may result in incorrect timestamps in
the output file.
[mpegts @ 0x44be9c0] Non-monotonous DTS in output stream 0:2; previous: 1,
current: -12000; changing to 2. This may result in incorrect timestamps in
the output file.
[mpegts @ 0x44be9c0] Non-monotonous DTS in output stream 0:2; previous: 2,
current: -9000; changing to 3. This may result in incorrect timestamps in
the output file.
[mpegts @ 0x44be9c0] Non-monotonous DTS in output stream 0:2; previous: 3,
current: -6000; changing to 4. This may result in incorrect timestamps in
the output file.
[mpegts @ 0x44be9c0] Non-monotonous DTS in output stream 0:2; previous: 4,
current: -3000; changing to 5. This may result in incorrect timestamps in
the output file.
[mpegts @ 0x44be9c0] Non-monotonous DTS in output stream 0:2; previous: 5,
current: 0; changing to 6. This may result in incorrect timestamps in the
output file.
No more output streams to write to, finishing.4kB time=00:00:14.93
bitrate=4500.7kbits/s speed=1.05x
frame= 449 fps= 31 q=-1.0 Lq=-1.0 size= 8240kB time=00:00:15.01
bitrate=4494.6kbits/s speed=1.05x
video:7350kB audio:180kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 9.434474%
Input file #0 (rtsp://192.168.1.20/stream):
Input stream #0:0 (audio): 705 packets read (184612 bytes);
Input stream #0:1 (video): 451 packets read (3718936 bytes);
Total: 1156 packets (3903548 bytes) demuxed
Input file #1 (rtsp://192.168.1.20/stream):
Input stream #1:0 (video): 457 packets read (3824077 bytes);
Total: 457 packets (3824077 bytes) demuxed
Output file #0 (twovideotracks.ts):
Output stream #0:0 (audio): 704 packets muxed (184384 bytes);
Output stream #0:1 (video): 449 packets muxed (3709109 bytes);
Output stream #0:2 (video): 456 packets muxed (3816889 bytes);
Total: 1609 packets (7710382 bytes) muxed
0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x45ecaa0] Statistics: 0 seeks, 1027 writeouts
More information about the ffmpeg-user
mailing list