Capturando vários streams RTSP simultaneamente em sincronia

5

Eu gostaria de capturar sequências h264 rtsp de até seis câmeras IP simultaneamente e salvá-las em arquivos separados. As câmeras estão conectadas a um switch Gigabit que está conectado ao meu pc. Os vídeos de saída devem ser sincronizados para processamento adicional: os vídeos precisam ter a mesma duração, hora de início, hora de término e taxa de quadros. Eu estou tentando usar o ffmpeg para esta tarefa.

Aparentemente, minhas câmeras IP fornecem saída com uma taxa de quadros variável. Para gravar vários fluxos em full hd simultaneamente, planejo copiar o fluxo primeiro e recodificá-lo para uma taxa de quadros constante posteriormente. Isso requer que o fluxo capturado carregue o registro de data e hora de cada quadro.

Minha primeira tentativa de gravar streams por, digamos, 10 segundos é:

ffmpeg -loglevel verbose -i rtsp://192.168.1.101 -i rtsp://192.168.1.102 \
-map 0:v -vcodec copy -an -t 10 -y out1.mp4 \
-map 1:v -vcodec copy -an -t 10 -y out2.mp4  

Isso deve salvar segundos de dois fluxos em out1.mp4 e out2.mp4, copiando vídeo, descartando áudio, sobrescrevendo se os arquivos existirem. O resultado, no entanto, são dois vídeos com duração diferente, entre 5 e 7 segundos, e não estão sincronizados. Além disso, os vídeos congelam a cada três segundos ou mais. A saída de log (verbose) lê:

ffmpeg version N-50911-g9efcfbe Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 13 2013 21:26:48 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libg
sm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libo
pencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-li
bschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-lib
twolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enabl
e-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    54.  4.100 / 54.  4.100
  libavfilter     3. 45.103 /  3. 45.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[rtsp @ 027698e0] SDP:
v=0
o=StreamingServer 3331435948 1116907222000 IN IP4 192.168.1.101
s=h264.mp4
c=IN IP4 0.0.0.0
t=0 0
a=control:*
m=video 0 RTP/AVP 96
a=control:trackID=0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0KAKNoB4AiTAWoEBARgQAAF9eE
AAC+vCve+Eg==,aM48gA==
m=application 0 RTP/AVP 107
a=control:trackID=2
a=rtpmap:107 vnd.onvif.metadata/90000


[h264 @ 0276c520] Current profile doesn't provide more RBSP data in PPS, skippin
g
[rtsp @ 027698e0] Estimating duration from bitrate, this may be inaccurate
Input #0, rtsp, from 'rtsp://192.168.1.101':
  Metadata:
    title           : h264.mp4
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Baseline), yuv420p, 1920x1088 [SAR 1:1 DAR 30:17],
 30.17 tbr, 90k tbn, 180k tbc
    Stream #0:1: Data: none
[rtsp @ 027682a0] SDP:
v=0
o=StreamingServer 3331435948 1116907222000 IN IP4 192.168.1.102
s=h264.mp4
c=IN IP4 0.0.0.0
t=0 0
a=control:*
m=video 0 RTP/AVP 96
a=control:trackID=0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0KAKNoB4AiTAWoEBARgQAB9AAA
DARlAve+EgA==,aM48gA==
m=application 0 RTP/AVP 107
a=control:trackID=2
a=rtpmap:107 vnd.onvif.metadata/90000


[h264 @ 0495b420] Current profile doesn't provide more RBSP data in PPS, skippin
g
[rtsp @ 027682a0] Estimating duration from bitrate, this may be inaccurate
Input #1, rtsp, from 'rtsp://192.168.1.102':
  Metadata:
    title           : h264.mp4
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: h264 (Baseline), yuv420p, 1920x1088 [SAR 1:1 DAR 30:17],
 30.17 tbr, 90k tbn, 180k tbc
    Stream #1:1: Data: none
Output #0, mp4, to 'out1.mp4':
  Metadata:
    title           : h264.mp4
    encoder         : Lavf55.0.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1088 [SAR 1
:1 DAR 30:17], q=2-31, 90k tbn, 90k tbc
Output #1, mp4, to 'out2.mp4':
  Metadata:
    title           : h264.mp4
    encoder         : Lavf55.0.100
    Stream #1:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1088 [SAR 1
:1 DAR 30:17], q=2-31, 90k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #1:0 (copy)
Press [q] to stop, [?] for help
[NULL @ 0495b420] Current profile doesn't provide more RBSP data in PPS, skippin
g
[NULL @ 0276c520] RTP: missed 362 packets
[NULL @ 0276c520] Current profile doesn't provide more RBSP data in PPS, skippin
g
    Last message repeated 1 times
frame=   44 fps=0.0 q=-1.0 q=-1.0 size=     560kB time=00:00:03.24 bitrate=1412.
frame=   60 fps= 59 q=-1.0 q=-1.0 size=     622kB time=00:00:03.77 bitrate=1350.
Current profile doesn't provide more RBSP data in PPS, skipping
[NULL @ 0276c520] Current profile doesn't provide more RBSP data in PPS, skippin
g
frame=   75 fps= 49 q=-1.0 q=-1.0 size=     813kB time=00:00:04.27 bitrate=1559.
frame=   90 fps= 45 q=-1.0 q=-1.0 size=     877kB time=00:00:04.76 bitrate=1507.
Current profile doesn't provide more RBSP data in PPS, skipping
[NULL @ 0276c520] Current profile doesn't provide more RBSP data in PPS, skippin
g
frame=  106 fps= 42 q=-1.0 q=-1.0 size=    1080kB time=00:00:05.29 bitrate=1669.
frame=  121 fps= 40 q=-1.0 q=-1.0 size=    1142kB time=00:00:05.79 bitrate=1613.
Current profile doesn't provide more RBSP data in PPS, skipping
[NULL @ 0276c520] Current profile doesn't provide more RBSP data in PPS, skippin
g
frame=  136 fps= 38 q=-1.0 q=-1.0 size=    1327kB time=00:00:06.29 bitrate=1727.
Current profile doesn't provide more RBSP data in PPS, skipping
frame=  151 fps= 37 q=-1.0 q=-1.0 size=    1382kB time=00:00:06.78 bitrate=1667.
Current profile doesn't provide more RBSP data in PPS, skipping
frame=  166 fps= 36 q=-1.0 q=-1.0 size=    1574kB time=00:00:07.28 bitrate=1770.
Current profile doesn't provide more RBSP data in PPS, skipping
frame=  182 fps= 36 q=-1.0 q=-1.0 size=    1643kB time=00:00:07.81 bitrate=1722.
Current profile doesn't provide more RBSP data in PPS, skipping
frame=  183 fps= 33 q=-1.0 q=-1.0 size=    1647kB time=00:00:06.49 bitrate=2078.
Current profile doesn't provide more RBSP data in PPS, skipping
frame=  183 fps= 30 q=-1.0 q=-1.0 size=    1647kB time=00:00:06.98 bitrate=1931.
frame=  183 fps= 28 q=-1.0 q=-1.0 size=    1647kB time=00:00:07.48 bitrate=1803.
Current profile doesn't provide more RBSP data in PPS, skipping
frame=  183 fps= 26 q=-1.0 q=-1.0 size=    1647kB time=00:00:07.98 bitrate=1690.
No more output streams to write to, finishing.
frame=  183 fps= 26 q=-1.0 Lq=-1.0 size=    1649kB time=00:00:08.01 bitrate=1685
.8kbits/s
video:3803kB audio:0kB subtitle:0 global headers:0kB muxing overhead -56.630223%

Como posso obter esses fluxos gravados em sincronia?

    
por MartinKS 08.11.2013 / 15:47

1 resposta

1

Eu também sou confrontado com esse problema.

O assincronismo vem do tempo de conexão diferente para as câmeras.

A solução na qual estou trabalhando é usar ffserver para capturar os streams continuamente e transmiti-los em localhost, então você pode usar o ffmpeg para acessar os streams sem atrasos de conexão.

    
por 15.12.2013 / 00:48