Skip to content

Instantly share code, notes, and snippets.

View basperheim's full-sized avatar

Benji Asperheim basperheim

View GitHub Profile
@basperheim
basperheim / reduce_videos.py
Created February 24, 2024 09:02
Use Python & FFmpeg to reduce video sizes
import os
import subprocess
DRY_RUN = False
# Function to find all video files in the current directory
def find_video_files():
video_files = []
for file in os.listdir('.'):
if file.endswith('.mkv') or file.endswith('.mp4'):
@basperheim
basperheim / reduce_mkv_files.py
Last active February 24, 2024 08:03
Reduce size of MKV files in current dir using FFmpeg and Python
import os
import subprocess
DRY_RUN = False
# Function to find all mkv files in the current directory
def find_mkv_files():
mkv_files = []
for file in os.listdir('.'):
if file.endswith('.mkv'):
@basperheim
basperheim / create_clips_using_subtitle_match.py
Created December 23, 2023 17:52
Creates MP3 or MP4 clips from a file by searching the respective SRT file for a string match
import os
import fnmatch
import sys
import json
import re
import subprocess
import argparse
# Check if ffmpeg is installed
try:
@basperheim
basperheim / angular-component-template-example.ts
Last active December 15, 2023 11:47
Boilerplate/Template Angular Component
import { Component, OnInit, OnDestroy } from "@angular/core";
import { Subscription, Observable, of } from "rxjs";
import { delay } from "rxjs/operators";
@Component({
selector: "replace-me",
templateUrl: "./replace-me.html",
styleUrls: ["./replace-me.scss"],
})
export class ReplaceMe implements OnInit, OnDestroy {
@basperheim
basperheim / postgres-postgresql-psql-essential-useful-commands.md
Last active January 10, 2025 20:04
Postgres psql essential commands

Useful Postgres (psql) commands

Here are some useful and essential psql commands to perform CRUD operations on PostgreSQL data.

DISCLAIMER: Use these commands with extreme caution.

It is highly recommended to:

  1. Back up your database before running any of these commands (especially the UPDATE, DROP, TRUNCATE, and DELETE commands).
  2. Double-check the command is the intended action you want to do.
  3. Review the output of the SELECT query before executing any DROP statements.
@basperheim
basperheim / check_nyse_market_open.py
Created September 10, 2023 18:13
Python function that checks if the NYSE is currently open.
from datetime import datetime, time
import holidays
import pytz
def market_is_open():
"""
Checks whether the U.S. stock market (NYSE) is currently open based on Eastern Standard Time (EST).
This function considers both the current date and time, taking into account:
- U.S. holidays observed by NYSE.

FFmpeg: Create filler video and merge them

Creating monochrome filler videos, add audio tracks to them, and merge them together.

Creating a filler video without audio

Is it possible to add a black video with no volume, as filler, to the end of an MP4, using FFmpeg?

Yes, it is possible to add a black video with no volume as filler to the end of an MP4 using FFmpeg. You can achieve this by creating a black video clip with the desired duration and then concatenating it with the original video.

@basperheim
basperheim / ffmpeg-merge-folder-of-videos.md
Last active May 18, 2025 14:45
Use FFmpeg to merge a directory of AVI files by appending each file name to a text file

FFmpeg: merge a folder of AVI files with names that include order number

You can merge a series of .avi files with ffmpeg using the concat filter. However, the concat filter requires that all inputs have the same streams (same codecs, same time base, etc.).

Here is an example of how you can do it (each video file should end in ..-01.avi, ..-02.avi, etc..):

Create the text file using echo

First, create a file that contains the list of all your .avi files. You can do this manually, but if your files are named in a sequence like 01.avi, 02.avi, 03.avi, and so on, you can generate this list automatically using a bash command. Here's how you can do it:

@basperheim
basperheim / useful-ffmpeg-commands.md
Last active August 15, 2024 13:37
Useful FFmpeg commands

Useful FFmpeg Commands

Remove Metadata from Video File

To remove metadata from a video file using FFmpeg, you can use the following command:

ffmpeg -i input.mp4 -map_metadata -1 -c:v copy -c:a copy output.mp4
@basperheim
basperheim / commands-to-get-docker-compose-working-raspbian.md
Last active October 15, 2023 10:30
Ubuntu commands to get Docker Compose to work on a Raspberry Pi (Rasbian)

Linux/Ubuntu commands to get Docker Compose working on a Raspberry Pi

Command history

# Get Docker script
cd ~/Downloads
curl -fsSL https://get.docker.com -o get-docker.sh
sudo chmod +x get-docker.sh 
./get-docker.sh