FFMPEG Movie Magic

FFMpeg: https://ffmpeg.org/ is an Extremely Ugly, Extremely *powerful* command line tool to process movies and stills.
My examplesa are for Linux, likely MACOS- Windows varies slightly.

Here are some of my most useful commands as a reference for Myself, really:

  • Break [MJPEG] Input Movie into single JPG still frames in the same directory:
    ffmpeg -i input.avi -vcodec copy frame%4d.jpg
    

    Convert between video types/containers:

    ffmpeg -i input.avi -c:v libx265 -c:a libfdk_aac output.mp4

    [h265 is super compressed, libfdk_aac is the highest quality AAC encoder you can use]

  • Above example, but Batch convert files into an (existing) folder “output” below this one, keeping main filename:
    for i in *.avi; do ffmpeg -i "$i" -c:v libx265 -c:a libfdk_aac./output/"${i%.*}.mp4"; done
  • Top Example, Batch, convert multiple videos into a huge collection of numbered frames  (for fun work re concatenating, etc) This will create: file1_0000.jpg (4 digitas count upward)
    file2_0000.jpg (same Story for file1.avi, file2.avi:
    for i in *.avi; do ffmpeg -i "$i" -c:v copy ./output/"${i%.*}_%3d.jpg"; done

My Dog Does Not Bite

Scenario 1: a Joke. Or is it?
Vector silhouette of a woman with a dog. - 50783515Woman walks in the park and sees a man and a dog sitting at a bench. “Does your dog bite?”, asks the woman
“No”.
So,  The woman  proceeds to pet that dog, which promptly bites her. “I thought you said your dog didn’t bite?” says she, angrily indeed.
Says He: “This is not my dog.”
Lady  Loses based on a wrong assumption.
Gentleman  loses due to lack of, well,
common decency in recognizing assumptions of others


Scenario 2: Serious. Sort of.
Man and Dog SetYou are in a park, the same hypothetical park may be.
A dog & its (Obvious) owner are there and Rover approaches you. So you say:
“Can you call your dog back please?”
The owner says something like” “Oh she is friendly” or similar. Wrong answer. basically,  a non-sequitur. You did not ask: “Is your dog friendly?”
Right one is “Yes” and “Heel” or something to comply,
Isn’t it? Anything else basically says: “!F..k you!”
Or am I crazy? Just get the Dog Away. As Above!
The reasoning is the same as above.

Treatment:
Technology is never about technology,
owning a dog is not about owning a dog. Let that sink in.
it’s always about being so called Human.
We Humans imagined, considered, designed, implemented and supported various choices  whether it was a about a fire-stick, tractor,  Boston terrier or nuclear weapon.
Forget the dog.
Think: “Human!”


Scenario 3:
Man Destroying Computer High Resolution Stock Photography and Images - AlamyTech Support: “We have never had any complaints about (xyzzy) before”
Problem: This assumes everything is Fine and that their “dog” does not or would not or could not  bite you or yours
But you just got bitten.
Dump that company.

In providing tech support I generally avoid the parental incantation:
“Because I Say So” about removing questionable software, for example.. and I try hard to cite the source of my concerns, usually with well respected web site links.
Security-wise, I love “Krebs On Security” by the way.
It’s also hard to be the point-person for design screw ups elsewhere.
“I am not responsible for this other person’s dog, right?”
I am well aware of the other company’s shortcomings that  are unknown to the caller.
They are calling ME and not calling Company 1XYZ
They may have tried, mind you. 
This is a minefield of problems, 
Should I take on the shortcomings of Company 1XYX?
Am I willing to get a client’s transfer of angst against 1XYZ to me?
Yes. on two conditions. 
1) I cannot guarantee success or that it will not get worse
2) It’s at least $500/hr with all meals and ‘entertainment’ included and may get posted to YouTube,
Those of you who know me will know which products & company I am referring to- and a few well known Web Hosts to boot.


Scenario #3Playing Tennis Cartoons and Comics - funny pictures from CartoonStock
A tennis star goes to the doctor and reports pain on raising her arm above horizontal- a limited range of motion, it might be called.
“So it hurts when you raise your left arm?” says the good doctor
“Yes” says she
“Well, that’s easy. just don’t do that then”
says the good doctor.

Treatment:
The only real computer security that exists is the computer you don’t have that’s not plugged in and you never owned or touched.
Practical, right? Just don’t do the thing that causes the Problem.
So the only real identity security is the one you don’t have
Unrealistic, right?

Nevertheless, guess what? #3 CAN be a useful insight.
If your database keeps screwing up, ask yourself,
“Does my information need to be in a database at all?”
Years ago I heard- and this may be apocryphal- that nuclear submarines- high tech like nothing else- would keep an inventory of supplies and spares on paper index cards.
Not infallible but orders of magnitude more reliable.
Somerset Maugham, the somewhat famous British writer started out hoping to be a painter in Paris, and was told:
“You are good but you will never be great”- So he took up writing…….


wreck.jpg
Credits: MARYX Blog (Click Image)

Scenario #4 AND Treatment, All In One!
the so called X Y Problem
In imagining Y is the solution to problem X, means to support problems with Y completely lose the original objective: Problem X.
Example:
“Ink Jet Printer Ink Is So Expensive!”
so, I tried elaborate “Solutions to Problem Y”: refurbished cartridges, refilling cartridges, “economy” printing, different brand of inkjet printer that could print using a single black and white cartridge even when the colors had run out. Yep. You know what I am talking about. I even got a “Chip Resetter” to defeat the manufacturer’s clever trickery that tried to force you to buy only their own  fresh cartridges. Here’s looking at you, HP, Epson…
All of it a Big Problem- several, really.. and Very Interesting:
Which led me to think:
The problem is really X: “Cheaper Printing- How?”
not: “Expensive cartridges are a Problem”. If I mostly print in black & white, why not use a laser printer?
(Color lasers are still too expensive for me)
In fact, at “root cause” one might even ask- Why print at all? If you need to give some pages to someone, why not send a PDF files..?
Just Sayin’.. (I hate that expression)
On the face of it, a laser printer may cost a bit more. 
Inkjet printers are “loss leaders” or “Sample Drugs” so you are now stuck with cartridges that cost more than the printer itself when you need them. I did check- Most laser printers don’t have a means to prevent you refilling them or buying inexpensive refurbished ones.
In my case: a monochrome Canon MF4700 has lasted me 8+ years and a 1200 page toner cartridge costs $8 refurbished from Amazon.
(Less Crap in the Landfill, guys!)
I use the vendor feedback and the knowledge I can return it if need be. NO PROBLEM!
So! How do I print in color, if indeed I must?
I send them to a Print Service like Kinko or CVS or Shutterstock. 
So! your Business generates forms that are required to have colored fields? (This is true if you do Insurance claims etc) 
Simple. Order a batch of pre printed color forms from Kinko, etc, then overprint with your black and white laser.
Some forms are even available online as PDFs.
Hell, many of them you can even order from Amazon if they are a common type such as bank check stock
Love photographs? I now have mine loaded into a digital Photo frame
Above are several examples of the X Y Problem at work-
Job #1 in Troubleshooting is, “Define the Problem”
Not: “Assume a solution and have at it” : )


Scenario #6Economic Jargon Cartoons and Comics - funny pictures from CartoonStock
“I have an opaque solution using jargon to your simple problem”
Sometimes when providing reference link to articles describing someone’s technical problem I realize there is enough jargon present to alienate that person.
Even the words: “Update” and “Upgrade” and the important difference between those 2 words- which are totally distinct- can cause bafflement.
Worse, context can change meanings in horrible ways. 
“Arguments” in computer science are words and numbers used as inputs to a program, not about people beating each other up.
It also has a different meaning in  debate which is not what is commonly understood to mean.
“Do not assume we speak a common language”
“Do not assume someone understands correctly just because they did not ask you what some word meant”
Most people I meet are smarter than they think about technology, given half a chance and not blindsided by jargon & tech elitism.


Conclusions:
Who noticed there was no Scenario #5? I went 1,2,3,4, to #6.
“Always Question your Own Assumptions First”
But It’s my blog, I can do what I like, right? Most tech companies and vendors essentially get to do whatever they like with their bottom line being the driving force, not the product.
If an oil company could make as much money by not drilling refining and selling oil, don’t you think they would?
There’s a very common misconception that “Big Companies Must Know What They Are Doing”.
or they are in the business of doing whatever it is they sell.
False- Their first responsibility is to their shareholders, not you.
Ironically- a great or at least useful product with no real need for improvement can kill a company as the need for further income may be gone. (Looking at you, Wordstar!) It’s why so many companies now have gone to a Subscription model where you pay monthly.
Damn them.

Not for profits are rather different which is why I prefer them
Commercial companies can afford to screw up more often and bigger than you and I can and they consist entirely of fallible arrogant humans just like you or me.
One year my business partnership (Pre Dot-Com Crash in 1999) only broke even in the same year IBM lost billions. Was I doing “Better’ than IBM? worth thinking about that.

Let us, we so-called Humans watch our assumptions closely.
We,
And our dogs. 

Credits: Various royalty free photo agencies or as Linked.
Thank you
Draft. Comments Welcomed!

WebSite security

  • Security
  • Reliability
  • Usability
  • Functionality
  • Availability

In my opinion, I have a few trusted Hosting Providers that take care of most of the things mentioned here FOR me, often even costing less than the one you might be using.
I do not need to go in and tweak much to Make It Right and is easy top check. Most Hosts miss many essential and simple things


Cartoon thief safecracker breaks into a safe vector illustration - 51877416* SECURITY
On no account should you be transferring/publishing  your material to or from  your site with anything that sends information unencrypted. Principally, your username and password must not cross the Internet readably or it will be intercepted and misused.
“FTP” (File Transfer Protocol) is “ancient” technology and just such a transfer program.
Firstly make sure your site has the service itself *OFF* so in fact it cannot be used or abused by anyone ‘out there’
This is even true if YOU do not use it for what you do.
The simplest replacement, If Available, is something called: “SFTP” (Secure File Transfer Protocol) but, your Host must Provide this
Don’t Worry- whatever you use for doing FTP, if it’s new enough,  will be able to do this in almost exactly the same way the FTP you were used to, does. It runs via a so called “Secure Shell”
(a kind of wrapper that encrypts everything within) so your literature may mention “SSH Login/Password… etc)
So, you say, you are using a WordPress Website that does not use this method at all? Watch Out. your Hosting Provider likely has an FTP access method turned on that you never use but that is vulnerable. get them Turn It OFF COMPLETELY.

  • If you Web Host has no ability to do this, does not know what you are talking about or says “It Is Not Possible” or charges or gives you the runaround…You know how that goes…
    The only acceptable answer by them is: “Ok!”
    else go elsewhere.

Your Web Service must have the “SSH/SFTP/SCP” service turned on. If they are Smart, it will NOT use the “Default Port” of 22.
Why Not? Because that is where miscreants will be looking for it.
“Never be where your enemy expects you to be” (The Art of War)
There are over 65,000 alternatives to force a miscreant to look- Make them work for it and, for reasons I won’t go into, much, ensure the “Port Number”: chosen is well over 1024.
Clever Hosts will boobytrap Port #22 to totally lock out whoever is knocking at that (wrong) door. : )

  • Your SFTP program will have an Option to change that Default port number from 22 to whatever was chosen by the Hosting Provider. 
    Don’t Forget: your Hosting Provider must be the one to provide  that non default port away from 22, then you follow suite.
    It’s not like you get to set some random port and that’s
    what’s used : ) If they cannot or will not, blah blah, Go Elsewhere.
    (you do know about Secure UserName/Password, right? 
    and, No amount of secure shelling can compensate for lame account credentials, passwords.
    You do not use “admin” as a Login, for example, right?

I like free program CYBERDUCK, for ALL platforms : )
Or command line: “sftp” if available,
You lucky Windows users: Try free WINSCP There is never a need to pay for a decent Transfer Program!

  • Your Webhost should reasonably be expected to keep its infrastructure Up To Date– Many use so called PHP. If this or things like it are out-of-date, it is vulnerable to misuse. Also- If their server ITSLELF is out-of-date… Good Luck.
  • So your Site either keeps or forwards Emails? If these Emails originate within a Form for Posting- that form must resist being bombarded by scripts that send junk mails.
    The commonest method is so called CAPTCHA  that forces miscreants to do uniquely Human work that a Script cannot do.
    Miscreant Scripts cannot easily “Read” images of traffic-lights, crossings and boats : )) –
    “Web Spamming” using forms on your site at its worst can, unknown to you, send Spam Emails to 3rd parties as “Someone Else”  and get you shut down or blocked by Google Searches.
    You could just wait until this happens then deal with it but this is Not Smart as it’s far harder ti unravel such a problem after it has happened that before. the excessive traffic can also make your Provider shut you down or bill your service for more traffic!

If your “domain” has Email where mailboxes are provided- the Protocol used MUST NOT include insecure methods
IMAPS not IMAP. No POP at all Please. and OAuth,
(Online Autherication) not generic  Username/passwords.
If you do not know what these things mean that’s OK so long as your site is NOT doing these things : )

Did I Mention? If you have them: Move OFF yahoo.com, hotmail.com, aol.com,  sbcglobal.net & its affiliates. These Email services are notoriously unreliable and insecure. “Just Saying”
Gmail.Com which not perfect seldom has problems
Another Blog I may talk about how To Move Email Services.
* your Domain’s DNS (domain Name Service) ideally uses SPF and more to hips Verify ‘real’Emails sent as ‘you’


  • SO YOU ARE USING WORDPRESS.
    FTP and even SFTP/SCP are all turned off and unavailable because lucky you you, you  get to publish and manage stuff over a Web Page? GOOD!
    First Off: Ensure WordPress is set to auto Update itself and its plugins. From ver 5.8 upwards, “Auto Update” of WordPress itself should be ENABLED and also for Plugins.
    (Remove all unknown themes and plugins while poking around-
    they can be an attack vector)
    Can Updates Cause Problems? YES OF COURSE but NOT updating will cause worse problems.
    There is now a mechanism to re enable your website with reasonable simplicity if some Update seems to Lock you Out. SO ensure that Worpress has a working “Notification Email Address” often the same as the Admin Login Email so that you will be Emailed reports of such actions and more.

Your whole site is using a Secure Certificate/SSL via “HTTPS://” and not “HTTP://” right?
If not- when you Publish stuff, the log in credentials and password are traversing the Internet in an easily stealable format.
Also true if your visitors are interacting in any way with forms or password protected pages,
Furthermore, any attempt to access the insecure version of the site on port #80 should redirect everything to the Secure version on port #443
(These are the Defaults and should not be altered)
Chrome Browser for example, will not longer deal with old standard port 80 and will immediately go looking for the Secure version of your site… Pretty soon, port #80 will I feel become officially unsupported! Do NOT Turn It Off Just Yet Though.
Just be sure your visitors get re direct 80->443
(Google Elsewhere- sorry ’bout that I cannot cover it all)

— Sep 18 2021 – To Be Continued

Libre Office

LibreOffice.Org is a free ‘Office Suite’ for MAC, PC and Linux to make documents, spreadsheets and presentations that admirably emulate Microsoft Word, Excel and Powerpoint:
But it needs a few little tweaks. 
You probably got referred here because either you do not have Microsoft Office or you do have it and it’s way out of date or broken.

You may have considered ‘upgrading’ to a newer Office Suite from Microsoft. It will cost, it will need new learning and it will be  infinitely larger and uses way more resources than this free alternative. If I’me wrong– Delete LibreOffice and go back to Plan 1. 
It can even peacefully co-exist with MS Office,
or will uninstall cleanly. 

Rest assured the installation (from the link above) is pretty easy and the download is small. By default, typically once it is installed clicking on a ::
* Microsoft Word (*.docx, *.doc) Documents [LibreOffice Writer]
* Excel (*.xlsx, *.xls) spreadheets [LibreOffice Sheets]
* Powerpoint (*.pspx, *.pps) Presentations [LibreOffice Presentations]
will launch your New Installation and You Will Be happy.
If it does not you will need to figure how to make Libreoffice the “Default Application” 

If in doubt, launch Libreoffice and File.. Open the file.
Change something. Anything. Now, “File.. Save As..”

Now- the Important Part. The “Default File Extension” for a Libreofficer Writer document is native to OpenOffice, and ends in *.ODT. If you sent this to someone who does not have LibreOffice it will not open. YOu need to do a “Save As”, Name the File and pull down the Option for Document Type- Et Voila- Looks like a Microsoft Excel Spreadsheet to anyone else, not a LibreOffice “Sheet”


Okay so why not have LibreOffice Always save the Microsoft Default way so you can cooperate better with the rest of the (non-libreoffice) world? Here’s the example for Microsoft Word when you make “Writer”documents,
[Your mileage may Vary depending on MAC PC or LINUX- But try your best to just use Options and see how to match this]
Go to Tools.. Options…

Document
Document

Spreadsheets:

Spreadsheet
Spreadsheet

And Presentations:

Presentation
Presentation

That’s IT for Now : )
I am sure there is More… Tell me in Comments.

Time Lapse Fun

Project: Automated daily timelapse video using Linux and an old IP Webcam

Required- Intermediate Expertise: AND:
A Crappy Webcam, patience, Linux, Exiftool, wget, imagemagick, cron, ffmpeg knowledge, more patience,
BASH shell understanding
NOT for Beginners!
Resulting Video At End Of Page


I have an old IP Webcam Dlink DCS-930L from? 2012, able to resolve 640 x 480 pixels. I will not go into how I got this running on WiFi except to say I did start with an Ethernet connection : ) In so configuring, I did give it a Fixed IP Address on my local network of 192.168.1.22 which will come up later. 
Using FireFox at http://192.168.1.22 you may  get a still image AFTER filling in the Username/Password that you set up.

Chrome browser will not work as it wants to redirect to a Secure Site httpS://.. all the time which this camera is too Old to oblige.

Device is nearly useless now as it originally required Java and/orActiveX for video and other stuff, which is insecure and unused anymore, but, I did find from Other Hackers that you can grab a single JPG still image like so:
http://192.168.1.22/image/jpeg.cgi
Again, with Username And Password being required…
Started Thinking: If I use a CRON job to grab just such a frame every minute, we could have a nice time-lapse scripted Video every day, No?

So here is a script using WGET(WebGet)  that grabs a jpeg frame from the camera every time it's called and saves it to a file:

wget - http://192.168.1.22/image/jpeg.cgi \ 
   --user=user --password=pass -O capture.jpg

Nice! Some tests showed that worked fairly reliably

More Cobbling with an ugly script- I have left in various pieces of diagnostic code for the curious. DO NOT run as Root User.
DO change the $BASE variable (the base directory to save files)
Script will generate date sequenced folders to drop timestamped jpg files a la:
/some/base/path/2021/Sep/01_Sat/13_15.jpg
I used a 24hr timestamp per file to simplify concatenation later and AVOIDED the use of colons which really throws stuff off:
script name I used: grabdlink
These paragraphs are ALL ONE SCRIPT which maintain variable names throughout. Note the $BASE path must be writable by the CRON owner and happens to be where the Web Server expects to find content in many distributions (Mine is MINT 20)
any number of directories off the ‘parent’ will be created as needed
which is the the -p arg in “mkdir”
______________________________________________

#!/bin/bash
YEAR=`date +%Y` # 4 digit year
MONTH=`date +%b` # Full Month name
DATE=`date +%d` # 01-31 day
DAY=`date +%a` # 3 char Day of Week
# TIME=`date +%I`_`date +%M`_`date +%p`
# CLOCK=`date +%R` # R=24h Clock 21:23 
HR=`date +%H_%M`
#
BASE="/var/www/html/dlink"
FOLDER="$YEAR/$MONTH/$DATE"_"$DAY"
FILE="$HR"
#
FULLPATH="$BASE/$FOLDER/$FILE.jpg"
mkdir -v -m 0755 -p $BASE/$FOLDER
#
echo "OutPut Name: " $BASE/$FILE.jpg
wget - http://192.168.1.22/image/jpeg.cgi --user=user --password=pass -O $FULLPATH
#__________________________________________
#The Dlink Camera produces basic JPEG files that lack any #meaningful EXIF (embedded meta data) so I added my own using #the superb EXIFTOOL  (All One Line below... sorry!)
#______________________________________________
/usr/bin/exiftool -P -overwrite_original '-AllDates<FileModifyDate' '-Model=Dlink DCS‑930L IPCAM' 
'[email protected]' '-Description=Http://Www.ArtOfLogic.Com' "-Comment=Http://Www.ArtOfLogic.Com Technology" $FULLPATH
#___________________________________________
#This way at least the time stamp for the #original shot remains #within the image no #matter what happens to the file's Unix # # #timetamp(s)!
#Now lets use the magical IMAGEMAGICK tools to #embed a visible #imestamp inside each jpg image. #It uses the embedded timestamp #we just created #so will work no matter how the *nix  file time #stamps change later:
__________________________________________________
convert "$FULLPATH" -gravity SouthEast -pointsize 20 -fill blue -annotate +30+30 %[exif:DateTimeOriginal] "$FULLPATH";
#END OF SCRIPT grabdlink

___________________________________________
Run as a Cron job:
* 6-18 * * * /home/sysop/bin/grabdlink
This will run every 60 seconds between 6AM and 7PM, not 6PM
as it’s all the times where “18” matches  the hr position : ))

This will give us about 900 jpg images per day one per minute all inside one day dated folder. Nice. 
At some point past the last capture (Or even during them, Why Not)
you can run this rather nasty-looking ffmpeg script to make things into a nice h.264 Video WITH AUDIO!.
Note that “GotamaCut.m4a” is an aac encoded Audio File longer than the longest expected video production, which will be copied into the resulting image stream, but will STOP as soon as the full video has played out.Ugly cut off ending, but it works
If you remove the “-shortest” option , audio will keep playing to its end while showing the last frame frozen. Could Do That Eh?

Also- ffmpeg DOES have a Fade Out option for audio add-in,
But I did not use it ; )

The mysterious TOUCH command sets the earliest time stamp possible for the resulting video so it will sort at the TOP of listings on an auto indexed web page. Of course, you can get cleverer than me here and fix it to the Earliest Still’s Date. Your Exercise!
_________________________________________
ffmpeg -i /home/sysop/Music/GotamaCut.m4a \
-r 8 -pattern_type glob -i ‘*.jpg’ \
-map 0:a -map 1:v -shortest -c:a copy -c:v libx264 -crf 25 -pix_fmt yuv420p timelapse_h264.mp4
# make It Sort FIRST (Earliest!) in Web listings
touch -t 202001010000 timelapse_h264.mp4
# End.
________________________________________
You COULD use libx265 not libx264 for an even more squashed HEVC video BUT web pages using HTML5 do not (yet) seem to know how to handle these. VLC is fine about it though : )
Likewise: -pix_fmt yuv420p seems to be required so web pages can stream the resulting video. I do not pretend to know Why : )

There IS a format MJPEG that means, “Motion Jpeg” but this is inefficient as it cannot perform intra-frame Compression,
only inter image. Lots of room to experiment!
-r 8 represents the “rate” of Frames per Second
Do the Math : )

Aaaand here is the Resulting Video

_______________________________________