Viewing H.264 bitstream in browser using ffmpeg to ffserver












1















This is a followup to https://raspberrypi.stackexchange.com/questions/93254/stream-usb-webcam-with-audio?noredirect=1#comment150507_93254



I, like many other brave tinkerers before me, thought it would be a simple task to take an old USB camera (c920) can pair it with a raspberry pi to make a network streaming device (e.g., baby monitor). As those that have gone before me, I have now realized (after two days of tearing my hair out), that this is an extremely complicated task.



Problem statement: I have a raspberry pi zero and a c920 webcam. I want to use the H.264 bitstream from the webcam and serve it on the pi without transcoding it (the feeble processor would really struggle). I want to combine the video stream with its audio and send it over to a browser (phone, tablet, pc - something HTML5 without NAPI).



My current strategy is to do the following:



ffmpeg -re -f s16le -i /dev/zero -f v4l2 -thread_queue_size 512 -codec:v h264 -s 1920x1080 -i /dev/video0 -codec:v copy -acodec aac -ab 128k -g 50 http://localhost:8090/camera.ffm (this is with dummy audio - I figured I would add audio later)



Followed by sudo ffserver -d -f /etc/ffserver.conf to received the feed and broadcast it as a stream. This is the ffserver.conf file:



`HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 100000
CustomLog -
<Feed camera.ffm>
File /tmp/streamwebm.ffm
FileMaxSize 50M
ACL allow localhost
ACL allow 128.199.149.46
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.0.255
</Feed>
<Stream stream>
ACL allow 192.168.0.0 192.168.0.255
Format webm

# Video Settings
VideoFrameRate 30
VideoSize 1920x1080

# Audio settings
AudioCodec libvorbis
AudioSampleRate 48000
AVOptionAudio flags +global_header

MaxTime 0
AVOptionVideo me_range 16
AVOptionVideo qdiff 4
AVOptionVideo qmin 4
AVOptionVideo qmax 40
#AVOptionVideo good
AVOptionVideo flags +global_header

# Streaming settings
PreRoll 10
StartSendOnKey

Metadata author "author"
Metadata copyright "copyright"
Metadata title "Web app name"
Metadata comment "comment"
</stream>


My basic html is<html><head></head><body><video> <source src="http://localhost:8090/stream"> </video></body></html>



The stream however, doesn't work (the browser won't connect) and I get the following:
enter image description here



And the browser on the client says (failed) NET::ERR_CONNECTION_REFUSED



Thoughts:
- https://stackoverflow.com/questions/28435564/begin-stream-simple-mp4-with-ffserver explains that ffserver can't stream .mp4 because of headers or something. This is why I am using webm (which doesn't support h.264 I believe and is causing the really slow performance converting to vp9). I'm not concerned about CPU usage at the moment, just want to get an image to appear on the browser!




  • I hear one issue deals with 'chunking' - that the camera h.264 is a bitstream but h.264 streams for html5 should be chunked. Not sure how that would work.


  • I have tried VLC for some things (RTP) but haven't have success.


  • Most resources (SE and other sites) are from 2010-2015 and it seems as thought v4l2 and other things have developed since then.


  • As my problem is most likely general ignorance of the subject matter, I would appreciate any answers that provide some general understanding as to the theory behind different techniques. I know this makes the question more of a call for opinion and less appropriate for SE, but I'm fixing to throw my computer out the window (you know the feeling).



Thank you!










share|improve this question



























    1















    This is a followup to https://raspberrypi.stackexchange.com/questions/93254/stream-usb-webcam-with-audio?noredirect=1#comment150507_93254



    I, like many other brave tinkerers before me, thought it would be a simple task to take an old USB camera (c920) can pair it with a raspberry pi to make a network streaming device (e.g., baby monitor). As those that have gone before me, I have now realized (after two days of tearing my hair out), that this is an extremely complicated task.



    Problem statement: I have a raspberry pi zero and a c920 webcam. I want to use the H.264 bitstream from the webcam and serve it on the pi without transcoding it (the feeble processor would really struggle). I want to combine the video stream with its audio and send it over to a browser (phone, tablet, pc - something HTML5 without NAPI).



    My current strategy is to do the following:



    ffmpeg -re -f s16le -i /dev/zero -f v4l2 -thread_queue_size 512 -codec:v h264 -s 1920x1080 -i /dev/video0 -codec:v copy -acodec aac -ab 128k -g 50 http://localhost:8090/camera.ffm (this is with dummy audio - I figured I would add audio later)



    Followed by sudo ffserver -d -f /etc/ffserver.conf to received the feed and broadcast it as a stream. This is the ffserver.conf file:



    `HTTPPort 8090
    HTTPBindAddress 0.0.0.0
    MaxHTTPConnections 2000
    MaxClients 1000
    MaxBandwidth 100000
    CustomLog -
    <Feed camera.ffm>
    File /tmp/streamwebm.ffm
    FileMaxSize 50M
    ACL allow localhost
    ACL allow 128.199.149.46
    ACL allow 127.0.0.1
    ACL allow 192.168.0.0 192.168.0.255
    </Feed>
    <Stream stream>
    ACL allow 192.168.0.0 192.168.0.255
    Format webm

    # Video Settings
    VideoFrameRate 30
    VideoSize 1920x1080

    # Audio settings
    AudioCodec libvorbis
    AudioSampleRate 48000
    AVOptionAudio flags +global_header

    MaxTime 0
    AVOptionVideo me_range 16
    AVOptionVideo qdiff 4
    AVOptionVideo qmin 4
    AVOptionVideo qmax 40
    #AVOptionVideo good
    AVOptionVideo flags +global_header

    # Streaming settings
    PreRoll 10
    StartSendOnKey

    Metadata author "author"
    Metadata copyright "copyright"
    Metadata title "Web app name"
    Metadata comment "comment"
    </stream>


    My basic html is<html><head></head><body><video> <source src="http://localhost:8090/stream"> </video></body></html>



    The stream however, doesn't work (the browser won't connect) and I get the following:
    enter image description here



    And the browser on the client says (failed) NET::ERR_CONNECTION_REFUSED



    Thoughts:
    - https://stackoverflow.com/questions/28435564/begin-stream-simple-mp4-with-ffserver explains that ffserver can't stream .mp4 because of headers or something. This is why I am using webm (which doesn't support h.264 I believe and is causing the really slow performance converting to vp9). I'm not concerned about CPU usage at the moment, just want to get an image to appear on the browser!




    • I hear one issue deals with 'chunking' - that the camera h.264 is a bitstream but h.264 streams for html5 should be chunked. Not sure how that would work.


    • I have tried VLC for some things (RTP) but haven't have success.


    • Most resources (SE and other sites) are from 2010-2015 and it seems as thought v4l2 and other things have developed since then.


    • As my problem is most likely general ignorance of the subject matter, I would appreciate any answers that provide some general understanding as to the theory behind different techniques. I know this makes the question more of a call for opinion and less appropriate for SE, but I'm fixing to throw my computer out the window (you know the feeling).



    Thank you!










    share|improve this question

























      1












      1








      1








      This is a followup to https://raspberrypi.stackexchange.com/questions/93254/stream-usb-webcam-with-audio?noredirect=1#comment150507_93254



      I, like many other brave tinkerers before me, thought it would be a simple task to take an old USB camera (c920) can pair it with a raspberry pi to make a network streaming device (e.g., baby monitor). As those that have gone before me, I have now realized (after two days of tearing my hair out), that this is an extremely complicated task.



      Problem statement: I have a raspberry pi zero and a c920 webcam. I want to use the H.264 bitstream from the webcam and serve it on the pi without transcoding it (the feeble processor would really struggle). I want to combine the video stream with its audio and send it over to a browser (phone, tablet, pc - something HTML5 without NAPI).



      My current strategy is to do the following:



      ffmpeg -re -f s16le -i /dev/zero -f v4l2 -thread_queue_size 512 -codec:v h264 -s 1920x1080 -i /dev/video0 -codec:v copy -acodec aac -ab 128k -g 50 http://localhost:8090/camera.ffm (this is with dummy audio - I figured I would add audio later)



      Followed by sudo ffserver -d -f /etc/ffserver.conf to received the feed and broadcast it as a stream. This is the ffserver.conf file:



      `HTTPPort 8090
      HTTPBindAddress 0.0.0.0
      MaxHTTPConnections 2000
      MaxClients 1000
      MaxBandwidth 100000
      CustomLog -
      <Feed camera.ffm>
      File /tmp/streamwebm.ffm
      FileMaxSize 50M
      ACL allow localhost
      ACL allow 128.199.149.46
      ACL allow 127.0.0.1
      ACL allow 192.168.0.0 192.168.0.255
      </Feed>
      <Stream stream>
      ACL allow 192.168.0.0 192.168.0.255
      Format webm

      # Video Settings
      VideoFrameRate 30
      VideoSize 1920x1080

      # Audio settings
      AudioCodec libvorbis
      AudioSampleRate 48000
      AVOptionAudio flags +global_header

      MaxTime 0
      AVOptionVideo me_range 16
      AVOptionVideo qdiff 4
      AVOptionVideo qmin 4
      AVOptionVideo qmax 40
      #AVOptionVideo good
      AVOptionVideo flags +global_header

      # Streaming settings
      PreRoll 10
      StartSendOnKey

      Metadata author "author"
      Metadata copyright "copyright"
      Metadata title "Web app name"
      Metadata comment "comment"
      </stream>


      My basic html is<html><head></head><body><video> <source src="http://localhost:8090/stream"> </video></body></html>



      The stream however, doesn't work (the browser won't connect) and I get the following:
      enter image description here



      And the browser on the client says (failed) NET::ERR_CONNECTION_REFUSED



      Thoughts:
      - https://stackoverflow.com/questions/28435564/begin-stream-simple-mp4-with-ffserver explains that ffserver can't stream .mp4 because of headers or something. This is why I am using webm (which doesn't support h.264 I believe and is causing the really slow performance converting to vp9). I'm not concerned about CPU usage at the moment, just want to get an image to appear on the browser!




      • I hear one issue deals with 'chunking' - that the camera h.264 is a bitstream but h.264 streams for html5 should be chunked. Not sure how that would work.


      • I have tried VLC for some things (RTP) but haven't have success.


      • Most resources (SE and other sites) are from 2010-2015 and it seems as thought v4l2 and other things have developed since then.


      • As my problem is most likely general ignorance of the subject matter, I would appreciate any answers that provide some general understanding as to the theory behind different techniques. I know this makes the question more of a call for opinion and less appropriate for SE, but I'm fixing to throw my computer out the window (you know the feeling).



      Thank you!










      share|improve this question














      This is a followup to https://raspberrypi.stackexchange.com/questions/93254/stream-usb-webcam-with-audio?noredirect=1#comment150507_93254



      I, like many other brave tinkerers before me, thought it would be a simple task to take an old USB camera (c920) can pair it with a raspberry pi to make a network streaming device (e.g., baby monitor). As those that have gone before me, I have now realized (after two days of tearing my hair out), that this is an extremely complicated task.



      Problem statement: I have a raspberry pi zero and a c920 webcam. I want to use the H.264 bitstream from the webcam and serve it on the pi without transcoding it (the feeble processor would really struggle). I want to combine the video stream with its audio and send it over to a browser (phone, tablet, pc - something HTML5 without NAPI).



      My current strategy is to do the following:



      ffmpeg -re -f s16le -i /dev/zero -f v4l2 -thread_queue_size 512 -codec:v h264 -s 1920x1080 -i /dev/video0 -codec:v copy -acodec aac -ab 128k -g 50 http://localhost:8090/camera.ffm (this is with dummy audio - I figured I would add audio later)



      Followed by sudo ffserver -d -f /etc/ffserver.conf to received the feed and broadcast it as a stream. This is the ffserver.conf file:



      `HTTPPort 8090
      HTTPBindAddress 0.0.0.0
      MaxHTTPConnections 2000
      MaxClients 1000
      MaxBandwidth 100000
      CustomLog -
      <Feed camera.ffm>
      File /tmp/streamwebm.ffm
      FileMaxSize 50M
      ACL allow localhost
      ACL allow 128.199.149.46
      ACL allow 127.0.0.1
      ACL allow 192.168.0.0 192.168.0.255
      </Feed>
      <Stream stream>
      ACL allow 192.168.0.0 192.168.0.255
      Format webm

      # Video Settings
      VideoFrameRate 30
      VideoSize 1920x1080

      # Audio settings
      AudioCodec libvorbis
      AudioSampleRate 48000
      AVOptionAudio flags +global_header

      MaxTime 0
      AVOptionVideo me_range 16
      AVOptionVideo qdiff 4
      AVOptionVideo qmin 4
      AVOptionVideo qmax 40
      #AVOptionVideo good
      AVOptionVideo flags +global_header

      # Streaming settings
      PreRoll 10
      StartSendOnKey

      Metadata author "author"
      Metadata copyright "copyright"
      Metadata title "Web app name"
      Metadata comment "comment"
      </stream>


      My basic html is<html><head></head><body><video> <source src="http://localhost:8090/stream"> </video></body></html>



      The stream however, doesn't work (the browser won't connect) and I get the following:
      enter image description here



      And the browser on the client says (failed) NET::ERR_CONNECTION_REFUSED



      Thoughts:
      - https://stackoverflow.com/questions/28435564/begin-stream-simple-mp4-with-ffserver explains that ffserver can't stream .mp4 because of headers or something. This is why I am using webm (which doesn't support h.264 I believe and is causing the really slow performance converting to vp9). I'm not concerned about CPU usage at the moment, just want to get an image to appear on the browser!




      • I hear one issue deals with 'chunking' - that the camera h.264 is a bitstream but h.264 streams for html5 should be chunked. Not sure how that would work.


      • I have tried VLC for some things (RTP) but haven't have success.


      • Most resources (SE and other sites) are from 2010-2015 and it seems as thought v4l2 and other things have developed since then.


      • As my problem is most likely general ignorance of the subject matter, I would appreciate any answers that provide some general understanding as to the theory behind different techniques. I know this makes the question more of a call for opinion and less appropriate for SE, but I'm fixing to throw my computer out the window (you know the feeling).



      Thank you!







      ffmpeg raspberry-pi video-streaming h.264 ffserver






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 21 at 17:08









      BobtheMagicMooseBobtheMagicMoose

      549310




      549310






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Changing localhost to 127.0.0.1 in the ffmpeg call fixed this issue for me.






          share|improve this answer
























          • Then it seems you had some issues with host name resolution.

            – RalfFriedl
            Feb 23 at 9:31











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1396700%2fviewing-h-264-bitstream-in-browser-using-ffmpeg-to-ffserver%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Changing localhost to 127.0.0.1 in the ffmpeg call fixed this issue for me.






          share|improve this answer
























          • Then it seems you had some issues with host name resolution.

            – RalfFriedl
            Feb 23 at 9:31
















          0














          Changing localhost to 127.0.0.1 in the ffmpeg call fixed this issue for me.






          share|improve this answer
























          • Then it seems you had some issues with host name resolution.

            – RalfFriedl
            Feb 23 at 9:31














          0












          0








          0







          Changing localhost to 127.0.0.1 in the ffmpeg call fixed this issue for me.






          share|improve this answer













          Changing localhost to 127.0.0.1 in the ffmpeg call fixed this issue for me.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 23 at 9:09









          AlexVestinAlexVestin

          101




          101













          • Then it seems you had some issues with host name resolution.

            – RalfFriedl
            Feb 23 at 9:31



















          • Then it seems you had some issues with host name resolution.

            – RalfFriedl
            Feb 23 at 9:31

















          Then it seems you had some issues with host name resolution.

          – RalfFriedl
          Feb 23 at 9:31





          Then it seems you had some issues with host name resolution.

          – RalfFriedl
          Feb 23 at 9:31


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1396700%2fviewing-h-264-bitstream-in-browser-using-ffmpeg-to-ffserver%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          Brian Clough

          Cáceres