我正在使用ffmpeg从图像文件创建mjpeg流,并将其写入ffserver的供稿中:
sudo ffmpeg -loop 1 -i fon.jpeg -vcodec mjpeg -f mjpeg http://localhost:8090/feed1.ffm
ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
built on Aug 19 2013 23:10:58 with gcc 4.7 (Debian 4.7.2-5)
configuration:
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
Input #0, image2, from 'fon.jpeg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Output #0, mjpeg, to 'http://localhost:8090/feed1.ffm':
Metadata:
encoder : Lavf55.12.100
Stream #0:0: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> mjpeg)
Press [q] to stop, [?] for help
ffserver配置为
Port 8090
RTSPPort 8594
BindAddress 0.0.0.0
MaxClients 100
MaxBandwidth 20000
NoDaemon
<Feed feed.ffm>
File /tmp/feed.ffm
FileMaxSize 3M
</Feed>
<Stream test.rtsp>
Feed feed.ffm
Format rtsp
VideoCodec mjpeg
VideoFrameRate 30
VideoBufferSize 80000
VideoBitRate 200
VideoQMin 1
VideoQMax 5
VideoSize 1280x720
PreRoll 1
Noaudio
</Stream>
<Stream test.swf>
Feed feed.ffm
Format swf
VideoCodec flv
VideoFrameRate 30
VideoBufferSize 50000
VideoBitRate 100
VideoQMin 1
VideoQMax 5
VideoSize 1280x720
PreRoll 0
Noaudio
</Stream>
然后,我尝试从ffserver检索rtsp流:
ffplay http://localhost:8090/test.rtsp -loglevel debug
avplay version 0.8.5-6:0.8.5-1, Copyright (c) 2003-2012 the Libav developers
built on Jan 13 2013 12:05:48 with gcc 4.7.2
configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra- version='6:0.8.5-1' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
avutil配置:--arch = amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version ='6:0.8.4-1'--libdir =/usr/lib/x86_64-linux-gnu- -prefix =/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir =/usr/lib/x86_64 -linux-gnu --enable-shared --disable-static
avcodec配置:--arch = amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version ='6:0.8.4-1'--libdir =/usr/lib/x86_64-linux-gnu- -prefix =/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir =/usr/lib/x86_64 -linux-gnu --enable-shared --disable-static
avformat配置:--arch = amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version ='6:0.8.4-1'--libdir =/usr/lib/x86_64-linux-gnu- -prefix =/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir =/usr/lib/x86_64 -linux-gnu --enable-shared --disable-static
swscale配置:--arch = amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version ='6:0.8.4-1'--libdir =/usr/lib/x86_64-linux-gnu- -prefix =/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir =/usr/lib/x86_64 -linux-gnu --enable-shared --disable-static
postproc配置:--arch = amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version ='6:0.8.4-1'--libdir =/usr/lib/x86_64-linux-gnu- -prefix =/usr --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir =/usr/lib/x86_64 -linux-gnu --enable-shared --disable-static
libavutil 51. 22. 1 / 51. 22. 1
libavcodec 53. 35. 0 / 53. 35. 0
libavformat 53. 21. 1 / 53. 21. 0
libavdevice 53. 2. 0 / 53. 2. 0
libavfilter 2. 15. 0 / 2. 15. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 52. 0. 0 / 52. 0. 0
http://localhost:8090/test.rtsp: Invalid data found when processing input
那么,如果我用流替代文件时没有问题,那么在此流传输示例中有什么问题呢?
我使用相同的参数9i.e创建一个mjpeg文件。文件是输出而不是流)
sudo ffmpeg -loop 1 -i fon.jpeg -vcodec mjpeg -f mjpeg test.mjpg
ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
built on Aug 19 2013 23:10:58 with gcc 4.7 (Debian 4.7.2-5)
configuration:
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
Input #0, image2, from 'fon.jpeg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Output #0, mjpeg, to 'test.mjpg':
Metadata:
encoder : Lavf55.12.100
Stream #0:0: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> mjpeg)
Press [q] to stop, [?] for help
frame= 36 fps=0.0 q=0.0 size= 888kB time=00:00:01.36 bitrate=5349.2kbits/sframe= 78 fps= 76 q=0.0 size= 1711kB time=00:00:03.04 bitrate=4609.9kbits/sframe= 120 fps= 78 q=0.0 size= 2533kB time=00:00:04.72 bitrate=4396.9kbits/sframe= 161 fps= 79 q=0.0 size= 3336kB time=00:00:06.36 bitrate=4297.5kbits/sframe= 202 fps= 79 q=0.0 size= 4139kB
time=00:00:08.00 bitrate=4238.8kbits/sframe= 243 fps= 79 q=0.0 size= 4943kB
time=00:00:09.64 bitrate=4200.1kbits/sframe= 282 fps= 79 q=0.0 size= 5706kB
time=00:00:11.20 bitrate=4173.9kbits/sframe= 321 fps= 79 q=0.0 size= 6470kB
time=00:00:12.76 bitrate=4154.0kbits/sframe= 358 fps= 78 q=0.0 size= 7195kB
time=00:00:14.24 bitrate=4139.2kbits/sframe= 397 fps= 68 q=0.0 size= 7959kB
time=00:00:15.80 bitrate=4126.6kbits/s
[1]+ Stopped sudo ffmpeg -loop 1 -i fon.jpeg -vcodec mjpeg -f mjpeg test.mjpg
然后,我用ffplay播放此mjpeg文件。播放是正确的,我看不到任何错误或异常。
ffplay test.mjpg
avplay version 0.8.5-6:0.8.5-1, Copyright (c) 2003-2012 the Libav developers
built on Jan 13 2013 12:05:48 with gcc 4.7.2
[mjpeg @ 0x7fc3680008c0] max_analyze_duration reached
[mjpeg @ 0x7fc3680008c0] Estimating duration from bitrate, this may be inaccurate
Input #0, mjpeg, from 'test.mjpg':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: mjpeg, yuvj420p, 1280x720 [PAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1200k tbn, 1200k tbc
[avsink @ 0x7fc360001020] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x7fc360001700] w:1280 h:720 fmt:yuvj420p -> w:1280 h:720 fmt:yuv420p flags:0x4
27.99 A-V: 0.000 s:0.0 aq= 0KB vq= 0KB sq= 0B f=0/0 0/0
那么,ffserver的配置问题是什么,或者可能是ffserver的错误?
UPD。我意识到,我喂的是file1.ffm而不是file.ffm;导致一些ffserver问题:
Mon Sep 9 11:43:20 2013 [ffm @ 0x2110000]Format ffm probed with size=2048 and score=101
Mon Sep 9 11:43:20 2013 Deleting feed file 'feed1.ffm' as stream counts differ (1 != 2)
Mon Sep 9 11:43:20 2013 [AVIOContext @ 0x210d660]Statistics: 4096 bytes read, 0 seeks
Mon Sep 9 11:43:20 2013 [AVIOContext @ 0x210a9a0]Statistics: 0 seeks, 1 writeouts
Mon Sep 9 11:43:20 2013 FFserver started.
Mon Sep 9 11:44:18 2013 File '/feed1.ffm' not found
Mon Sep 9 11:44:18 2013 127.0.0.1 - - [POST] "/feed1.ffm HTTP/1.1" 404 149
设置正确的供稿后,ffmpeg出现了另一个异常:
sudo ffmpeg -loop 1 -i fon.jpeg -vcodec mjpeg -f mjpeg http://localhost:8090/feed.ffm
ffmpeg version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
built on Aug 19 2013 23:10:58 with gcc 4.7 (Debian 4.7.2-5)
configuration:
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
Input #0, image2, from 'fon.jpeg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
Output #0, mjpeg, to 'http://localhost:8090/feed.ffm':
Metadata:
encoder : Lavf55.12.100
Stream #0:0: Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg -> mjpeg)
Press [q] to stop, [?] for help
av_interleaved_write_frame(): Connection reset by peer
尽管ffserver完全没有显示错误:
sudo ffserver -f /etc/ffserver3.conf
ffserver version 2.0 Copyright (c) 2000-2013 the FFmpeg developers
built on Aug 19 2013 23:10:58 with gcc 4.7 (Debian 4.7.2-5)
configuration:
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
Mon Sep 9 12:08:19 2013 FFserver started.
Mon Sep 9 12:08:40 2013 127.0.0.1 - - [POST] "/feed.ffm HTTP/1.1" 200 4096
Mon Sep 9 12:12:28 2013 127.0.0.1 - - [GET] "/ HTTP/1.1" 200 1847
那么,现在有什么问题呢?
最佳答案
简短的答案是:您不能这样做,至少不能那样做。 ffserver
通过查看提要输出名称来确定预期的输入格式。当看到您将数据发送到feed.ffm
时,它将假定为ffm
数据,因此,当libavformat/utils.c
例程avformat_open_input
调用s->iformat->read_header(s)
时,它将在ffm_read_header
中使用libavformat/ffmdec.c
例程:
/* header */
tag = avio_rl32(pb);
if (tag == MKTAG('F', 'F', 'M', '2'))
return ffm2_read_header(s);
if (tag != MKTAG('F', 'F', 'M', '1')) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
在这里,它在JPEG数据的开头看到
<ff><d8><ff><e0>
,看到它不等于FFM2
或FFM1
,并且以“处理输入时发现无效数据”失败,尽管该消息从未显示。我还不能告诉您正确的方法,但是至少现在您知道发生了什么。
关于image-processing - av_interleaved_write_frame(): Connection reset by peer mjpeg : What is wrong with mjpeg stream, ffserver和ffplay?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18689534/