Skip to content

Instantly share code, notes, and snippets.

@tetkuz
Last active February 13, 2024 16:49
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save tetkuz/0c038321d05586841897 to your computer and use it in GitHub Desktop.
Save tetkuz/0c038321d05586841897 to your computer and use it in GitHub Desktop.
GStreamer stream to HTML5

Description

[Server] GStreamer ---> HTML [Client]

Require

  • gstreamer-1.x
  • Browser which supports video tag of HTML5

debian

sduo apt-get install gstreamer1.0

Usage

  1. Please set a webcam to the your pc.
  2. Open index.html by the browser.
  3. Run streaming-XXXXX.sh by the terminal.
  4. You will can watch video which captured by webcam !!
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>gst-stream</title>
</head>
<body>
<video width=320 height=240 autoplay>
<source src="http://localhost:8080">
</video>
</body>
</html>
#!/bin/sh
# for Linux
gst-launch-1.0 \
v4l2src device=/dev/video0 \
! videoconvert ! videoscale ! video/x-raw,width=320,height=240 \
! clockoverlay shaded-background=true font-desc="Sans 38" \
! theoraenc ! oggmux ! tcpserversink host=127.0.0.1 port=8080
#!/bin/sh
# for Windows
gst-launch-1.0 \
ksvideosrc device-index=0 \
! videoconvert ! videoscale ! video/x-raw,width=320,height=240 \
! clockoverlay shaded-background=true font-desc="Sans 38" \
! theoraenc ! oggmux ! tcpserversink host=127.0.0.1 port=8080
@m-blanke
Copy link

m-blanke commented Oct 9, 2018

The reason for chrome throwing ERR_INVALID_HTTP_RESPONSE lies with tcpserversink not implementing HTTP. I.e. the reply on Port 8080 is only the payload/file, akin to transferring files with netcat. Chrome expects to see at least a bare header HTTP/1.0 200 OK, and refuses the stream.
This appears not to be something that could be fixed with gst-launch-1.0.
Meanwhile Firefox (and likely other browsers as as well) simply deal with it ;-)

@Turbine1991
Copy link

In Armbian:
v4l2src: command not found

gstreamer1.0-plugins-bad and gstreamer1.0-plugins-good are installed.

@stiv-yakovenko
Copy link

Of course this wouldn't work, because tcpserversink is not http server.

@sureshbadagi
Copy link

sureshbadagi commented Dec 9, 2019

Hi,
How can I stream by providing file .mp4?

I am new to HTML5 and working on feasibility test for gstreamer in HTML5.

I am able to run this command from the terminal and changed port number in index.html but nothing will be shown in html page.
Tried to chrome, IE etc.,

gst-launch-1.0 -v uridecodebin name=uridec uri=file:///C:\a.mp4 ! videoconvert ! videoscale ! video/x-raw,width=648,height=486 ! x264enc tune=4 bitrate=1000 threads=4 speed-preset=1 ! rtph264pay ! tcpserversink host=127.0.0.1 port=5000

@stiv-yakovenko
Copy link

Use hlssink instead

@sureshbadagi
Copy link

sureshbadagi commented Dec 9, 2019

Hi,
Thanks for the quick reply.

I have tried to change like below and getting black screen in the video player.,

gst-launch-1.0 videotestsrc is-live=true ! x264enc ! mpegtsmux ! hlssink max-files=5 playlist-root=http://127.0.0.1:5000 location=C:\Users\suresh\hlssink playlist-location=C:\Users\suresh\hlssink

BR/Suresh

@stiv-yakovenko
Copy link

I have no good idea how to do it, sorry/ Google for hlssink and do your research. Don't use this code sample.

@sureshbadagi
Copy link

Thanks, I will try and update if i get any good solution.

@stiv-yakovenko
Copy link

Yes, that would be very helpful to the community. I just wanted to say that this instruction is clearly missleading.

Thanks, I will try and update if i get any good solution.

@Sayyam-Jain
Copy link

Thanks, I will try and update if i get any good solution.

Did you figure it out?

@janoglezcampos
Copy link

Hello everyone, Im working on an Electron app with GStreamer, and I needed it to work with Chrome, and after lots of headaches I managed it work, I posted the script used on a repository, is my first time posting code, may its not very good explained, so open an issue if you don't can't make it work or anything else so I can improve it.

The problem (as net::ERR_INVALID_HTTP_RESPONSE states), is that you need to add a response, so I did with NodeJs, wish it can help.

Here is the repository: https://github.com/janoglezcampos/GstreamerChromeBridge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment