ffmpeg:使用RTSP流式传输并同时录制

时间:2017-11-29 15:06:30

标签: ffmpeg streaming

我的目标是将桌面的一部分流式传输到远程计算机,并同时记录发送的流。 选择的流技术是RTSP协议,FFserver作为rtsp服务器。

我已经使用ffmpeg成功完成了流媒体部分,但现在我正在尝试同时录制流。为此,我正在尝试使用这里引用的tee伪复用器: http://trac.ffmpeg.org/wiki/Creating%20multiple%20outputs

https://ffmpeg.org/ffmpeg-formats.html#tee

不幸的是,我在启动以下命令时出现错误消息:

ffmpeg -loglevel debug  -f alsa -ac 2 -thread_queue_size 512 -ar 44100 -i hw:0 \
-f x11grab -framerate 30 -show_region 1 -video_size 800x480 -thread_queue_size 512 -i :0.0 \
-f tee -c:v libx264 -c:a mp3 -pix_fmt yuv422p  -flags +global_header -map 1:v -map 0:a \
"test.mp4|[f=ffm]http://localhost:8000/feed.ffm/"

这是输出:

  ffmpeg version 3.4-1~xenial1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609
  configuration: --prefix=/usr --extra-version='1~xenial1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-nonfree --enable-libfdk-aac --enable-nvenc --enable-libdc1394 --enable-libiec61883 --enable-libopencv --enable-frei0r --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'hw:0':
  Duration: N/A, start: 1512038836.756092, bitrate: 1411 kb/s
    Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Input #1, x11grab, from ':0.0':
  Duration: N/A, start: 1512038836.789836, bitrate: N/A
    Stream #1:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 800x480, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[libx264 @ 0x5621206c0180] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x5621206c0180] profile High 4:2:2, level 3.1, 4:2:2 8-bit
[libx264 @ 0x5621206c0180] 264 - core 148 r2643 5c65704 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[tee @ 0x5621206bef60] Slave '[f=ffm]http://localhost:8000/feed.ffm/': error writing header: Broken pipe
[tee @ 0x5621206bef60] Slave muxer #1 failed, aborting.
Could not write header for output file #0 (incorrect codec parameters ?): 

Broken pipe
Error initializing output stream 0:1 -- 
Conversion failed!

我也试过f = rtsp,没有机会和这个错误信息:

[tee @ 0x559b26ea2f40] Slave '[f=rtsp]http://localhost:8000/feed.ffm/': error writing header: Invalid data found when processing input
[tee @ 0x559b26ea2f40] Slave muxer #1 failed, aborting.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
Error initializing output stream 0:1 -- 

FFserver配置:

<Feed feed.ffm>
   File /tmp/feed.ffm
   FileMaxSize 20M
</Feed>

<Stream test.mp4>
   Feed feed.ffm
   Format rtp
   VideoSize 800x480
   VideoQMin 1
   VideoQMax 25
   VideoFrameRate 30
   VideoBitRate 8000
   VideoCodec libx264
   PixelFormat yuv422p


   #h264 options
   AVOptionVideo flags +global_header
   AVOptionVideo preset ultrafast
   AVOptionVideo crf 25
   AVOptionVideo profile high422
   AVOptionVideo tune zerolatency

   NoAudio
</Stream>

“Slave”[f = ffm] http://localhost:8000/feed.ffm/':错误写入标题:“断管”是关键,但我无法确定我的命令有什么问题。没有T恤,它可以完美地工作。

我做了很多搜索,但还没找到问题,所以我在这里问。

谢谢, Barzou。

0 个答案:

没有答案