diff --git a/depot/services/kattv-ingest/default.nix b/depot/services/kattv-ingest/default.nix index 99e3c7a1..613d15df 100644 --- a/depot/services/kattv-ingest/default.nix +++ b/depot/services/kattv-ingest/default.nix @@ -2,7 +2,100 @@ with lib; -{ +let + env = { + FREI0R_PATH = "${pkgs.frei0r}/lib/frei0r-1"; + GST_PLUGIN_SYSTEM_PATH_1_0 = with pkgs.gst_all_1; lib.makeSearchPath "lib/gstreamer-1.0" [ + gstreamer + gst-plugins-base + gst-plugins-good + gst-plugins-bad + gst-plugins-ugly + ]; + }; + queue_frame = { + element."queue" = { + leaky = "downstream"; + flush-on-eos = true; + max-size-buffers = 3; + }; + }; + queue_data = { + element.queue = { + leaky = "downstream"; + }; + }; + videoconvert_cpu = { + element.videoconvert = { + n-threads = 4; + dither = 0; + chroma-resampler = 0; + chroma-mode = 3; + }; + }; + videoconvert_gpu = [ + # TODO: vulkancolorconvert? + "glupload" + "glcolorconvert" + "gldownload" + ]; + encodeopts = { + speed-preset = "ultrafast"; + tune = "zerolatency"; + pass = "qual"; + #psy-tune = "film"; + #noise-reduction=0; + quantizer = 27; + bitrate = 8192; + rc-lookahead = 6; + }; + denoise = { + element.frei0r-filter-hqdn3d = { + spatial = 0.175; #0.325; + temporal = 0.06; #0.11; + }; + }; + encode_high = [ + { + element.x264enc = { + key-int-max = 150; + } // encodeopts; + } + { + caps."video/x-h264" = { + profile = "high"; + }; + } + "h264parse" + ]; + rtmpsink = [ + queue_data + "flvmux" + { + element.rtmp2sink = { + location = "rtmp://localhost:1935/stream/kattv"; + }; + } + ]; + pipeline = [ + { + element.fdsrc = { + fd = 3; + }; + } + "matroskademux" + "jpegdec" + queue_frame + + videoconvert_cpu + denoise + + videoconvert_cpu + encode_high + + rtmpsink + ]; +in { services.nginx.appendConfig = '' rtmp { server { @@ -33,8 +126,8 @@ with lib; }; systemd.services."kattv@" = { - environment = pkgs.kat-tv-ingest.env; - script = "exec ${pkgs.gst_all_1.gstreamer.dev}/bin/gst-launch-1.0 -e --no-position ${pkgs.lib.gst.pipelineShellString pkgs.kat-tv-ingest.pipeline}"; + environment = env; + script = "exec ${pkgs.gst_all_1.gstreamer.dev}/bin/gst-launch-1.0 -e --no-position ${pkgs.lib.gst.pipelineShellString pipeline}"; after = [ "nginx.service" ]; description = "RTMP stream of kat cam"; serviceConfig = { diff --git a/pkgs/default.nix b/pkgs/default.nix index 8107199c..a663e780 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -80,14 +80,6 @@ let kat-glauca-dns = self.callPackage ./kat-glauca-dns { }; - kat-tv = import ./kat-tv { pkgs = self; lib = self.lib; }; - - kat-tv-ingest = import ./kat-tv-ingest { pkgs = self; lib = self.lib; }; - - kat-website = self.callPackage ./kat-website { }; - - kat-weather = self.callPackage ./kat-weather { }; - kat-gpg-status = self.callPackage ./kat-gpg-status { }; kat-tw-export = self.callPackage ./kat-tw-export { }; diff --git a/pkgs/kat-tv-ingest/default.nix b/pkgs/kat-tv-ingest/default.nix deleted file mode 100644 index fa1cc026..00000000 --- a/pkgs/kat-tv-ingest/default.nix +++ /dev/null @@ -1,178 +0,0 @@ -{ pkgs ? import { }, lib }: with lib; with pkgs.gst_all_1; let - queue_frame = { - element."queue" = { - leaky = "downstream"; - flush-on-eos = true; - max-size-buffers = 3; - }; - }; - queue_data = { - element.queue = { - leaky = "downstream"; - }; - }; - videoconvert_cpu = { - element.videoconvert = { - n-threads = 4; - dither = 0; - chroma-resampler = 0; - chroma-mode = 3; - }; - }; - videoconvert_gpu = [ - # TODO: vulkancolorconvert? - "glupload" - "glcolorconvert" - "gldownload" - ]; - cameracapture = { - element."v4l2src" = { - device = "/dev/videomew"; - saturation = 100; - brightness = 100; - extra-controls = "c,exposure_auto=3"; - }; - }; - v4l2src = [ - cameracapture - { - caps."image/jpeg" = { - width = 1280; - height = 720; - framerate = "30/1"; # "10/1" - }; - } - "jpegdec" - queue_frame - ]; - filesrc = [ - { - element.filesrc = { - location = "rawvid.mkv"; - }; - } - "matroskademux" - ]; - denoise = { - element.frei0r-filter-hqdn3d = { - spatial = 0.175; #0.325; - temporal = 0.06; #0.11; - }; - }; - encodeopts = { - speed-preset = "ultrafast"; - tune = "zerolatency"; - pass = "qual"; - #psy-tune = "film"; - #noise-reduction=0; - quantizer = 27; - bitrate = 8192; - rc-lookahead = 6; - }; - encode_intra = [ - { - element.x264enc = { - intra-refresh = true; - key-int-max = 0; - } // encodeopts; - } - { - caps."video/x-h264" = { - profile = "high-4:2:2-intra"; - }; - } - "h264parse" - ]; - encode_high = [ - { - element.x264enc = { - key-int-max = 150; - } // encodeopts; - } - { - caps."video/x-h264" = { - profile = "high"; - }; - } - "h264parse" - ]; - rtmpsink = [ - queue_data - "flvmux" - { - element.rtmp2sink = { - location = "rtmp://localhost:1935/stream/kattv"; - }; - } - ]; - filesink = [ - "matroskamux" - { - element.filesink = { - location = "out.mkv"; - }; - } - ]; - videosink = "autovideosink"; - pipeline = [ - #filesrc - #v4l2src - { - element.fdsrc = { - fd = 3; - }; - } - "matroskademux" - "jpegdec" - queue_frame - - videoconvert_cpu - denoise - - videoconvert_cpu - encode_high - - rtmpsink - #filesink - ]; - #gst-launch-1.0 $camera ! $videoconvert ! $queue ! $denoise ! $encode ! $outfile - env = { - FREI0R_PATH = "${pkgs.frei0r}/lib/frei0r-1"; - GST_PLUGIN_SYSTEM_PATH_1_0 = with pkgs.gst_all_1; lib.makeSearchPath "lib/gstreamer-1.0" [ - gstreamer - gst-plugins-base - gst-plugins-good - gst-plugins-bad - gst-plugins-ugly - ]; - }; - shell = pkgs.mkShell (env // { - nativeBuildInputs = [ gstreamer kattv ]; - }); -in -{ - inherit shell pipeline env; -} -#!/usr/bin/env bash -/* - - - - - #encode='x264enc intra-refresh=true key-int-max=0 speed-preset=superfast tune=zerolatency pass=qual psy-tune=film noise-reduction=250 quantizer=23 rc-lookahead=15 ! video/x-h264,profile=high-4:2:2-intra ! h264parse' - #encode="x264enc intra-refresh=true key-int-max=0 $encodeopts ! video/x-h264,profile=high-4:2:2-intra ! h264parse ! $bufqueue" - encode="x264enc key-int-max=50 $encodeopts ! video/x-h264,profile=high-4:2:2 ! h264parse ! $bufqueue" - - # original pipeline: - # gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=YUY2,width=1280,height=800,framerate=10/1" ! videoconvert ! x264enc intra-refresh=true key-int-max=0 speed-preset=superfast tune=zerolatency pass=qual psy-tune=film noise-reduction=250 quantizer=23 rc-lookahead=15 ! video/x-h264,profile=high-4:2:2-intra ! h264parse ! flvmux ! rtmpsink location="rtmp://kittywit.ch/kattv/meowlymeowl live=1" - - - #gst-launch-1.0 filesrc location=rawvid.mkv ! mkvdemux ! "video/x-raw,format=YUY2,width=1280,height=800,framerate=10/1" ! videoconvert ! x264enc intra-refresh=true key-int-max=0 speed-preset=superfast tune=zerolatency pass=qual psy-tune=film noise-reduction=250 quantizer=23 rc-lookahead=15 ! video/x-h264,profile=high-4:2:2-intra ! h264parse ! flvmux ! filesink location=out.flv - - #gst-launch-1.0 filesrc location=rawvid.mkv ! matroskademux ! "video/x-raw,format=YUY2,width=1280,height=800,framerate=10/1" ! videoconvert ! "video/x-raw,format=RGBA" ! frei0r-filter-hqdn3d spatial=0.35 temporal=0.115 ! videoconvert ! autovideosink - - outfile='flvmux ! filesink location=out.flv' - #gst-launch-1.0 $camera ! $videoconvert ! $denoise ! autovideosink - gst-launch-1.0 $camera ! $videoconvert ! $queue ! $denoise ! $encode ! $outfile - #gst-launch-1.0 $camera ! $videoconvert ! $encode ! $outfile -*/ diff --git a/pkgs/kat-tv/default.nix b/pkgs/kat-tv/default.nix deleted file mode 100644 index 1c65fc91..00000000 --- a/pkgs/kat-tv/default.nix +++ /dev/null @@ -1,168 +0,0 @@ -{ pkgs ? import { }, lib }: with lib; with pkgs.gst_all_1; let - queue_frame = { - element."queue" = { - leaky = "downstream"; - flush-on-eos = true; - max-size-buffers = 3; - }; - }; - queue_data = { - element.queue = { - leaky = "downstream"; - }; - }; - videoconvert_cpu = { - element.videoconvert = { - n-threads = 4; - dither = 0; - chroma-resampler = 0; - chroma-mode = 3; - }; - }; - videoconvert_gpu = [ - # TODO: vulkancolorconvert? - "glupload" - "glcolorconvert" - "gldownload" - ]; - cameracapture = { - element."v4l2src" = { - device = "/dev/videomew"; - saturation = 100; - brightness = 100; - extra-controls = "c,exposure_auto=3"; - }; - }; - v4l2src = [ - cameracapture - { - caps."image/jpeg" = { - width = 1280; - height = 720; - framerate = "30/1"; # "10/1" - }; - } - ]; - filesrc = [ - { - element.filesrc = { - location = "rawvid.mkv"; - }; - } - "matroskademux" - ]; - denoise = { - element.frei0r-filter-hqdn3d = { - spatial = 0.175; #0.325; - temporal = 0.06; #0.11; - }; - }; - encodeopts = { - speed-preset = "ultrafast"; - tune = "zerolatency"; - pass = "qual"; - #psy-tune = "film"; - #noise-reduction=0; - quantizer = 27; - bitrate = 8192; - rc-lookahead = 6; - }; - encode_intra = [ - { - element.x264enc = { - intra-refresh = true; - key-int-max = 0; - } // encodeopts; - } - { - caps."video/x-h264" = { - profile = "high-4:2:2-intra"; - }; - } - "h264parse" - ]; - encode_high = [ - { - element.x264enc = { - key-int-max = 150; - } // encodeopts; - } - { - caps."video/x-h264" = { - profile = "high"; - }; - } - "h264parse" - ]; - rtmpsink = [ - queue_data - "flvmux" - { - element.rtmp2sink = { - location = "rtmp://192.168.1.223:1935/stream/kattv"; - }; - } - ]; - filesink = [ - "matroskamux" - { - element.filesink = { - location = "out.mkv"; - }; - } - ]; - videosink = "autovideosink"; - pipeline = v4l2src ++ [ - #filesrc - "jpegtrunc" - { element.matroskamux.streamable = true; } - { - element.tcpclientsink = { - host = "192.168.1.223"; - port = "4953"; - sync = false; - }; - } - ]; - #gst-launch-1.0 $camera ! $videoconvert ! $queue ! $denoise ! $encode ! $outfile - env = { - FREI0R_PATH = "${pkgs.frei0r}/lib/frei0r-1"; - GST_PLUGIN_SYSTEM_PATH_1_0 = with pkgs.gst_all_1; lib.makeSearchPath "lib/gstreamer-1.0" [ - gstreamer - gst-plugins-base - gst-plugins-good - gst-plugins-bad - gst-plugins-ugly - pkgs.gst-jpegtrunc - ]; - }; - shell = pkgs.mkShell (env // { - nativeBuildInputs = [ gstreamer kattv ]; - }); -in -{ - inherit shell pipeline env; -} -#!/usr/bin/env bash -/* - - - - - #encode='x264enc intra-refresh=true key-int-max=0 speed-preset=superfast tune=zerolatency pass=qual psy-tune=film noise-reduction=250 quantizer=23 rc-lookahead=15 ! video/x-h264,profile=high-4:2:2-intra ! h264parse' - #encode="x264enc intra-refresh=true key-int-max=0 $encodeopts ! video/x-h264,profile=high-4:2:2-intra ! h264parse ! $bufqueue" - encode="x264enc key-int-max=50 $encodeopts ! video/x-h264,profile=high-4:2:2 ! h264parse ! $bufqueue" - - # original pipeline: - # gst-launch-1.0 v4l2src device=/dev/video0 ! "video/x-raw,format=YUY2,width=1280,height=800,framerate=10/1" ! videoconvert ! x264enc intra-refresh=true key-int-max=0 speed-preset=superfast tune=zerolatency pass=qual psy-tune=film noise-reduction=250 quantizer=23 rc-lookahead=15 ! video/x-h264,profile=high-4:2:2-intra ! h264parse ! flvmux ! rtmpsink location="rtmp://kittywit.ch/kattv/meowlymeowl live=1" - - - #gst-launch-1.0 filesrc location=rawvid.mkv ! mkvdemux ! "video/x-raw,format=YUY2,width=1280,height=800,framerate=10/1" ! videoconvert ! x264enc intra-refresh=true key-int-max=0 speed-preset=superfast tune=zerolatency pass=qual psy-tune=film noise-reduction=250 quantizer=23 rc-lookahead=15 ! video/x-h264,profile=high-4:2:2-intra ! h264parse ! flvmux ! filesink location=out.flv - - #gst-launch-1.0 filesrc location=rawvid.mkv ! matroskademux ! "video/x-raw,format=YUY2,width=1280,height=800,framerate=10/1" ! videoconvert ! "video/x-raw,format=RGBA" ! frei0r-filter-hqdn3d spatial=0.35 temporal=0.115 ! videoconvert ! autovideosink - - outfile='flvmux ! filesink location=out.flv' - #gst-launch-1.0 $camera ! $videoconvert ! $denoise ! autovideosink - gst-launch-1.0 $camera ! $videoconvert ! $queue ! $denoise ! $encode ! $outfile - #gst-launch-1.0 $camera ! $videoconvert ! $encode ! $outfile -*/ diff --git a/pkgs/kat-weather/default.nix b/pkgs/kat-weather/default.nix deleted file mode 100644 index e409c70c..00000000 --- a/pkgs/kat-weather/default.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ lib, stdenv, fetchurl, python36, pythonPackages, installShellFiles }: - -stdenv.mkDerivation { - name = "kat-weather"; - buildInputs = [ - (python36.withPackages (pythonPackages: with pythonPackages; [ requests ])) - ]; - unpackPhase = "true"; - installPhase = '' - mkdir -p $out/bin - cp ${./weather.py} $out/bin/kat-weather - chmod +x $out/bin/kat-weather - ''; -} diff --git a/pkgs/kat-weather/weather.py b/pkgs/kat-weather/weather.py deleted file mode 100644 index 6def3c80..00000000 --- a/pkgs/kat-weather/weather.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 - -import requests -import json -import sys - -city = sys.argv[1] -api_key = sys.argv[2] - -url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric" - -weather_icons = { - "Thunderstorm": "摒", - "Clouds": "摒", - "Drizzle": "", - "Rain": "", - "Snow": "流", - "Clear": "滛", - "Mist": "", - "Smoke": "", - "Haze": "", - "Dust": "", - "Fog": "", - "Sand": "", - "Ash": "", - "Squall": "", - "Tornado": "" -} - -#def degrees_to_cardinal(d): -# dirs = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", -# "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"] -# ix = int((d + 11.25)/22.5) -# return dirs[ix % 16] - -response = requests.get(url) -data = json.loads(response.text) -#print(data) - -condition = data["weather"][0]["main"] -weather_icon = weather_icons[condition] -temperature = f"{round(data['main']['temp'])}°C" -feels_like_temperature = f"{round(data['main']['feels_like'])}°C" -humidity = f"{data['main']['humidity']}%" -wind = f"{round(data['wind']['speed'])}m/s" # {degrees_to_cardinal(data['wind']['deg'])}" - -end_string = f"{weather_icon} {temperature} {feels_like_temperature} {humidity} {wind}" -print(end_string)