LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-22-2016, 01:52 PM   #1
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Rep: Reputation: 31
trouble opening ffmpeg stream in browser


I'm trying to stream a live webcam feed from my raspberry pi using ffserver and ffmpeg and a usb webcam (Logitech C615). I know the webcam, the driver, the network connection, etc, are good as I can stream with motion running on the Pi and view the stream in Firefox or Chromium just by going to 192.168.1.115:8081 in the browser.

I know ffserver is working (configured to port 8080) and ffmpeg also works: if I start it with
Code:
ffmpeg -r 15 -s 640x360 -f v4l2 -i /dev/video0 output.mkv
I can view the resulting output.mkv file in vlc media player and it looks fine.

But when I start ffmpeg this way:
Code:
ffmpeg -r 15 -s 640x360 -f v4l2 -i /dev/video0 http://localhost:8080/webcam.ffm
and then put the address in a browser on my desktop 192.168.1.115:8080/webcam.mjpeg the browser just spins "waiting for 192.168.1.115" until I kill ffmpeg on the Pi. Then the browser pops open a dialog offering to open or save the file webcam.mjpeg, but all it saves is an empty text file.

Some more details:
Code:
:~ $ cat /etc/ffserver.conf
HTTPPort 8080
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 20
MaxClients 10
MaxBandwidth 5000
#NoDaemon

<Feed webcam.ffm>
      file /tmp/webcam.ffm
      FileMaxSize 200K
      ACL allow 127.0.0.1
      ACL allow localhost
      ACL allow 192.168.1.0 192.168.1.255
</Feed>

<Stream webcam.mjpeg>
	Feed webcam.ffm
	Format mjpeg
	VideoSize 640x360
	VideoFrameRate 15
	VideoBitRate 2000
	VideoQMin 1
	VideoQMax 10
</Stream>
running ffserver:
Code:
:~ $ ffserver -d -f /etc/ffserver.conf 
ffserver version N-78597-g9dd4dcd Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --enable-libfreetype --enable-gpl --enable-nonfree --enable-libx264 --enable-libass --enable-libmp3lame --bindir=/usr/local/bin
  libavutil      55. 18.100 / 55. 18.100
  libavcodec     57. 24.103 / 57. 24.103
  libavformat    57. 25.101 / 57. 25.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 34.100 /  6. 34.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
/etc/ffserver.conf:26: Setting default value for video bit rate tolerance = 500000. Use NoDefaults to disable it.
/etc/ffserver.conf:26: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
/etc/ffserver.conf:26: Setting default value for video max rate = 31670144. Use NoDefaults to disable it.
/etc/ffserver.conf:26: Setting default value for video buffer size = 4000000. Use NoDefaults to disable it.
Mon Feb 22 14:38:42 2016 FFserver started.
running ffmpeg:
Code:
:~ $ ffmpeg -r 15 -s 640x360 -f v4l2 -i /dev/video0 http://localhost:8080/webcam.ffm
ffmpeg version N-78597-g9dd4dcd Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --enable-libfreetype --enable-gpl --enable-nonfree --enable-libx264 --enable-libass --enable-libmp3lame --bindir=/usr/local/bin
  libavutil      55. 18.100 / 55. 18.100
  libavcodec     57. 24.103 / 57. 24.103
  libavformat    57. 25.101 / 57. 25.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 34.100 /  6. 34.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 249.166926, bitrate: 55296 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x360, 55296 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
[tcp @ 0x20cef60] Connection to tcp://localhost:8080 failed (Connection refused), trying next address
Mon Feb 22 14:46:31 2016 127.0.0.1 - - New connection: GET /webcam.ffm
Mon Feb 22 14:46:31 2016 127.0.0.1 - - [GET] "/webcam.ffm HTTP/1.1" 200 4175
[tcp @ 0x20d1380] Connection to tcp://localhost:8080 failed (Connection refused), trying next address
Mon Feb 22 14:46:31 2016 127.0.0.1 - - New connection: POST /webcam.ffm
[swscaler @ 0x20de0b0] deprecated pixel format used, make sure you did set range correctly
Output #0, ffm, to 'http://localhost:8080/webcam.ffm':
  Metadata:
    creation_time   : 2016-02-22 14:46:31
    encoder         : Lavf57.25.101
    Stream #0:0: Video: mjpeg, yuvj422p(pc), 640x360, q=1-10, 2000 kb/s, 15 fps, 1000k tbn, 15 tbc
    Metadata:
      encoder         : Lavc57.24.103 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 4000000/0/2000000 buffer size: 4000000 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame=    8 fps=0.0 q=18.5 size=     364kB time=00:00:00.53 bitrate=5591.0kbits/frame=   16 fps= 15 q=24.8 size=     660kB time=00:00:01.06 bitrate=5068.8kbits/frame=   24 fps= 15 q=24.8 size=     952kB time=00:00:01.60 bitrate=4874.2kbits/frame=   32 fps= 15 q=24.8 size=    1244kB time=00:00:02.13 bitrate=4777.0kbits/frame=   40 fps= 15 q=24.8 size=    1540kB time=00:00:02.66 bitrate=4730.9kbits/frame=   48 fps= 15 q=24.8 size=    1832kB time=00:00:03.20 bitrate=4689.9kbits/frame=   54 fps= 15 q=24.8 Lsize=    2056kB time=00:00:03.60 bitrate=4678.5kbits/s speed=0.996x    
video:2044kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.611696%
Mon Feb 22 14:46:35 2016 127.0.0.1 - - [POST] "/webcam.ffm HTTP/1.1" 200 2105344
Exiting normally, received signal 2.
(The last 4 lines are after I hit Ctl-C.)

Any ideas - what can be causing the "connection refused" error?
 
Old 02-22-2016, 03:07 PM   #2
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Original Poster
Rep: Reputation: 31
I modified the command to start ffmpeg (changing localhost to 127.0.0.1):
Code:
ffmpeg -r 15 -s 640x360 -f v4l2 -i /dev/video0 http://127.0.0.1:8080/webcam.ffm
Now the "connection refused" errors are gone but browsers are still acting the same way -- unable to show the stream and wanting to download an empty file after ffmpeg is killed.

Here's what the output from ffmpeg looks like when it starts up now:
Code:
~ $ ffmpeg -r 15 -s 640x360 -f v4l2 -i /dev/video0 http://127.0.0.1:8080/webcam.ffm
ffmpeg version N-78597-g9dd4dcd Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --enable-libfreetype --enable-gpl --enable-nonfree --enable-libx264 --enable-libass --enable-libmp3lame --bindir=/usr/local/bin
  libavutil      55. 18.100 / 55. 18.100
  libavcodec     57. 24.103 / 57. 24.103
  libavformat    57. 25.101 / 57. 25.101
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 34.100 /  6. 34.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 4501.838518, bitrate: 55296 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x360, 55296 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
Mon Feb 22 15:57:24 2016 127.0.0.1 - - New connection: GET /webcam.ffm
Mon Feb 22 15:57:24 2016 127.0.0.1 - - [GET] "/webcam.ffm HTTP/1.1" 200 36943
Mon Feb 22 15:57:24 2016 127.0.0.1 - - New connection: POST /webcam.ffm
[swscaler @ 0x1c0fa40] deprecated pixel format used, make sure you did set range correctly
Output #0, ffm, to 'http://127.0.0.1:8080/webcam.ffm':
  Metadata:
    creation_time   : 2016-02-22 15:57:24
    encoder         : Lavf57.25.101
    Stream #0:0: Video: mjpeg, yuvj422p(pc), 640x360, q=1-10, 2000 kb/s, 15 fps, 1000k tbn, 15 tbc
    Metadata:
      encoder         : Lavc57.24.103 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 4000000/0/2000000 buffer size: 4000000 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame=    9 fps=0.0 q=21.1 size=     380kB time=00:00:00.60 bitrate=5188.3kbits/s speed=1.07x frame=   17 fps= 16 q=24.8 size=     644kB time=00:00:01.13 bitrate=4655.0kbits/s speed=1.05x frame=   25 fps= 16 q=24.8 size=     912kB time=00:00:01.66 bitrate=4482.7kbits/s speed=1.04x frame=   33 fps= 16 q=24.8 size=    1180kB time=00:00:02.20 bitrate=4393.9kbits/s speed=1.04x frame=   41 fps= 15 q=24.8 size=    1448kB time=00:00:02.73 bitrate=4339.8kbits/s speed=1.03x frame=   48 fps= 15 q=24.8 size=    1680kB time=00:00:03.20 bitrate=4300.8kbits/s speed=   1x frame=   57 fps= 15 q=24.8 size=    1980kB time=00:00:03.80 bitrate=4268.5kbits/s speed=1.02x frame=   65 fps= 15 q=24.8 size=    2248kB time=00:00:04.33 bitrate=4249.8kbits/s speed=1.02x frame=   73 fps= 15 q=24.8 size=    2516kB time=00:00:04.86 bitrate=4235.2kbits/s speed=1.02x ...
That last line is actually a series of lines scrolling down the terminal page, like
Code:
frame=    9 fps=0.0 q=21.1 size=     380kB time=00:00:00.60 bitrate=5188.3kbits/s speed=1.07x
frame=   17 fps= 16 q=24.8 size=     644kB time=00:00:01.13 bitrate=4655.0kbits/s speed=1.05x
frame=   25 fps= 16 q=24.8 size=     912kB time=00:00:01.66 bitrate=4482.7kbits/s speed=1.04x 
...
When the browser (on another machine) attempts to open the stream, ffmpeg (on the Pi) displays a line like this:
Code:
Mon Feb 22 15:58:09 2016 192.168.1.105 - - [GET] "/webcam.mjpeg HTTP/1.1" 200 66
One more observation. I ran netcat in another ssh terminal on the Pi and saw this:
Code:
nc: connect to localhost port 8080 (tcp) failed: Connection refused
Connection to localhost 8080 port [tcp/http-alt] succeeded!
I don't know what the first line means. How can port 8080 be open and closed at the same time?

Last edited by r.stiltskin; 02-23-2016 at 12:22 AM.
 
Old 02-24-2016, 05:58 PM   #3
r.stiltskin
Member
 
Registered: Oct 2003
Location: USA
Distribution: Xubuntu, Arch
Posts: 231

Original Poster
Rep: Reputation: 31
partial solution

Getting back to this ...
Trying to simplify things to isolate the problem, I compiled ffmpeg on my Xubuntu box & installed it locally (in my home dir, not /usr, to avoid conflicts with libav) & I'm trying to get everything working on it, then I can move it over to the Pi.

I modified ffserver.conf to this (the significant change was to the HTTP bind address on line 2):
Code:
HTTPPort 8080
HTTPBindAddress 127.0.0.1
MaxHTTPConnections 20
MaxClients 10
MaxBandwidth 5000
#NoDaemon

<Feed webcam.ffm>
      file /tmp/webcam.ffm
      FileMaxSize 200K
      ACL allow 127.0.0.1
</Feed>

<Stream webcam.mjpeg>
	Feed webcam.ffm
	Format mjpeg
	VideoSize 640x360
	VideoFrameRate 15
	VideoBitRate 2000
	VideoQMin 1
	VideoQMax 10
</Stream>
So I connect the webcam to this computer, run ffserver, pointing it to ffserver.conf:
Code:
ffserver -d -f ~/ffmpeg_build/share/doc/ffserver.conf
check the output & it's running OK, no errors; put it in the background & run ffmpeg, sending the feed to 127.0.0.1:
Code:
ffmpeg -r 15 -s 640x360 -f v4l2 -i /dev/video0 http://127.0.0.1:8080/webcam.ffm
It also runs with no errors.
And now I run ffplay
Code:
ffplay http://127.0.0.1:8080/webcam.mjpeg
and voila! it opens a window and displays the live camera feed. There's a slight delay but quality is good and keeps up with movement. Great! I close that and try to do the same thing in Firefox, but it doesn't open the video, it wants to open the file (webcam.mjpeg) with ... I should select application to open it ... or save it. I try Chrome but it doesn't display the stream either, it just starts saving webcam.mjpeg to my downloads folder.

So what's going on? I keep finding tutorials that say Firefox and Chrome can display mjpeg streams directly just by browsing to the source, but they all seem to be a few years old. Have the browsers been changed to make them unable to do this anymore?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line to stream audio/video using ffmpeg? Xeratul Linux - General 1 08-05-2014 12:41 PM
FFMPEG : While converting a video how to select second audio stream bloodstreetboy Linux - Software 4 07-16-2012 07:11 AM
ffserver ffmpeg live stream from webcam Micah Linux - Software 2 08-31-2011 08:50 PM
extracting a stream from ffmpeg sumeet inani Linux - Newbie 3 11-18-2010 05:41 AM
ffmpeg - Unsupported codec for output stream #0.0 yitzle Linux - Software 4 01-30-2008 04:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration