Skip to content

Instantly share code, notes, and snippets.

View TheDrHax's full-sized avatar

Дмитрий Карих TheDrHax

  • Moscow, Russian Federation
View GitHub Profile
@TheDrHax
TheDrHax / Dockerfile
Created January 26, 2024 20:57
mediamtx alpine
# docker build -t thedrhax/mediamtx .
FROM bluenviron/mediamtx
FROM alpine:3.19
RUN apk --no-cache add ffmpeg curl jq
COPY --from=0 /* /
ENTRYPOINT ["/mediamtx"]
@TheDrHax
TheDrHax / twitch-to-youtube-desync.md
Last active June 23, 2020 18:57
How to predict and fix audio desynchronization when uploading Twitch streams to YouTube.

The problem

When I download streams from Twitch, I remux them into MP4 because MPEG-TS doesn't support -movflags faststart, is not supported by HTML5 players and can't be uploaded directly to YouTube. Sometimes this process changes framerate of the video stream. Incorrect FPS somehow corrupts the video during processing on YouTube, which leads to horrible audio desynchronization on any resolutions below 1080p60.

My working theory is that Twitch doesn’t fill the voids in the stream when frames are lost. This is not critical for MPEG-TS and FLV containers, however, the MP4 container tries to compute the global average FPS. YouTube somehow relies on the global FPS during video processing, which leads to a decrease in the duration of the video stream, and causes its desynchronization with audio.

Check if video is safe to upload (manual method)

Good video (60 fps):

@TheDrHax
TheDrHax / keepsync.lua
Created October 5, 2019 23:10
MPV script that speeds up playback to maintain synchronization with live streams
-- keepsync.lua
--
-- Attempts to maintain initial offset of the live stream in case of
-- network or hardware lags by slightly speeding up playback until
-- synchronization is restored.
--
-- Initial offset is calculated right at the start of playback. If playback
-- immediately starts to lag, you can increase offset by pressing Shift+LEFT.
-- If your connection to stream source is good enough, you can also try to
-- decrease offset by pressing Shift+RIGHT. Both hotkeys are changing offset
@TheDrHax
TheDrHax / autosave.lua
Last active May 4, 2024 15:39 — forked from Hakkin/autosave.lua
MPV script that periodically saves "watch later" data during playback
-- autosave.lua
--
-- Periodically saves "watch later" data during playback, rather than only saving on quit.
-- This lets you easily recover your position in the case of an ungraceful shutdown of mpv (crash, power failure, etc.).
--
-- You can configure the save period by creating a "lua-settings" directory inside your mpv configuration directory.
-- Inside the "lua-settings" directory, create a file named "autosave.conf".
-- The save period can be set like so:
--
-- save_period=60
@TheDrHax
TheDrHax / script.js
Last active November 22, 2019 07:27
Скрипт для GreaseMonkey, быстро прокликивающий все нужные кнопки на https://auth.wi-fi.ru/
// ==UserScript==
// @name MosMetroV2.js
// @description This script skips annoying quizes and full screen ads on https://auth.wi-fi.ru
// @author Dmitry Karikh <mosmetro@thedrhax.pw> (https://github.com/mosmetro-android)
// @version 2
// @grant none
// @include *://auth.wi-fi.ru/auth*
// ==/UserScript==
(function () {
@TheDrHax
TheDrHax / Dockerfile
Last active April 3, 2017 13:51
Dockerfile for telegram-cli
FROM ubuntu:latest
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y git libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make
RUN git clone --recursive https://github.com/vysheng/tg.git && \
cd /tg && \
./configure && \
make -j5