Pages

Wednesday 14 June 2023

batch converting audio codecs only in a folder of videos using ffmpeg

 So you have a folder of videos with a problematic audio format?  In my case i have H264 videos using Apples Audio Codec AAC that will not be compatible to play on any non apple devices like Roku etc.   This is annoying when you have many flavours of devices in your house.

The basic command looks like this:

ffmpeg -i "video.mkv" -c:v copy -c:a ac3 "video-ac3.mkv"

but we need to process many files in a folder so we'll create a loop using the following command:

for i in *.mkv; do ffmpeg -i "$i" -c:v copy -c:a ac3 "${i%.*}-ac3.mkv"; done

for i in *.mkv; do: This part initiates a loop that iterates over all files with the ".mkv" extension in the current directory. The loop variable i represents each file in the loop.

ffmpeg -i "$i" -c:v copy -c:a ac3 "${i%.*}-ac3.mkv";: Within the loop, this command is executed for each MKV file.

-i "$i": This specifies the input file for each iteration of the loop. The $i variable represents the current MKV file.

-c:v copy: This option ensures that the video stream is copied without re-encoding, maintaining the original video quality.

-c:a ac3: This option specifies the audio codec to use for the output file. In this case, ac3 is specified, indicating that the audio stream will be encoded using the AC3 codec.

"${i%.*}-ac3.mkv": This specifies the output file path. The ${i%.*} expression extracts the file name without the extension, and -ac3.mkv is appended to create the output file name. For example, if the input file is "video.mkv", the output file will be "video-ac3.mkv".

The command essentially processes each MKV file in the current directory, copies the video stream, and encodes the audio stream using the AC3 codec. The resulting output files will have the same video streams as the input files, but with the audio streams encoded in AC3 format and appended with "-ac3" in their names.

Tuesday 28 February 2023

 A Simple MOTD script for linux server

In order to produce a “System Status” Message Of The Day (MOTD) file in Debian you should write this script (as systemstats.sh) in /usr/local/bin


#!/bin/bash
#
# Server Status Script
# Version 0.1.3 m
# Updated: July 26th 2011 m

CPUTIME=$(ps -eo pcpu | awk ‘NR>1’ | awk ‘{tot=tot+$1} END {print tot}’)
CPUCORES=$(cat /proc/cpuinfo | grep -c processor)
UP=$(echo `uptime` | awk ‘{ print $3 ” ” $4 }’)
echo ”
****************************************************************************
System Status
Updated: `date`

– Server Name = `hostname`
– OS Version = `grep openSUSE /etc/SuSE-release`
– Load Averages = `cat /proc/loadavg | awk {‘print $1″ “$2” “$3’}`
– System Uptime = `uptime | awk {‘print $3” “$4’}`
– Platform Data = `uname -orpi| awk {‘print $1” “$4’}`
– CPU Usage (average) = `echo $CPUTIME / $CPUCORES | bc`%
– Memory free (real) = `free -m | head -n 2 | tail -n 1 | awk {‘print$4’}` Mb
– Memory free (cache) = `free -m | head -n 3 | tail -n 1 | awk {‘print$3’}` Mb
– Swap in use = `free -m | tail -n 1 | awk {‘print $3’}` Mb
– Disk Space Used = `df -h / | awk ‘{ a = $4 } END { print a }’`
****************************************************************************
” > /etc/motd

# End of Script

Remember to make it executable (as root or sudo)

chmod +x /usr/local/bin/systemstats.sh

To make the script update the information automatically, you should edit /etc/crontab as root, and add this two lines at the end of the file

# Status Script
*/5 * * * * root /usr/local/bin/systemstats.sh

After you update the /etc/motd file (by running as root /usr/local/bin/systemstats.sh), it should look like something like this:

david@virtual:~> cat /etc/motd

****************************************************************************
System Status
Updated: Thu Oct 20 01:55:01 CEST 2011

– Server Name = virtual
– OS Version = openSUSE 11.4 (x86_64)
– Load Averages = 0.00 0.01 0.05
– System Uptime = 2:22, 1
– Platform Data = 2.6.37.6-0.7-desktop GNU/Linux
– CPU Usage (average) = 0%
– Memory free (real) = 3667 Mb
– Memory free (cache) = 138 Mb
– Swap in use = 0 Mb
– Disk Space Used = 9.5G

****************************************************************************

Monday 18 May 2020

[Tutorial] "This App Is Incompatible With This iPhone" on iOS 6 and below: The problem + workaround


Tutorial
iOS 6 and below are affected by a problem where if the latest version of an app requires a hardware component that your device doesn't have, they will not serve up the last compatible version of that app as they normally would. In the majority of cases this is when the app you're trying to download now requires iOS 11.0+ (Netflix, YouTube, Twitter etc) and therefore demands a 64 bit CPU (arm64), a hardware component that no iOS 4/5/6 device has. As a result, iOS 6 and below won't offer the last compatible version of these apps and they can't be downloaded without carrying out additional steps.
The good news is this problem does not affect iOS 7 & above, which will offer an older version to download even if the latest version requires missing hardware, and will display the message "This version of [insert app name] is not compatible with this device. Would you like to download the last compatible version?"
***WORKAROUND***
Add arm64 as a hardware capability of your device so that it will once again serve up the last compatible version of iOS 11.0+ apps. Carry out the following steps:
  1. Open iFile on your iOS 4/5/6 device and navigate to /System/Library/CoreServices/Springboard.app/
  2. Locate the file [xxx]AP.plist (filename varies depending on your device, see list below)
  3. Open the file with Property List Viewer and go to capabilities. Click the + icon in the bottom right corner, name it arm64 and set type to Boolean. Then click create, and toggle it on in the list.
  4. Respring or reboot your device and you should now be able to download the affected apps as normal from your purchased history.
Thanks to u/iPodee for this information and easier solution.
Filenames by device:
iPhone 3G - N82AP
iPhone 3GS - N88AP
iPhone 4 - N90AP, N90BAP, N92AP
iPhone 4s - N94AP
iPhone 5 - N41AP, N42AP
iPod Touch (2nd Gen) - N72AP
iPod Touch (3rd Gen) - N18AP
iPod Touch (4th Gen) - N81AP
iPad (1st Gen) - K48AP
iPad (2nd Gen) - K93AP, K94AP, K95AP, K93AAP
iPad (3rd Gen) - J1AP, J2AP, J2AAP
iPad (4th Gen) - P101AP, P102AP, P103AP
iPad Mini (1st Gen) - P105AP, P106AP, P107AP
*Please note this tutorial is specifically intended to fix "This App Is Incompatible With This iPhone/iPad/iPod". If you are getting a "This app requires iOS x.x" message, it's because;
a) The app is not in your purchased history (download on a newer device or with iTunes 12.6.5.3 first)
b) The app vendor has removed older versions of the app from the App Store (e.g eBay, PayPal) - download and backup all the apps you need while you still can!
c) The app is fairly new and was never compatible with your firmware.
*Also note that these steps manually replicate most of what the "Checkmate, Store!" tweak does, which was released after I wrote this tutorial. However, the tweak has additional usage on iOS 3 as it enables the "download older version" functionality that exists in iOS 4 onwards.

Monday 11 May 2020

How to set a random mapcycle with nQuakesv

This article assumes you are running the nquakesv server package on a linux flavour.

I don't know about you but I seem to still be playing Quake multiplayer 25 years after this game was released - Not the entire time,  but I'm kind of revisiting it right now after a decade or so of not playing.

So my biggest issue with nquake is having random levels every time i start a multiplayer match.   They say most modern servers work on a map voting system where the players vote for a map but I just can't deal with that and would rather have my server just randomly pumping out a new level after every match.

nquake does ship with a built in random function you can add to your server.cfg and that parameter is called k_random_maplist 1  however the biggest problem with this function is that it repeats levels pretty easily since random is well random...   I thought there could be a better way.

KTX currently loads maps in a way that is numbered like set k_ml_0 "dm2" and set k_ml_1 "dm6" etc..   so I thought i would create an array of the level names and then have a script shuffle them.


  1. run the following command in the /nquakesv/qw/maps/ folder:
  2. ls > level_names.txt
  3. open this file and find and replace all .bsp and .ent and .txt endings after each filename - you should now have a long list of just the map names alone.
  4. copy the contents of the file and paste it into this script I got from one of the nquake discord members
#!/bin/bash
#generate ffa map rotation using specified list in the following format:
# mapname minplayers maxplayers

#shuffle map cycle?
shuffle=1

#this is our fallback map
firstmap="dm5"

#paste your map names into the array below
maps="
13edge
a2
ab2
ac4
aerowalk
ag
agenda
agent
aggressr
aghast
alk08dm
"

shuffle_com="cat"
if [ "$shuffle" -eq 1 ];then
shuffle_com="shuf"
fi
shuffled=$(echo "$maps"|sort -u|grep --color=never -v '^#'|$shuffle_com)

#newmaps=$(echo -e "${firstmap}\n${shuffled}")
newmaps=$(echo -e "${shuffled}")

count=0

while read -r line; do
if [ -z "$line" ];then
continue
fi
map=""
min=""
max=""
for part in $line;do
if [ -z $map ];then
map=$part
continue
fi
if [ -z $min ];then
min=$part
continue
fi
if [ -z $max ];then
max=$part
continue
fi
done
echo 'set k_ml_'$count' "'$map'"'
if [ -z $min ];then
min=0
fi
echo 'set k_ml_minp_'$count' "'$min'"'
if [ -z $max ];then
max=0
fi
echo 'set k_ml_maxp_'$count' "'$max'"'
let count=count+1
done <<< "$newmaps"

  1. Save the script above as something like generate_maps.sh and give it a chmod +x
  2. The Script on its own simply outputs everything in a way that KTX can use and also sets the min and max player counts per level.  If you want to use the min and max settings of this script then where you paste your map names in the array you can put two numbers after each entry like aerowalk 2 4 this would set the aerowalk map to have a minimum of 2 players and a max of 4
  3. What i did next was create a second shell script called start_mapcycle.sh which also has a chmod +x and save it in the root of nquakesv.  The contents of the script are:

#!/bin/bash
./generate_mapcycle.sh > ./ktx/configs/usermodes/ffa/mapcycle.cfg

  1. This will now write the maps into a text file that KTX understands and in a shuffled way.
  2. All you need to do now is have whatever usermode cfg you are running exec your new file in my case i'm using configs/usermodes/ffa/default.cfg
  3. inside default.cfg at the map rotation section simply have it read
exec configs/usermodes/ffa/mapcycle.cfg

You'll need to run start_mapcycle.sh before every start of your server if you want a freshly rotated list of maps - but its still an awesome way to do it.   All credit to @ciscon at nquake #helpdesk

How to enable bots on nquake


This article is my experience with nQuakesv server package running on Ubuntu 18.04


  1. Make sure your server is not running.
  2. With your new server setup and installed you want to navigate to the nquakesv/ktx folder
  3. You will see 3 files named qwprogs,  you want to backup your existing qwprogs.so by renaming it qwprogs.so.bak or something like that.
  4. now you will rename the file called qwprogs-bots-enabled.so to be named qwprogs.so
  5. Start your server again and when connected bring up your player console and type /botcmd enable - this will enable the bot system.
  6. You can now add bots to only the levels that are in your ktx/bots/ folder - these maps have waypoints - if you are using custom maps you have to train the bots via waypoints.
  7. To add a bot to a level simply type /botcmd addbot   and then set its skill level with /botcmd skill 1 through 10

Friday 5 January 2018

find and delete files based off grep search

at some point it could be useful to search for the text within a group of file names and delete those,  here's an example terminal command to find and execute a deletion of files which meet a certain criteria

find . -name "*2017-11*" -exec /bin/rm {} \;

Sunday 10 December 2017

Make Bootable OSX drive from install app

From a terminal:

sudo /Applications/Install\ OS\ X\ Yosemite/Contents/Resources/createinstallmedia --volume /Volumes/DRIVENAME --applicationpath /Applications/Install\ OS\ X\ Yosemite\  --nointeraction