Paul Sutton

BatchProcessing

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,


MastodonPeertubeJoin 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


MastodonPeertubeJoin 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


MastodonPeertubeJoin 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,


MastodonPeertubeJoin 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,


MastodonPeertubeJoin 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,


MastodonPeertubeJoin 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 4 – Goals

One of my goals with this, is now to create a script to take the following

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 a script need to do this with each file of that type in the directory or folder.

Again looking on stack overflow This may point to a solution

for f in *.shp; do printf '%s\n' "${f%.shp}_poly.shp"; done

You will, of course, need to set execute permissions

chmod +x script.sh

Tags

#Bash,#Bashscripting,#BatchProcessing


MastodonPeertubeJoin 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 3 – array

I have now figured out how to take a directory listing and put the contents in to an array. I had some help from a Stack Overflow post

#take a directory listing and store files in an array

#! /bin/bash

var=(*)
printf '[%q]\n' "${var[@]}"  # store all files in directory in array var
echo $var[png];

You will, of course, need to set execute permissions

chmod +x script.sh

Tags

#Bash,#BashScripting,#BatchProcessing


MastodonPeertubeJoin 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

Index

Donate using Liberapay

A #AbsorbtionSpectra #Abuse #Academy #Activism #Adenine #Afghanistan #Africa #Alphablocks #AMES #AminoAcid #AmnestyInternational #AMOC #Analytics #apg #Api #Apt #Aptitude #AralBalkan #Archaeology #Arduino #ARM #Artemis #arXiv #Assembler #AstroBiology #AstroChemistry #Astronify #Astronomy #Astrophysics #Atlantic #AtomicStructure B #BlueGhost #bash #BASH #BASHShell #BatchProcessing #Beamer #BepiColombo #better #BibTeX #BigBluButton #BigOil #BioChemistry #Biology #BioMass #Blender #Blog #Bonfire #Bookworm #Bookwyrm #Browser #Bullseye #Buster C #Castopod #Charity #Chat #Chemistry #Chrome #Chromium #Climate #Code #CodeClub #Coding #Commons #Conditions #Conference #Console #Cornwall #Corona #CoronaVirus #Cosmology #Covid19 #cpd #CPD #Creative #CreativeCommons #CreativeEducation #CriticalThinking #CrudeOil #Cryptpad #Crystal #CTAN #CyberSecurity #Cytosine D #DarkMatter #Data #DBS #dcglug #dclug #Debconf #Debian #Decentralised #Decentralized #DeepLearning #Derived #Detox #Development #Devon #Diaspora #Digital #DiodeZone #Discussions #disroot #Disroot #dna #DNA #Docker #Documentation #Donate #Donation #Draft #DRM #Drupal E #Editing #Education #EdX #Electronics #Elements #emacs #Email #EmissionSpectra #Employment #Energy #EnergySavingWeek #Engine #Engine #ESA #Ethics #Ethiopia #EventManagement #Events #EveryonesInvited #Exoplanet #Exploration F #FalconsEye #Federated #Fediverse #Firefox #Flockingbird #Football #FootBall #Fosdem #FOSSandCrafts #FossileFuels #Foundation #Framablog #FramaBlog #Framework #FreeBSD #FreeBSD #Freedom #FreeSoftware #Friendica #Friendica #FSF #FSFE #Funkwhale #Fusion #FutureLearn G #Galaxy #Galculator #GameEngine #Games #Games #Gamma #GDPR #GettingStarted #Ghostreply #Gimp #Git #Gitlab #GitLab #gm #GNOME #GNU #GnuSocial #GoAccess #GoatCounter #GoDot #gold #GPL #GraphicsMagick #Greek #Guanine #GUI H #Hack #HackerPublicRadio #Hacking #Hardware #Hexchat #HomeChemistry #HomeChemistry1 #HomeChemistry10 #HomeChemistry11 #HomeChemistry12 #HomeChemistry13 #HomeChemistry14 #HomeChemistry15 #HomeChemistry16 #HomeChemistry17 #HomeChemistry18 #HomeChemistry2 #HomeChemistry3 #HomeChemistry4 #HomeChemistry5 #HomeChemistry6 #HomeChemistry7 #HomeChemistry8 #HomeChemistry9 #Hosting #HPR #htop #Hubble #Hubzilla #HumanRights #Hypothesis I #Image #ImageManipulation #Index #InfoGraphic #information #Inkscape #Invidious #IRC J #JamesWebb #Jit.si #Jitsi #JoeEditor #jpl #JPL #Jupyter #JupyterNotebook #JWST K #Kanban #kbin #KCSIE #KDE #KeepingChildrenSafeinEducation, #Kenya #kstars L #LaTeX #Law #Learning #Lecture #Legal #Legislation #Lemmy #LGPL #LiberaPay #Libre #LibreAdventure #LibreLounge #Librem #Libreoffice #LibreOffice #LibreOfficeCalc #LibreOfficeDraw #LibreOfficeGettingStarted #LibreOfficeImpres #LibreOfficeWriter #LibrePlanet #Linux #LinuxMint #Lua #Luanti #Luanti #LXDE #Lynx M #Magnesium #Management #Manganese #Map #Mapscii #Mars #Mastodon #Materials #Matomo #Matrix #Maya #Meeting #Meetings #mercury #Mercury #Meta #Micro.blog #mining #Misskey #mobile #Mobile #Mobilizon #Mobilizon #MolarSolutionCalculator #Moon N #NaCl #Nano #NationsLeague #Nebula #NetHack #network #NewSkillsAcademy #Nextcloud #NFL #NGINX #Nuclear #NuclearFusion #Nucleobases #NASA O #Ocean #Oil #OilProducts #Online #Online #OnlineSafetyBill #Open #OpenData #OpenLearn #OpenStreetMap #OpenUniversity #Orbitals #OU #Overleaf #Owncast #OwnCloud P #Package #Parker #PaigntonLibrarySTEMGroup #Pandas #Paper #ParticlePhysics #Particles #Password #Payment #Paypal #PDF #PeerTube #PeriodicTable #Phonics #Photo #Photograph #Photographs #Photos #Physics #pinebook #pinephone #PixelFed #Planet #Plausible #Pleroma #Plume #Podcast #PowderToy #Privacy #Production #Products #Programming #ProtoSchool #Public #Purism #Python #Python3 Q #Quark #Quarks R #RadioAstronomy #Reading #Recovery #RedBubble #RedCabbage #Research #Rights #RISC #RISCV #rna #RNA #RocksAndDiamonds #Rookie #RookieCamp #Rust S #Safeguarding #SaferInternetDay #Safety #Salt #Schools #Science #Science #ScienceDaily #Scismic #Scratch #Scratch2 #Scratch3 #SDTJ #Seagl #Security #Simulator #Sitejs #Skymaps #smallweb #Soccer #Social #SocialHome #SocialHub #SodiumChloride #Solarus #Solid #SouthDevonTechJam #Space #Stars #Stellarium #Stickers #Stripe #stsci #Symmetry #Synaptic T #Tailings #Talk #Teaching #TeachingAssistant #Techlearningcollective #Telescope #Terminal #Terms #TeX #TextEditor #TheOpenUniversity #Theory #TheOU #Thesis #Thunar #Thunderbird #Thymine #Tilde #Toot #Top #Topic #Torbay #TorbayTrojans #Transit #Translation #Trojans #Trunk #Tuxiversity U #Ulytsheavy #Umami #UN #UnitedKingdom #UnitedNations #UniverseOfLearning #Uracil #Use #users V #Vaccine #Virgo #VLC #VokoScreen #Volunteer #Volunteering #VultureNethack #vultureseye W #Warming #wayland #weatherinfo #Website #WhiteVinegar #wicd #wireless #Wordpress #Work #WorldCup #WorldSpaceWeek #Wormhole #Write.as #Write freely #Writing X #Xchat #XenonLamp #XFCE #XFCE4 #XMPP #xorg #Xournal #xray Y #YearOfTheFediverse Z #Zoo