Skip to content

Instantly share code, notes, and snippets.

View dudewheresmycode's full-sized avatar

Brian R dudewheresmycode

View GitHub Profile
@dudewheresmycode
dudewheresmycode / FFMPEG Scene Detection.md
Last active March 4, 2024 10:06
Notes on scene detection with FFMPEG

Basic ffmpeg scene detection:

ffmpeg -i input.flv -filter:v "select='gt(scene,0.4)',showinfo" -f null -

scene (video only) value between 0 and 1 to indicate a new scene; a low value reflects a low probability for the current frame to introduce a new scene, while a higher value means the current frame is more likely to be one (see the example below) https://ffmpeg.org/ffmpeg-filters.html#select_002c-aselect

Set the scene change detection threshold as a percentage of maximum change on the luma plane. Good values are in the [8.0, 14.0] range. Scene change detection is only relevant in case combmatch=sc. The range for scthresh is [0.0, 100.0].

@dudewheresmycode
dudewheresmycode / install_node_20_rpi4.sh
Created November 13, 2023 02:53
Install NodeJS on Raspberry Pi 4 (armv8)
#!/bin/bash
wget "https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-arm64.tar.xz"
tar -xf node-v20.9.0-linux-arm64.tar.xz
cd node-v20.9.0-linux-arm64
sudo cp -R bin include lib share /usr/local/
node -v
npm -v
@dudewheresmycode
dudewheresmycode / package.sh
Last active July 10, 2023 15:13
Transcode fragmented MP4s and package into HLS and DASH using shaka-packager
#!/bin/bash
packager \
'in=./tmp/output_540p.mp4,stream=video,init_segment=./tmp/output/video_3000_0/video_init.mp4,segment_template=./tmp/output/video_3000_0/video_$Number$.m4s' \
'in=./tmp/output_720p.mp4,stream=video,init_segment=./tmp/output/video_1700_1/video_init.mp4,segment_template=./tmp/output/video_1700_1/video_$Number$.m4s' \
'in=./tmp/output_1080p.mp4,stream=video,init_segment=./tmp/output/video_1200_2/video_init.mp4,segment_template=./tmp/output/video_1200_2/video_$Number$.m4s' \
'in=./tmp/output_audio_128.mp4,stream=audio,language=en,roles=main,hls_name=main_en_2,init_segment=./tmp/output/audio_96_2/audio_init.mp4,segment_template=./tmp/output/audio_96_2/audio_$Number$.m4s' \
'in=./tmp/output_audio_196.mp4,stream=audio,language=en,roles=main,hls_name=main_en_3,init_segment=./tmp/output/audio_64_3/audio_init.mp4,segment_template=./tmp/output/audio_64_3/audio_$Number$.m4s' \
--fragment_duration 6 \
--segment_duration 6 \
@dudewheresmycode
dudewheresmycode / generate_iframes_list.sh
Created March 17, 2023 18:06
Generate a list of keyframes from a media file
#!/bin/bash
ffprobe \
-v error \
-select_streams v \
-show_entries frame=pict_type,pts_time \
-of csv=p=0 \
-skip_frame nokey \
$INPUT_FILE > iframes.txt
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>

Install x264

cd ~
git clone git://git.videolan.org/x264
cd x264
./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
make -j4
sudo make install

Generate 2min of colorbars and audio

ffmpeg \
-f lavfi -i "sine=frequency=1000:duration=120" \
-f lavfi \
-i testsrc=duration=5:size=1280x720:rate=24 \
-t 120 \
-map 0:0 \
-map 1:0 \
@dudewheresmycode
dudewheresmycode / deploy_to_roku.sh
Last active January 27, 2022 23:35
A bash script to automate deploying test apps to Roku devices on the local network.
#!/bin/bash
BUILD_ID=$(date +"%s")
SRC_DIR="MyApp"
ZIP_FILE="dist/devbuild_$BUILD_ID.zip"
ROKU_URL="http://192.168.1.167"
ROKU_DEV_USER="rokudev"
ROKU_DEV_PW="******"
@dudewheresmycode
dudewheresmycode / generate-live-stream.sh
Created February 8, 2021 02:33
Generate test colorbars and count for live streaming
#!/bin/sh
ffmpeg \
-i "http://relay.publicdomainradio.org/classical.mp3" \
-f lavfi \
-re \
-i testsrc=duration=120:size=1280x720:rate=24 \
-map 0:0 \
-map 1:0 \
-c:v libx264 \