[Home]

CLI Stuff

Last Updated - [4/3/2024]

Shy's collection of various cli things or scripts that are super useful!

all preformatted so expect pagebreaks!

FFMPEG Related:

Find all webp's in a folder and create a png from them:

find ./ -name "*.webp" -exec ffmpeg -i {} {}.png \;

This isn't perfect, if you have an "animated" webp then it doesn't generate the png, I use Xconvert usually but this sometimes comes in handy when I am limted to a CLI

put the audio of one video into another:

ffmpeg -an -i video.mp4 -vn -i audio.mp4 -c:a copy -c:v copy output.mov

output must be a "container" format like mov or mkv, and both streams must be compat with that format, in my case I am using aac audio and h265 video

add/replace audio in a video without re-encode:

ffmpeg -i video.mp4 -i audio.mp3 -c copy -map 0:v -map 1:a output.mkv

output must be a "container" format like mov or mkv UNLESS the audio file is something mp4 supports like AAC or mp3

Pixel Perfect 2x Upscale Options:

-vf scale=2*iw:2*ih:flags=neighbor

convert a video to prores + aac

ffmpeg.exe -i file.mp4 -map 0:0 -c:v prores -profile:v 0 -c:a none output.mov
ffmpeg -i file.mp4 -vn -map 0:1 -acodec aac -b:a 320k output.aac

refer to my bashrc function that does the same thing, I use ffmpeg.exe in WSL2 since the windows version runs at full speed

my ingest script

#!/bin/bash
cd /mnt/x/VIDEO/INGEST
for f in *.mkv; do ffmpeg.exe -i "$f" -map 0:0 -c:v prores -profile:v 3 -filter:v fps=30 -c:a none "../READYFOREDIT/${f%.*}.mov" && ffmpeg.exe -i "$f" -vn -map 0:1 -acodec copy "../READYFOREDIT/${f%.*}_track1.aac" && ffmpeg.exe -i "$f" -vn -map 0:2 -acodec copy "../READYFOREDIT/${f%.*}_track2.aac"; done

I typically use profile:v 1 and fps=60 but this one is the "HD" ingest. I don't define pix format I let it use defaults which is 422 so thats prefectly fine for youtube (which is 420) as for the profile it controls the bitrate, 0 is 45, 1 is 102, 2 is 147, and 3 is 220mbps. honestly I'd say even 0 (proxy, 45mbps) is fine for what I do, very little quality loss from the original obs recording but i still prefer profile 1. FPS matters, 30fps files will be half the size as 60. I cant give an exact size per hour becuase it actually seems to kind of depend on the content? MAYBE? I can't tell I've ran tests and can't figure it out. Just assume at least 150gb per hour to b safe. However using profile 1 at 30 fps about 4 hours of footage ended up being under 200gb.

script to convert webms to mp4 for editing

#!/bin/bash
cd /mnt/x/VIDEO/INGEST
for f in *.webm; do ffmpeg.exe -i "$f" -crf 26 -preset medium "${f%.*}.mp4"; done

This is for when I need to use a youtube vid or something but the format is in webm, i need to convert it to a reasonable quality mp4 to use it in my videos, this seems to be decent.

script to convert my iphone's 4k videos into 1080p "lossless" h264 for quick editing tasks

#!/bin/bash
cd /mnt/x/VIDEO/INGEST
for f in *.MOV; do ffmpeg.exe -i "$f" -filter:v "scale=iw/2:ih/2" -c:v libx264 -crf 22 -c:a copy "../${f%.*}.mp4"; done;

saves ouput in upper directory.

ETC:

Find instances of words inside of specific file types:

grep -r --include=*.file "word" .

DO NOT FORGET THE DOT! will search files with ONLY .file extentions and will return each file and each line that "word" is in. For example: grep -r --include=*.vmt "shystudios" . from my materials folder will return stuff like ./shystudios/tools/toolsnodraw_blue.vmt: "$basetexture" "shystudios/tools/nodraw_blue"

Find all text files of a given name and merge them to a single text file:

find . -name 'Archive.txt' -exec cat {} \; > test.txt

I used this to merge all of my ytdlp archive files, which I get when archiving a whole youtube channel into a single master file that the software can check during normal use.

List all files and folders in the current dir by size:

du -xsh ./* | sort -h

Find all thumbs.db files in current dir tree and delete them:

find . -iname 'thumbs.db' -delete

Find all empty directories in current dir tree and delete them:

find . -type d -empty -delete

Find the drive the current dir is mounted on:

findmnt -T .

dont forget the . very useful for when you are not 100% sure about what drive a folder is on. I use this to ensure my omv /dev-disk-by-uuid's are actaully attached to the disk that I am targeting, usually for backup related stuff.

Download a list of direct links to files:

wget -c -i filename.txt

-c for continue so it doesn't overwrite the file when you drop connection. -i is the list command, newline seperated url list.

Find the actual exec command name for a window manager:

grep "^Exec" /usr/share/xsessions/*

for manually configuring stuff like xinit or gdm or whatever

Log out of connected network servers on windows:

net use * /delete
klist purge

can also specify the server in net use

Show the common fingerprint of a pgp key

gpg --show-keys --fingerprint file.pgp

batch file for killing non responding tasks on windows save this as killtasks.bat

@echo off
TITLE Kill Tasks
tasklist.exe /FI "status eq NOT RESPONDING"
echo(
echo Kill These tasks?

CHOICE /M Select /C yn

If Errorlevel 2 goto end
If Errorlevel 1 goto kill

:kill
taskkill.exe /F /FI "status eq NOT RESPONDING"
pause
goto end

:end
exit
HOW TO PUT THIS IN UR RIGHT CLICK:
click the link for the file, put it in the system32 folder
then make a reg entry like:
HKEY_CLASSES_ROOT\DesktopBackground\Shell\taskkilla\Command
and set the default string key there to:
cmd.exe /K killtasks.bat
Then add the following string keys to the taskkilla (or whatever u named it) key:
Icon 		%SystemRoot%\\System32\\imageres.dll,-98
MUIVerb 	Kill not responding tasks
Position 	Bottom

Create a virtual box proxy disk for a real physical disk (ie: use a real usb drive or something like that):

VBoxManage.exe createmedium disk --filename "X:\vbox\usbx601.vmdk" --format=VMDK --variant RawDisk --property RawDrive=\\.\PhysicalDrive4

Filename is path where the image will go, it does not have a physical size. rawdrive is a windows specific drive number, refer to the windows disk manager to get the exact disk number. DO NO PUT IN THE WRONG NUMBER!!!

Mount a shared vbox folder from within a linux guest:

sudo mount -t vboxsf NAME_OF_SHARE path_to_mount_point

NAME_OF_SHARE is the actual "name" of the share as defined in virtualbox. I assume you need guest additions for this maybe??? but maybe not.

useful stuff for debugging windows wake timers:

powercfg /lastwake [shows events that woke the computer last]
powercfg /waketimers [ shows events that will wake the computer in the near future]
powercfg -devicequery wake_armed [shows what hardware can wake the pc]
[you can selectively disable what can and can't wake via device manager]
powercfg -requests [shows software that would stop your computer from sleeping]

gotta run these in admin cmd, powershell works too

Source Engine Related:

Launch gmod dedi:

./srcds_run -tickrate 33 -game garrysmod +maxplayers 4 +map gm_flatgrass

This is tuned for my lil unlisted test server

run another games's vis on a gmod map:

.\vvis.exe -low -game "C:\STEAM\steamapps\common\GarrysMod\garrysmod\" "c:\map\mapfile"

obviously run this from the bin fodler of your game

run another games's rad on a gmod map:

.\vrad.exe -ldr -final -StaticPropLighting -StaticPropPolys -game "C:\STEAM\steamapps\common\GarrysMod\garrysmod\" "C:\maps\mapname"

generate ssbump:

./height2ssbump.exe -r 100 ./file.tga 17

-r isn't needed but default is 250 the 17 is the bumpscale and really depends on your hightmap. 15-25 is usually good for most things. The heightmap must be in the alpha channel of the tga plz refer to this page for more info

batch file to convert vtf to a tga file, save this as vtf2tga.bat or something:

start "" "T:\STEAM\steamapps\common\GarrysMod\bin\vtf2tga.exe" -i %1%

edit the path to suit your need, drag a vtf file onto the batch file's icon.

Shy's Bashrc stuff:

alias clist='echo newingest tx rmbh ytm yt yta ytanf ytlq yt7 c2prores'
#i use the above to document my commands incase i forget
alias newingest='cd /mnt/x/VIDEO/INGEST'
alias tx='cd /mnt/x/SHARE/TX'
alias rmbh='rm /home/shy/.bash_history'

alias ytupdate='yt-dlp --cookies /home/shy/.stuff/ytcookies.txt --sponsorblock-remove all --embed-subs --download-archive Archive.txt https://www.youtube.com/playlist?list=MY_DOWNLOAD_PLAYLIST_ID'

function ytm(){
	yt-dlp --no-playlist -f 140 --download-archive Archive.txt --cookies "/home/shy/.stuff/ytcookies.txt" $1
}

function yt(){
	yt-dlp --no-playlist --embed-subs --cookies "/home/shy/.stuff/ytcookies.txt" --sponsorblock-remove all --download-archive Archive.txt $1
}

function ytlq(){
        yt-dlp --no-playlist -f 18 --embed-subs --cookies "/home/shy/.stuff/ytcookies.txt" --sponsorblock-remove all --download-archive Archive.txt $1
}

function yt7(){
        yt-dlp --no-playlist -f 22 --embed-subs --cookies "/home/shy/.stuff/ytcookies.txt" --sponsorblock-remove all --download-archive Archive.txt $1
}

function yta(){
	yt-dlp --download-archive Archive.txt -f 22 --embed-subs --cookies "/home/shy/.stuff/ytcookies.txt" --no-playlist $1
}

function ytanf(){
	yt-dlp --download-archive Archive.txt --embed-subs --cookies "/home/shy/.stuff/ytcookies.txt" --no-playlist $1
}

function ytam(){
        yt-dlp --download-archive Archive.txt -f 140 --cookies "/home/shy/.stuff/ytcookies.txt" $1
}

function yttw(){
	yt-dlp --download-archive Archive.txt --cookies "/home/shy/.stuff/twitter.com_cookies.txt" $1
}

function c2prores(){
	ffmpeg.exe -i "$1" -map 0:0 -c:v prores -profile:v 0 -c:a none "$1".mov && ffmpeg -i "$1" -vn -map 0:1 -acodec aac -b:a 320k "$1".aac
}