Paul Sutton

Personal Blog

Bash scripting 10 – Add text to video

Following on from stripping sound, I have looked up on stack overflow how to add text to a video. The script below is slightly modified, so that the text is added to a single video file.

echo strip sound content from video
echo
append=nosnd # set text to append to filename

for file in *.MP4 # apply to all files ending with MP4
do
    filename="${file%.*}"
    ffmpeg -i test1.MP4 -vf "drawtext=fontfile=/path/to/font.ttf:text='Torbay Trojans':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy test1-text.MP4   
    #ffmpeg -i $file -c copy -an ${filename}_$append.MP4
done

# https://stackoverflow.com/questions/17623676/text-on-video-ffmpeg

This adds “Torbay Trojans” text to the centre of the video. See link above, as the text can be positioned where you want.

Tags

#Bash,#Bashscripting,#BatchProcessing,


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Ditch summit session 3

So attended my first session at the 2024 Ditch summit, video discussion on Cautious Steps Toward AI Implementation in Education with Ken Shelton and Dee Lanier.

The videos of the sessions will be up until the 10th January

Excellent conversation and some really valid points raised about bias, and how we define for example cheating and ways we can address this by reframing how we do approach tasks, such as reframe cheating as potentially compromising learning.

Tags

#Education,#Summit,#Conference,#Digital,#Virtiual.#DitchSummit


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

T Corona Borealis

This was in the news back in the summer, it seems that Astronomers may have a better idea as to when the nova may occur. More details in this BBC Science article

With any luck, the skies may actually be clear enough to see this.

Tags

#TCoronaBorealis,#Astronomy


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Bash scripting 9 – check for root

Some tasks require the user to have root or admin permissions in order for the task to be completed successfully. There are several ways to do this, some are detailed on AskUbuntu

if ((${EUID:-0} || "$(id -u)")); then
  echo You are not root.
else
  echo Hello, root.
fi

Tags

#Bash,#Bashscripting,#BatchProcessing,#CheckRoot


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Stop deep sea mining

The deep sea is a treasure trove of biodiversity and home to untold wonders and possibilities. It is also one of our best allies against climate change. But a threat is coming: deep sea mining.

The good news is we can stop this industry before it’s too late. But we don’t have much time.

Deep sea mining companies, including Canada-based ‘The Metals Company’, are pressuring our governments to let them go several kilometers below the surface of the ocean, and chew up the seabed to extract metals. If this industry is given the green light, gigantic machines weighing more than a blue whale will be lowered onto the ocean floor to plunder these pristine ocean ecosystems.

This is a once-in-a-generation opportunity. Help us stop another extractive industry from damaging the global oceans.

Canada announced its support for a moratorium on deep sea mining in 2023 [1]. Now it must join other global governments in ensuring these calls of support become a reality to ensure this industry stops before it starts and the deep ocean is protected.

Sign this petition to tell the Canadian government to hold the line and actively engage with other countries to convince them to make a deep sea mining moratorium a reality.

Papers and articles on deep sea biodiversity

#StopDeepSeaMining,#Greenpeace


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Hacker Public Radio – NYE show

Hacker Public Radio will be holding their annual 26 Hour New Years Eve Show. This will be their 13th, and starts at 05:00 Eastern US. https://hackerpublicradio.org

I do plan joining the #Mumble audio chat at times, but unsure exactly when. I am working 31st December 2024, and Arianna & I are going to a friends house that evening.

If you are able to please pop-in and chat.

For those who are voice shy, there will be an option on the website to listen in to the live broadcast.

#HackerPublicRadio,#HPR,#HappyHogmanay


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Bash scripting 8 – Backup

So moving on, making backups of files is generally a good idea, especially with the scripts we have been making

echo "Basic backup script"
echo
append=-bak # set text to append to file
echo "list files"
echo
ls
echo
for file in *.JPG # apply to all files ending with JPG
do
    filename="${file%.*}"
    cp $file ${filename}.JPG$append
done
echo "backed up files"
ls

Tags

#Bash,#Bashscripting,#BatchProcessing,#Backup


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Bash scripting 7 – Image resize

So moving on to resizing images, I have created two scripts. The first extracts the image size from the photo metadata.

echo display metadata image size in photos
echo
echo "requires exiftool as a dependency"
echo "requires gm (graphics magick) as a dependency"


for file in *.JPG # apply to all files ending with JPG
do
    filename="${file%.*}"
    exiftool -TAG -s -ImageSize ${file}
done

The second script resizes each image to the specified new size. Then displays the new metadata to help confirm successful operation.

echo resize photos
echo
echo "requires exiftool as a dependency"
echo "requires gm (graphics magick) as a dependency"

for file in *.JPG # apply to all files ending with JPG
do
    filename="${file%.*}"
    gm mogrify -resize 1024x768 $file  
    exiftool -TAG -s -ImageSize ${file}
done

Tags

#Bash,#Bashscripting,#BatchProcessing,


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Bash scripting 6 – Strip sound from video

I have further improved the script from the previous post, the text that is appended to the filename is now set via a variable.

echo strip sound content from video
echo
append=nosnd # set text to append to file

for file in *.MP4 # apply to all files ending with MP4
do
    filename="${file%.*}"
    ffmpeg -i $file -c copy -an ${filename}$append.MP4
done

As a further enhancement,

ffmpeg -i $file -c copy -an ${filename}_$append.MP4

Will put an underscore before the appended text.

Tags

#Bash,#Bashscripting,#BatchProcessing,


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay

Bash scripting 5 – Strip sound from video

I had a go at this, storing filenames in an array, which isn't ideal for this problem, so I asked for help via the lug, as I also want the output filename to be different.

So the current solution is:

ffmpeg -i 20OCT5.mp4 -c copy -an 20OCT5-ns.mp4

Which only works on 1 file, so I need to run and modify the above for each fine in a directory. As I take more video, then the need to have better automation would be useful.

So, the above line of code :

  • Takes a single .mp4 file
  • Removes the sound content
  • Saves the output to a new file that appends the filename with -ns

So the new solution is

echo strip sound content from video
echo
for file in *.MP4
do
    filename="${file%.*}"
    ffmpeg -i $file -c copy -an ${filename}-ns.MP4
done

This takes a set of MP4 video files, strips out the sound and saves as newfile-ns.MP4

If you need to, then you will have to set the execute permission on your new script.

chmod +x script.sh

This can also be achieved with a single line of bash

ls ./*.mp4 | sed -e 's\.mp4\\g' | while read INFILE; do ffmpeg -i $INFILE.mp4 -c copy -an $INFILE-ns.mp4; done 

So, a big thank you to the LUG members who have helped with this.

My original solution is below,

echo strip sound content from video
echo
videos=(
  # list of files
"test1.MP4"
"test2.MP4" 
"test3.MP4"
"test4.MP4"     
)

# Loop to download each file
for url in "${videos[@]}"; do
   #echo "$url" 
   ffmpeg -i $url -c copy -an "$url" 

# ffmpeg -i 20OCT5.mp4 -c copy -an 20OCT5-ns.mp4

Tags

#Bash,#Bashscripting,#BatchProcessing,


Mastodon ShellLabs Join Mastodon
AI statement : Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity. Consent CANNOT be assumed, it has to be granted.

Donate using Liberapay