Sunday, October 27, 2019

Making Slideshows w/FFMpeg

Browsing Reddit or StackOverflow and you come across numerous posts asking how to generate slideshows with FFMpeg.  Seems a common interest and incredibly easy with the right tools.  FFMpeg is one of the said tools,the other....makefiles.

There are few utilities that are truly hated in this industry, makefiles seem to be one of them.  Despite it's poor reputation, make is a perfect utility for many image and video processing pipelines.  I blame it's bad reputation on the hacks that claim to maintain them.  Make is the perfect utility, it's dependency engine is a perfect match for creating videos from input media.

This short little makefile will convert all JPGs in the current directory into subvideos of 1 sec durations, then concat them together into a long video and finally adding audio.

$ cat Makefile 
SRCS=${wildcard *.jpg}
SIZES=$(subst .jpg,.jpg.size,${SRCS})
CLIPS=$(subst .jpg,.mp4,${SRCS})
SlideDuration=1
FPS=25

all: video.mp4

video.mp4: slideshow.mp4 audio.aac
${SH} ffmpeg -i slideshow.mp4 -i audio.aac -shortest -strict -2 $@

audio.aac:
${SH} youtube-dl -f best https://www.youtube.com/watch?v=IYbE2coMZPc
${SH} ffmpeg -i Íslandsklukkur\ \(Instrumental\ Icelandic\ Folk\ Music\)-IYbE2coMZPc.mp4 -vn -codec copy audio.aac

slideshow.mp4: ${CLIPS}
${SH} for f in `echo $^`; do echo "file '$$f'" >> filelist.txt; done;
${SH} ffmpeg -y -f concat -i filelist.txt -codec copy $@
${RM} filelist.txt

%.mp4: %.jpg video.size background.jpg
${SH} ffmpeg -y -loop 1 -i background.jpg -i $< -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -r $(FPS) -vframes $(shell echo $(FPS)*$(SlideDuration) | bc) -an $@

video.size: ${SIZES}
${SH} echo $(shell cat *.size | cut -f 1 -d 'x' | sort -un | tail -1)x$(shell cat *.size | cut -f 2 -d 'x' | sort -un | tail -1) > $@

%.jpg.size: %.jpg
${SH} mogrify -auto-orient $<
${SH} identify $< | cut -f 3 -d ' ' > $@

background.jpg: video.size
${SH} convert -size $(shell cat $<) xc:black $@

clean: 
${RM} *.mp4 *.size background.jpg *.aac

This makefile works for an arbitrary list of image sizes, it first auto-orients images (portrait/landscape) as it's not uncommon to have phone images mis-oriented.  It then generates a *.jpg.size file that contains the image dimensions.  These files are used next by the video.size target, which generates the maximum image size...this allows creating the video to match the largest of the images.  Next, a background jpg image is created of said dimensions.  Next, each image is converted into a 1 sec video which is then concatenated into the slideshow.mp4 file.  Finally, an audio video is created by downloading a video from Youtube and the audio is extracted, then applied to the slideshow mp4 file to get the final video.

I dumped our Iceland photo archive into the directory to test and it spit out the following video;


Sunday, October 20, 2019

Fantasy Engineering Team

I’ve been fortunate to have worked with some incredible engineers in my career.  Every so often my lovely wife will buy a PowerBall ticket that incites thoughts of ‘what would you do if you won’?  My answer has been consistent since college; I’d build something cool the way I felt it should be built.

The world is about compromise, often motivated by constraints.  Projects typically have limited time, limited budget and limited availability of team members.  Since college, I’ve always wanted to build something cool in the way I felt it should be done rather than how it has to be done due to pre-defined constraints.  So, it’s always fun to perform the mental exercise of “what if you could execute a software development project the way you think it should be done?”

In past years, I’d first focus on the what; what is the project?  Lately I tend not to think of that as the first step, I am still a tech nerd and interesting projects are still a heavy influence but I don’t think of the what as much as I think of the who.  The reason; there are nearly infinite interesting projects and technologies, something interesting is always around the corner.  Instead, I focus on the people I’d want to do it with.

So, I figured I’d play out my top 6 draft picks; software engineers I’d immediately call up if I ever had the ability to cherry-pick a software development team to work on some new sexy project.  The if I had a $100 million dollars project budget development team.  Unless we have run in the same circles, many of these folks you’ll unlikely know.  They are primarily located in Minnesota and folks I’ve had the pleasure to work with.  For those of you that don’t recognize these folks, I’d suggest you focus on the why’s rather than the who’s; why would I pick this superstar over the dozens and dozens and dozens of other folks I’ve worked for.  

One last thing; I’ve intentionally excluded my wife, who is an extraordinary software engineer, simply because of an oath.  I’ve made two oaths in my life: 1) the oath to her in marriage, 2) the oath to never work with one another on the same project again.  We worked on the same team in the days my hair was much fuller and less gray and it was an incredible strain on our relationship.  The lack of separating home live and work life is an ugly monster and while I’ve matured since those days it’s simply not worth the risk of repeat.

My dream team list, in no particular order;

Marshall Meier

I’ve known Marshall for nearly my entire professional life, and most of my college days.  From ‘go’ it was clear that this man was destined for greatness, one of the most organized and even-tempered men you’ll ever meet.  His ambition and technical prowess had drawn him into the consulting community early where he fine-tuned his professional communication skills and honed his breadth of technical expertise.  His continued pursuit of knowledge has earned him multiple degrees, many of which were earned while working and balancing a full family life.  Any good team needs a calming voice and technical leadership during the monsoon of challenges every worthwhile project will encounter.  The kind of guy that can talk you off the edge when you’re prepared to abandon ship.  The type of guy that is well-versed in how to make a happy, productive, engaged team and how to maintain it.  The kind of guy that has the technical chops to bounce ideas off of as well as the kind of guy that can/will roll up his sleeves and put in the work.  Great engineering teams need strong technical expertise as well as people with proficiency in building effective working relations.

Dan Ruhland

Dan started his professional life as a controls engineer and was remarkable at it.  I first met Dan when he was responsible for writing the controls software for a 7-axis ammunition loading system.   He authored the control loop algorithms for each axis and authoring sequencing logic to transfer ammo to/from the breech while avoiding slamming one-of-a-kind equipment into one another; arguably, the most sophisticated subsystem of the weapons system.  From our earliest encounters it was clear that Dan was an expert in his field; disciplined, precise and wicked smart.  Dan made the transition to software development in later years and brought with him a vast amount of technical knowledge of the system as well as all the professional characteristics that made him a great controls engineer.  While our profession is no stranger to team members from other engineering disciplines (e.g. EE’s, physics,…) it’s my opinion that many while great at low-level software development have difficulty being equally proficient with higher-level development activities such as abstraction, design-patterns, best practices… Dan showed no such limitation.  I feel he’s as proficient a high-level designer as he is at the hardware abstraction layer.  So, why specifically Dan?  Simply because I’m confident that regardless of the complexity of the problem to be solved he’s got the intellectual horsepower and tenacity to devise a solution.  Dan would be my ‘ace in the hole’ for any math-intensive problems/solutions, regardless of complexity.


Matt Spencer

Smart, motivated and quick learner; three of the key traits that come to mind when I think of Matt.  I’ve personally airdropped Matt into technical domains with no available support on more occasions that I care to admit.  Each and every time, Matt chisels his way through the jungle of tech and solves the problem; each and every time.  A jack of all trades as well as an expert in many, he’s a legend in the community.  Engineers often are like engines; high-performance engines require high-maintenance, many high-performance engineers come with higher maintenance traits (e.g. impatience, peculiarities, temperament,…).  Matt demonstrates none of these expected, all the performance with none of the maintenance.  Likely one of the quickest learners I’ve ever had the pleasure to work with, if it can be done likely Matt can do it and probably faster than you thought possible.  He is truly is in a category of one.


Rob Rapheal

Some say that you get along with people that possess traits you either share or wish you had.  Rob has an overwhelming desire for new technologies and it’s apparent from how he spends his free time.  He’s a tinkerer and continuously pursuing learning new technologies in his spare time hoping to one day apply them to a corporate project.  He’s authored an Arduino-based temperature control system for his hobby kiln…….just for fun.   He once spent significant hours pursuing C#/.NET/WPF as emerging technologies while the corporation was focusing on MFC-based applications.  His gamble payed off when a greenfield development activity was materializing and his knowledge of C#/WPF helped influence the product development.  In this profession you need folks that have an eye on the road as well as an eye on the horizon;  Rob provides both.  His talents have been recognized by his peers, whom in the past had informally selected him as the lead designer/architect which was later formalized.





Cliff Winkel

Cliff possesses an indescribable energy and enthusiasm.  Like a squirrel jacked up on Red Bull, this guy can pound out code at an extraordinary rate.  In this profession, we all ‘get in the zone’ on occasion, often through self-medicated caffeine ingestion.  Head-to-head with this guy and you’ll likely fall short.  Cliff worked on a multi-year green-field project with 2-week sprints and consistently completed his tasks regardless of what you threw at him.  Hitting targets is easy when you lay-up, but this guy hungered for work and always chose challenging task loads and never disappointed.  A wicked hard worker, enthusiastic and great to work with.



David Englund

You like to think that greatness in an individual can be recognized early.  David is not as long-in-the-tooth as many of the rest of my fantasy engineering team members.  Hungry, driven, self-learner and an eagerness of understanding “how should it be done”.  His ambition drew him into the consulting profession early and when I was once asked by a contract house “He’s pretty young to be asking for such a rate”, I simply responded “His knowledge is beyond that of his years, just get him in an interview and that’ll become evident”.  David shares many of the same qualities as the rest of my fantasy team and is still in the beginning stage of his career.  I’m eager to see what he’ll accomplish in the next decade.



So that’s it, my fantasy engineering team; many talented alternates but I felt it best to keep the list short'ish.  I’d stack this team against any other development squad in the world and stake a significant wager on their victory.  They tend to all have the types of qualities I’d want in a team: smart, driven, low-maintenance, self-learners, and high producers.  The kind of folks you’d equally want to hang out with as well as stake your project success on. 

If PowerBall ever hits for me I’ll be calling in the draft.

Cheers.

Sunday, October 13, 2019

ZeroMQ Presentation @ pyMNtos Meetup

I've always admired those that can present technical content in an informative, entertaining and well-presented style.  I've worked for some great managers and/or co-workers who have the presentation gene and it's a pleasure to watch them unfold a story about a technology.

Introverts by nature, engineers come in at a distinct disadvantage to becoming a proficient public speaker.  We spend many hours in the absence of human contact and often go out of our way to avoid it.  There are full days when I've spoken less than a couple dozen words and I'm convinced that speaking like a muscle needs practice and I've found over the past couple years that my proficiency in smooth speech has diminished and I'm more apt to stumble for wording so I was particularly nervous to throw my hat into the presenter ring.  But, for whatever reason, I wanted to give 'er a try and found a very accommodating audience in pyMNtos.  An extraordinary group and I'd highly recommend it to anyone who has even a passing interest in Python.



Check out the full video here:



Sunday, October 6, 2019

Monitor Specific Process w/Top


Top is the amazing utility that allows you to peek at the performance of your system.  By default, top shows the overall system performance in the header and shows a subset of the running processes.  Sometimes you're simply interested in a specific process and while the default presentation will show your process when it's part of the process subset list.

If you're interested in a specific process you can specify the process id on the command line:
$ top -p <pid>

That works very well, but requires you know the process id to specify.

The pgrep command allows looking up a process id by name.  For example, if you're interested in the process id of top you can get it by specifying;

$ pgrep top

Pair these together and you can ask top to show the process overview of the top process;

$ top -p `pgrep top`


Hope you find this useful.

Cheers.