Μηνιαία αρχεία: Μάρτιος 2021


ffmpeg: Create a video countdown – new post (2021) 2

The code below was used to generate the video countdown timers that are available in the following playlist using ffmpeg. These counters show seconds and fractions of seconds only. They do not bother with formating for minutes nor hours, etc.

#!/bin/bash

# This code will create a countdown video.
# If no command line arguments are provided, it will default to creating a 3-second video, with two fractional digits at 100 frames per second.
# It will print the elapsed and remaining times using two decimals accuracy.
defaultSeconds=3;
# If command line argument 1 is empty, the default value will be used.
seconds="${1:-$defaultSeconds}";

# Calculating how many digits are used to compose the seconds variable.
# We will use this information for zero-padding to avoid having the text move a lot.
# We used the shell parameter expansion to get the length of the variable value.
integerDigits="${#var}";

defaultFractionalDigits=2;
# If command line paremeter 2 is empty, the default value will be used.
fractionalDigits="${2:-$defaultFractionalDigits}";

#Computing how many frames per second are needed to maintain the accuracy of time based on the fractional digits.
fps=$((10 ** $fractionalDigits));

countDownFont=600;
countUpFont=100;
#Using a fixed width and fixed height font, to avoid having the text move around.
font='./Led.ttf';

#We are using the n variable: the frame number starting from 0 rather than the t variable, which is the timestamp expressed in seconds. We will get better accuracy on the decimals.
ffmpeg -loop 1 -i ~/Pictures/Black-Background.png -c:v libx264 -r $fps -t $seconds -vf "fps=$fps,
drawtext=fontfile=$font:fontcolor=yellow:fontsize=$countDownFont:x=(main_w-text_w)/2:y=(main_h-text_h)/2:text='%{eif\:($seconds-(n/$fps))\:d\:$integerDigits}.%{eif\:(mod($fps - mod(n, $fps), $fps))\:d\:$fractionalDigits}',
drawtext=fontfile=$font:fontcolor=yellow:fontsize=$countUpFont:x=(main_w-text_w)/2:y=((main_h-text_h)/2)+$countDownFont:text='Elapsed\: %{eif\:(n/$fps)\:d\:$integerDigits}.%{eif\:(mod(n, $fps))\:d\:$fractionalDigits}'" "$seconds seconds countdown timer with $fractionalDigits fractional digits accuracy.mp4";

Notes

  • We used a single black frame for the background that defined the video frame’s size as well.
  • Using the fps variable, we defined the number of Frames per Second for the video.
  • The seconds variable defined the number of seconds the duration of the video should be.
  • The fractionalDigits variable defines how many decimal digits should be shown after the dot.
  • countDownFont and countUpFont define the fonts’ size in the upper row and the lower one, respectively.
  • We used the drawtext directive twice to write to the frames.
  • font variable defines a fixed-width font to avoid having the text moving around.

Notes on the first drawtext

  • x=(main_w-text_w)/2 defines the X-coordinate of the location for the text on the frame, here we center the text horizontally on the frame.
  • (main_h-text_h)/2 defines the Y-coordinate of the location for the text on the frame, here we center the text vertically on the frame.
  • text='%{eif\:($seconds-(n/$fps))\:d\:$integerDigits}.%{eif\:(mod($fps - mod(n, $fps), $fps))\:d\:$fractionalDigits}' We print the remaining seconds for the video to finish with specific decimal digit accuracy.

Notes on the second drawtext

  • x=(main_w-text_w)/2 defines the X-coordinate of the location for the text on the frame, here we center the text horizontally on the frame.
  • y=((main_h-text_h)/2)+$countDownFont defines the Y-coordinate of the location for the text on the frame, here shift the text from the vertical center of the frame enough to move it under the main text.
  • text='Elapsed\: %{eif\:(n/$fps)\:d\:$integerDigits}.%{eif\:(mod(n, $fps))\:d\:$fractionalDigits}' We print the elapsed seconds since the video started with specific decimal digit accuracy.

Problem with compiling C# code on Ubuntu using the mono project while the source path contains Unicode characters

To avoid having the same issues as we did, avoid saving your code in folders that contain spaces and non-ASCII characters as it seems that the mono compiler on Ubuntu GNU/Linux is having some issues dealing with those.

We installed the mono compiler as follows:

sudo apt install mono-complete;

Then we tried to compile our C# code as follows:

mcs -out:program.exe Program.cs;

Which produced the following error:

error CS0016: Could not write to file `program'. Could not find a part of the path "윐뛶單/윐뛶單/program.exe".

By moving our code out of that folder, we were able to compile and execute our application as follows:

mono program.exe;


Cold-brew iceberg coffee

This guide will show you how to make delicious cold-brew coffee at home. Iced coffee will never taste watery or bitter again.

You can drink decent iced coffee all year round, but if you detest how watered down or bitter most iced coffees end up, you only have one choice: cold-brew coffee. Every time, this process creates an icy and smooth cup.

Cold-brew coffee doesn’t take a high level of expertise or special equipment to produce, and there are numerous examples of how to go about doing so on the internet. You only need a big container and a strainer to prepare the coffee.

Steps for making cold-brew coffee

The following shows how it works: Grind the coffee coarsely, and you can perform this job yourself in your own home or at the place where you buy your beans. Pour the grounds into a container, then add water. Cover and let sit for 12 hours or overnight.

When this happens, the coffee absorbs into the water at a prolonged rate, which results in a solid, concentrated brew. The next morning, strain the liquid, and you’re good to go.

Steps for making cold-brew iceberg coffee

This section takes it a bit further, which actually makes the coffee process even longer! Once the above procedure is done, pour the iced coffee into ice cube molds and freeze until solid, about 5 hours.

Then, finally, after so many hours of waiting for a cup of coffee… pour some fresh cold-brew coffee in a glass and add lots of cold-brew coffee ice cubes to it!

Enjoy!

Alternative steps for making cold-brew iceberg coffee

Instead of pouring the iced coffee into ice cube molds, pour coffee into a glass and fill it up to half. Then put that glass into the freezer and let it freeze solid.

The next day, pour fresh cold-brew coffee in that glass and give it a few minutes for the ice to get unstuck from the bottom of the glass! You will be drinking icy coffee all day long! (This actually works by pouring filter coffee or other warm coffee instead of cold-brew, and it gets cold really fast! There might be a chance for the glass to break, never happened to us, but still… you never know.).