Last active
February 18, 2019 18:15
-
-
Save furqanrydhan/805fdcd729c7586afc7046cad00210b8 to your computer and use it in GitHub Desktop.
untested but should be a basic hls -> access frame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.7-stretch | |
RUN apt update && apt -y install \ | |
autopoint \ | |
autotools-dev \ | |
bison \ | |
build-essential \ | |
ffmpeg \ | |
flex \ | |
git \ | |
gtk-doc-tools \ | |
libgirepository1.0-dev \ | |
librtmp-dev \ | |
libx264-dev \ | |
openssh-client \ | |
python3-venv \ | |
yasm \ | |
curl \ | |
libsoup2.4-1 \ | |
libsoup2.4-dev \ | |
&& rm -rf /var/lib/apt/lists/* | |
WORKDIR /gstreamer | |
COPY . . | |
RUN sh install.sh && rm -rf ./*/ && rm -rf ./*.tar.xz | |
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/cuda-9.2:${LD_LIBRARY_PATH} | |
ENV GI_TYPELIB_PATH=/usr/local/lib/girepository-1.0:${GI_TYPELIB_PATH} | |
ENV GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0:${GST_PLUGIN_PATH} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import gi | |
gi.require_version("Gst", "1.0") | |
from gi.repository import Gst, GLib | |
Gst.init(None) | |
HLS_U = "http://some/playlist.m3u8" | |
demux = None | |
pipeline = None | |
def on_frame(_, buf, pad): | |
caps = pad.get_current_caps() | |
caps_structure = caps.get_structure(0) | |
width = caps_structure.get_int("width").value | |
height = caps_structure.get_int("height").value | |
(_result, mapinfo) = buf.map(Gst.MapFlags.READ) | |
nparr = np.fromstring( | |
mapinfo.data, np.uint8).reshape(height, width, 3) | |
buf.unmap(mapinfo) | |
timestamp = buf.pts | |
def on_message(_, message): | |
pass | |
def demux_pad_added(element, pad): | |
if element != demux: | |
return | |
caps_string = pad.get_current_caps().to_string() | |
if "video" in caps_string: | |
h264parse = Gst.ElementFactory.make("h264parse") | |
h264dec = Gst.ElementFactory.make("avdec_h264") | |
videorate = Gst.ElementFactory.make("videorate") | |
videoconvert = Gst.ElementFactory.make("videoconvert") | |
capsfilter = Gst.ElementFactory.make("capsfilter", name) | |
caps = Gst.Caps.from_string("video/x-raw,framerate=1/1,format=BGR") | |
capsfilter.set_property("caps", caps) | |
fakesink_queue = Gst.ElementFactory.make("queue") | |
fakesink_queue.set_property("leaky", 2) | |
fakesink = Gst.ElementFactory.make("fakesink") | |
fakesink.set_property("signal-handoffs", True) | |
fakesink.connect( | |
"handoff", on_frame) | |
elements = [h264parse, h264dec, videorate, videoconvert, | |
capsfilter, fakesink_queue, fakesink] | |
for e in elements: | |
pipeline.add(e) | |
pad.link(h264parse.get_static_pad("sink")) | |
Gst.Element.link(h264parse, h264dec) | |
Gst.Element.link(h264dec, videorate) | |
Gst.Element.link(videorate, videoconvert) | |
Gst.Element.link(videoconvert, capsfilter) | |
Gst.Element.link(capsfilter, fakesink_queue) | |
Gst.Element.link(fakesink_queue, fakesink) | |
for e in elements: | |
e.set_state(Gst.State.PLAYING) | |
try: | |
loop = GLib.MainLoop() | |
loop.run() | |
pipeline = Gst.Pipeline.new("SOME_NAME") | |
bus = pipeline.get_bus() | |
bus.add_signal_watch() | |
bus_message_connection = bus.connect( | |
"message", on_message) | |
src = Gst.ElementFactory.make("souphttpsrc") | |
src.set_property("location", HLS_URL) | |
demux = Gst.ElementFactory.make("hlsdemux") | |
queue = Gst.ElementFactory.make("queue") | |
pipeline.add(src) | |
pipeline.add(queue) | |
pipeline.add(demux) | |
Gst.Element.link(src, queue) | |
Gst.Element.link(queue, demux) | |
demux.connect("pad-added", demux_pad_added) | |
pipeline.set_state(Gst.State.PLAYING) | |
except KeyboardInterrupt: | |
sys.exit(0) | |
except Exception as e: | |
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LD_LIBRARY_PATH=/usr/local/lib | |
set -e | |
set -x | |
### gstreamer | |
wget https://gstreamer.freedesktop.org/src/gstreamer/gstreamer-1.14.4.tar.xz | |
tar xvf gstreamer-1.14.4.tar.xz | |
cd gstreamer-1.14.4 | |
./autogen.sh --enable-introspection --disable-failing-tests --disable-gtk-doc | |
make -j4 | |
make install | |
cd .. | |
## base | |
wget https://gstreamer.freedesktop.org/src/gst-plugins-base/gst-plugins-base-1.14.4.tar.xz | |
tar xvf gst-plugins-base-1.14.4.tar.xz | |
cd gst-plugins-base-1.14.4 | |
./autogen.sh --enable-introspection --disable-failing-tests --disable-gtk-doc | |
make -j4 | |
make install | |
cd .. | |
## good | |
wget https://gstreamer.freedesktop.org/src/gst-plugins-good/gst-plugins-good-1.14.4.tar.xz | |
tar xvf gst-plugins-good-1.14.4.tar.xz | |
cd gst-plugins-good-1.14.4 | |
./autogen.sh --enable-introspection --disable-failing-tests --disable-gtk-doc | |
make -j4 | |
make install | |
cd .. | |
## bad | |
wget https://gstreamer.freedesktop.org/src/gst-plugins-bad/gst-plugins-bad-1.14.4.tar.xz | |
tar xvf gst-plugins-bad-1.14.4.tar.xz | |
cd gst-plugins-bad-1.14.4 | |
./autogen.sh --enable-introspection --disable-failing-tests --disable-gtk-doc | |
make -j4 | |
make install | |
cd .. | |
## ugly | |
wget https://gstreamer.freedesktop.org/src/gst-plugins-ugly/gst-plugins-ugly-1.14.4.tar.xz | |
tar xvf gst-plugins-ugly-1.14.4.tar.xz | |
cd gst-plugins-ugly-1.14.4 | |
./autogen.sh --enable-introspection --disable-failing-tests --disable-gtk-doc | |
make -j4 | |
make install | |
cd .. | |
## av | |
wget https://gstreamer.freedesktop.org/src/gst-libav/gst-libav-1.14.4.tar.xz | |
tar xvf gst-libav-1.14.4.tar.xz | |
cd gst-libav-1.14.4 | |
./autogen.sh --enable-introspection --disable-failing-tests --disable-gtk-doc | |
make -j4 | |
make install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment