无法使用ffmpeg并排同步两个网络摄像头流中的帧

时间:2019-06-15 19:22:16

标签: linux ffmpeg mpeg

我正在尝试使用ffmpeg websocket以sbs模式流式传输两个摄像头。

它可以工作,但是两个场景之间要延迟一秒钟。

这是我的工作:

ffmpeg -f v4l2   -framerate 30 -video_size 1280x720 -input_format mjpeg 
-i /dev/video1 -f v4l2 -framerate 30  -input_format mjpeg 
-video_size 1280x720 -i /dev/video0 -filter_complex "
[0:v][1:v]hstack [left+right]" -map [left+right] -r 30 -fflags nobuffer 
-f mpegts -codec:v mpeg1video -s 2560x720 -b:v 800k -bf 0 http://localhost:8081/secretsecret

这是输出:

ffmpeg version 4.1.3-0ubuntu1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8 (Ubuntu 8.3.0-6ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable- libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, video4linux2,v4l2, from '/dev/video2':
    Duration: N/A, start: 9539.835119, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 25 fps, 25 tbr, 1000k tbn, 1000k tbc
Input #1, video4linux2,v4l2, from '/dev/video4':
  Duration: N/A, start: 9541.474622, bitrate: N/A
    Stream #1:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 25 fps, 25 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 (mjpeg) -> hstack:input0
  Stream #1:0 (mjpeg) -> hstack:input1
  hstack -> Stream #0:0 (mpeg1video)
Press [q] to stop, [?] for help
[swscaler @ 0x55aa2c266f00] deprecated pixel format used, make sure you did set range correctly
Output #0, mpegts, to 'http://localhost:8081/supersecret':
  Metadata:
encoder         : Lavf58.20.100
Stream #0:0: Video: mpeg1video, yuv420p, 2560x720, q=2-31, 800 kb/s, 25 fps, 90k tbn, 25 tbc (default)
Metadata:
  encoder         : Lavc58.35.100 mpeg1video
Side data:
  cpb: bitrate max/min/avg: 0/0/800000 buffer size: 0 vbv_delay: -1
[video4linux2,v4l2 @ 0x55aa2c1d4e40] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)

它可以工作,但是两个屏幕之间有约1秒的延迟。

还尝试了:

ffmpeg -f v4l2 -framerate 25 -video_size 1280x720 -input_format mjpeg -i \
/dev/video2 -f v4l2 -framerate 25  -input_format mjpeg -video_size 1280x720 \
-i /dev/video4 -filter_complex " \
nullsrc=size=2560x720 [background]; \
[0:v] setpts=PTS-STARTPTS, scale=1280x720 [left]; \
[1:v] setpts=PTS-STARTPTS, scale=1280x720 [right]; \
[background][left]       overlay=shortest=1       [background+left]; \
[background+left][right] overlay=shortest=1:x=1280 [left+right] \
" -map [left+right] -f mpegts -codec:v mpeg1video -s 2560x720 -b:v 800k -bf 0     http://localhost:8081/supersecret

但同样的问题.... 我该如何解决?

0 个答案:

没有答案