5

我正在使用 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--enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu - -启用-共享--禁用-静态--enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/x86_64-linux-gnu - -启用-共享--禁用-静态

 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

那么,现在的问题是什么?

4

1 回答 1

2

简短的回答是:你不能那样做,至少不能那样做。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;
 }

这里是它<ff><d8><ff><e0>在 JPEG 数据的开头看到的地方,看到它不等于FFM2or FFM1,并且由于“处理输入时发现无效数据”而失败,尽管该消息从未显示。

我还不能告诉你正确的方法,但至少现在你知道发生了什么。

于 2016-12-31T15:18:51.097 回答