Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have ffmpeg/ffserver running in the following setup:

10.1.2.2 captures from video capture cards (16 channels) and streams them to an ffserver as mpeg1video

10.1.1.1/10.1.2.1 (two NICs) hosts the ffserver and some processes that convert the mpeg1video streams into webm streams along with zoneminder (feeding off the original ffmpeg streams). 10.1.2.2 and 10.1.2.1 are connected via gigabit crossover cable. The /tmp director is mounted as 128MB of RAM via tmpfs.

The mpeg1video stream is always delayed about 0.1-0.2 seconds behind the webm stream, this is perfectly acceptable to me (but I mention it because it might be useful to know for troubleshooting purposes).

When restarted all streams are delayed by 3-5 seconds (I would like to cut this delay down - I can view any individual stream directly from the video device live, so it might be that I'm getting these in the wrong format, except for the compounding delay). When run overnight the streams still appear "live" (fluid motion) in both mpeg1video and webm formats, but are clearly delayed by 4-5 HOURS (as evident by the fact the lights appeared to my amazement to be off when I came in this morning, and kept the screens up watching them until 4-5 hours after people started to come in that morning the lights came on [but not all together, they appear to get out of sync from one another as well]).

These are the processes I'm using:

On 10.1.2.2:

ffmpeg -f video4linux2 -standard ntsc -i /dev/video0 http://10.1.2.1:8090/0.ffm

On 10.1.2.1/10.1.1.15:

ffserver -f /etc/ffserver.conf
ffmpeg -f mpegvideo -i http://localhost:8090/0.mpg -vcodec libvpx http://localhost:8090/0_webm.ffm

And an excerpt from /etc/ffserver.conf on 10.1.2.1/10.1.1.15:

Port 8090
MaxHTTPConnections 2000
MAXClients 100
MaxBandwidth 1000000
CustomLog /var/log/ffserver
NoDaemon

<Feed 0.ffm>
File /tmp/0.ffm
FileMaxSize 1M
ACL allow 10.1.2.2
</Feed>

<Feed 0_webm.ffm>
File /tmp/0_webm.ffm
FileMaxSize 1M
ACL allow localhost
</Feed>

<Stream 0.mpg>
Feed 0.ffm
Format mpeg1video
NoAudio
VideoFrameRate 29.97
VideoBitRate 512K
VideoSize 320x240
VideoBufferSize 40
VideoGopSize 12
#VideoIntraOnly
</Stream>

<Stream 0.webm>
Feed 0_webm.ffm
Format webm
NoAudio
VideoCodec libvpx
VideoSize 320x240
VideoFrameRate 29.97
AVOptionVideo flags +global_header
AVOptionVideo cpu-used 0
AVOptionVideo quality good
PreRoll 0
StartSendOnKey
VideoGopSize 12
VideoBitRate 256
</Stream>

Now, 1MB is far too small to hold 4-5 hours of streaming video at 29.97 FPS and 320x240 resolution in yuv420p color - so my questions is, what is going on here and how do I fix it? To me is seems like something taking place within the initial ffmpeg process on 10.1.2.2, but I can't figure out what, does ffmpeg use some buffer of it's own or is there perhaps a command I can use to force it to drop any excessive frames when pulling from the video card - that is just to take a snapshot as quickly as it can and send from a single-image buffer to ffserver to ensure what is being sent is always live?

My goal here is a live stream feeding into zoneminder and a live stream output in webm format for each of the 16 channels (0-15) - so I am open to any solution but would prefer something based around ffmpeg/ffserver because they seem to be the gold-standard within Linux for tasks like this.

The initial delay of 3-5 seconds and the 4-5 hour delay may be different issues as well. When I kill 10.1.2.2 via "sudo reboot" it takes 3-5 seconds for the individual mpg/webm streams to cut out coming from 10.1.1.15, so it seems there is some buffering taking place within ffserver that goes beyond simply relaying the streams.

Edit: tried reducing all the feed FileMaxSize's to 30K and the 3-5 second delay is still present in all the streams. The same delay exists whether there are 16 or just 1 ffmpeg processes on 10.1.2.2.

Log outputs:

Server:

sudo ffserver -f /etc/ffserver.conf -d

ffserver version git-2013-03-15-cd5f50a Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 15 2013 14:03:16 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 45.104 /  3. 45.104
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Thu Mar 21 14:08:53 2013 FFserver started.
Thu Mar 21 14:08:57 2013 10.1.3.2 - - New connection: GET /15.ffm
Thu Mar 21 14:08:57 2013 10.1.3.2 - - [GET] "/15.ffm HTTP/1.1" 200 4175
Thu Mar 21 14:08:57 2013 10.1.3.2 - - New connection: POST /15.ffm
Thu Mar 21 14:09:03 2013 127.0.0.1 - - New connection: GET /15.mpg
Thu Mar 21 14:09:06 2013 127.0.0.1 - - New connection: GET /15_webm.ffm
Thu Mar 21 14:09:06 2013 127.0.0.1 - - [GET] "/15_webm.ffm HTTP/1.1" 200 4175

sudo ffmpeg -f video4linux2 -standard ntsc -i /dev/video7 http://10.1.3.1:8090/15.ffm

video device --> mpg

ffmpeg version git-2013-03-21-4331484 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 20 2013 20:44:06 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 22.100 / 52. 22.100
  libavcodec     55.  1.100 / 55.  1.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 48.100 /  3. 48.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[video4linux2,v4l2 @ 0xa1d34c0] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video7':
  Duration: N/A, start: 1363889339.048888, bitrate: 27620 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240, 27620 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
Output #0, ffm, to 'http://10.1.3.1:8090/15.ffm':
  Metadata:
    creation_time   : now
    encoder         : Lavf55.0.100
    Stream #0:0: Video: mpeg1video, yuv420p, 320x240, q=2-31, 512 kb/s, 1000k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> mpeg1video)
Press [q] to stop, [?] for help
frame= 3552 fps= 30 q=5.5 size=    7644kB time=00:01:58.45 bitrate= 528.7kbits/s

ffmpeg -f mpegvideo -i http://localhost:8090/15.mpg -vcodec libvpx http://localhost:8090/15_webm.ffm

mpg --> webm

ffmpeg version git-2013-03-15-cd5f50a Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 15 2013 14:03:16 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 45.104 /  3. 45.104
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mpeg1video @ 0x3901000] 0x0 is invalid
    Last message repeated 2 times
[mpegvideo @ 0x38f4f80] max_analyze_duration 5000000 reached at 5011633 microseconds
[mpegvideo @ 0x38f4f80] Estimating duration from bitrate, this may be inaccurate
Input #0, mpegvideo, from 'http://localhost:8090/15.mpg':
  Duration: N/A, bitrate: 1024 kb/s
    Stream #0:0: Video: mpeg1video, yuv420p, 320x240 [SAR 1:1 DAR 4:3], 1024 kb/s, 29.92 fps, 29.97 tbr, 1200k tbn, 29.97 tbc
[libvpx @ 0x39046a0] v1.2.0
Output #0, ffm, to 'http://localhost:8090/15_webm.ffm':
  Metadata:
    creation_time   : now
    encoder         : Lavf55.0.100
    Stream #0:0: Video: vp8, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=1-31, 128 kb/s, 1000k tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg1video -> libvpx)
Press [q] to stop, [?] for help
frame= 4845 fps= 31 q=0.0 size=    4192kB time=00:02:41.66 bitrate= 212.4kbits/s dup=4 drop=0

Adding more output per request:

$v4l
No command 'v4l' found, did you mean:
 Command 'vl' from package 'atfs' (universe)
 Command 'dv4l' from package 'dv4l' (universe)
v4l: command not found

$v4l2
No command 'v4l2' found, did you mean:
 Command 'qv4l2' from package 'qv4l2' (universe)
v4l2: command not found

$ sudo ffprobe -show_streams -show_format -f video4linux2 /dev/video0
ffprobe version git-2013-03-16-c9a51c2 Copyright (c) 2007-2013 the FFmpeg developers
  built on Mar 16 2013 18:48:40 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-libass --enable-libfaac --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libspeex --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 47.100 /  3. 47.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[video4linux2,v4l2 @ 0xb0a0540] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 1364261173.317100, bitrate: 27620 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240, 27620 kb/s, 29.97 fps, 29.97 tbr, 1000k tbn, 1000k tbc
[STREAM]
index=0
codec_name=rawvideo
codec_long_name=raw video
profile=unknown
codec_type=video
codec_time_base=1/1000000
codec_tag_string=I420
codec_tag=0x30323449
width=320
height=240
has_b_frames=0
sample_aspect_ratio=0:1
display_aspect_ratio=0:1
pix_fmt=yuv420p
level=-99
timecode=N/A
id=N/A
r_frame_rate=30000/1001
avg_frame_rate=30000/1001
time_base=1/1000000
start_pts=1364261173317100
start_time=1364261173.317100
duration_ts=N/A
duration=N/A
bit_rate=27620379
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
[/STREAM]
[FORMAT]
filename=/dev/video0
nb_streams=1
format_name=video4linux2,v4l2
format_long_name=Video4Linux2 device grab
start_time=1364261173.317100
duration=N/A
size=N/A
bit_rate=27620379
[/FORMAT]

Video capture cards are both bt878a 8-channel using the bttv driver with a /etc/modprobe.d/bttv.conf setup as follows per the manufacturer's instructions on each of the two machines containing the cards:

options i2c-algo-bit_test=1
options bttv gbuffers=16 card=102,102,102,102,102,102,102,102 radio=0,0,0,0,0,0,0,0 tuner=4,4,4,4,4,4,4,4 chroma_agc=1 combfilter=2 full_luma_range=1 coring=1 autoload=0

On the local machines using:

ffplay -f video4linux2 -standard ntsc -i /dev/video0

Works in real-time and doesn't appear to accrue latency no matter how long it runs.

share|improve this question
1  
Did you try the -r command line option for 10.1.2.2, e.g. ffmpeg -f video4linux2 -standard ntsc -i /dev/video0 -r 29.97 http://10.1.2.1:8090/0.ffm? –  alldayremix Mar 20 '13 at 16:17
    
Yeah, I tried -r -b -s and -vcodec, the effect was the same in each case. –  CoryG Mar 20 '13 at 16:57
1  
Can you run ffmpeg / ffserver with the -d option (debug) and post the output here? –  alldayremix Mar 21 '13 at 17:57
    
Just added them. –  CoryG Mar 21 '13 at 18:13
1  
Those look ok, so let's get more info. What do v4l /dev/video0 and ffprobe -show_streams -show_format -f video4linux2 /dev/video0 give you? –  alldayremix Mar 25 '13 at 15:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.