Skip to content

Instantly share code, notes, and snippets.

View robwalch's full-sized avatar

Rob Walch robwalch

View GitHub Profile
@robwalch
robwalch / HLS.js-talk.md
Last active May 17, 2021 20:52
HLS.js v1.0 talk outline
@robwalch
robwalch / media-element-observer.js
Last active March 29, 2021 19:03
Observe attribute changes, method calls and events fired on a media element
const mediaElement = document.createElement('video');
function toString(video) {
return ((video.parentNode ? ('<' + video.parentNode.nodeName + '>') : '') + '<' + video.nodeName + '>')
.toLowerCase();
}
function videoEventHandler(e) {
console.warn(toString(e.target) + ' >> "' + e.type + '"');
}
@robwalch
robwalch / jw-ima-waterfall-hidden-setup-remove-on-ad-error.js
Last active December 17, 2020 18:05
JW Player Google IMA (bad) waterfall setup, with player that is hidden/removed unless ad break begins
const correlator = Math.floor(Date.now() / 1000 / 60); // changes every 60s
jwplayer('jwplayer_1').setup({
file: 'https://cdn.jwplayer.com/manifests/LQQpmqYT.m3u8',
autostart: true,
advertising: {
preloadAds: true,
autoplayadsmuted: true,
client: 'googima',
@robwalch
robwalch / sync_test.sh
Created July 25, 2020 00:21 — forked from elv-peter/sync_test.sh
Generate live HLS stream that causes audio to be out-of-sync for HLS.js
#!/bin/bash
#
# https://github.com/terabit-software/dynamic-stream-server/blob/master/scripts/sync_test.sh
#
# Tool to check video and audio sync.
# Loop with 1 beep per second with 4 increasing frequencies.
# Can be used to measure delays up to 4 seconds.
# The grid is accurate to about 1ms.
#
# Beep duration: 0.125s
@robwalch
robwalch / tos-4k.sh
Last active July 6, 2020 07:00
Tears of Steal 4k multibitrate multitrack HLS encode
#!/bin/sh
mkdir -p variant_source
ffmpeg -y -i tearsofsteel_4k.mov -vcodec libx264 -preset veryfast -crf 18 -profile:v baseline -s 480x212 -aspect 9/4 -acodec aac -strict experimental -ac 2 -b:a 96k -ar 44100 -bufsize 360K -maxrate 360K variant_source/ld.mp4
ffmpeg -y -i tearsofsteel_4k.mov -vcodec libx264 -preset veryfast -crf 18 -profile:v main -s 640x288 -aspect 9/4 -an -bufsize 720K -maxrate 720K variant_source/sd.mp4
ffmpeg -y -i tearsofsteel_4k.mov -vcodec libx264 -preset veryfast -crf 18 -profile:v high -s 1280x572 -aspect 9/4 -an -bufsize 2400K -maxrate 2400K variant_source/hd.mp4
ffmpeg -y -i tearsofsteel_4k.mov -vcodec libx264 -preset veryfast -crf 18 -profile:v high -s 1920x856 -aspect 9/4 -an -bufsize 3200K -maxrate 3200K variant_source/fullhd.mp4
ffmpeg -y -i tearsofsteel_4k.mov -vcodec libx264 -preset veryfast -crf 18 -profile:v high -s 2560x1142 -aspect 9/4 -an -bufsize 4800K -maxrate 4800K variant_source/quadhd.mp4
@robwalch
robwalch / gist:6324bd94dddb49bfd4696745796b9002
Created March 2, 2020 17:04
Detect audio playback in video element
// Use WebAudio API to detect audio playback with volume
// Returns early with false when audio could not be playing
// Returns null if WebAudio API cannot be used while media is in a playing state
function isMediaPlayingAudio(mediaElement) {
if (media.paused || media.muted || media.volume === 0 || media.played.length < 1) {
return false;
}
let analyser = media.audioAnalyser;
let audioCtx = media.audioCtx;
if (!analyser) {
@robwalch
robwalch / playbackrate.js
Last active November 14, 2019 17:33
Modify playbackRate for all video / audio elements on the page.
// playbackrate.js
// https://github.com/bgrins/devtools-snippets
// Increase playbackRate for all video / audio elements on the page.
(function() {
console.group('playbackRate');
[].forEach.call(document.querySelectorAll("video,audio"), function(media) {
var splitPath = media.src.split('/');
@robwalch
robwalch / media-element-observer-iife.js
Last active November 13, 2019 20:34
Observe attribute changes, method calls and events fired on a media element
(function (video) {
function toString() {
return ((video.parentNode ? ('<' + video.parentNode.nodeName + '>') : '') + '<' + video.nodeName + '>')
.toLowerCase();
}
function videoEventHandler(e) {
console.warn(toString() + ' >> "' + e.type + '"');
}
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
if (MutationObserver) {
@robwalch
robwalch / jwplayer-event-listeners.js
Last active July 2, 2018 01:48
Use Chrome's `getEventListeners` to list all even listeners added on the player container and child elements.
(function(jwplayer) {
const container = jwplayer().getContainer();
const elements = Array.prototype.slice.call(container.querySelectorAll('*'))
.filter(element => element.tagName !== 'path');
elements.unshift(container);
const listeners = elements.reduce((accumulator, element) => {
const listenersObj = getEventListeners(element);
return accumulator.concat(Object.keys(listenersObj).reduce((accumulator2, name) => {
listenersObj[name].forEach(eventListener => {
@robwalch
robwalch / jwplayer.timer.js
Created June 14, 2018 13:54
Sample customer provider for jwplayer
(function(jwplayer) {
var utils = jwplayer.utils;
var _ = jwplayer._;
var TIMEOUT_MS = 25;
var TIMEOUT_SEC = TIMEOUT_MS/1000;
var TIMER = 'timer';
function formatTime(t) {
t *= 1000; // seconds to milliseconds