Saturday, February 29, 2020

FFmpeg Cheatsheet

FFmpeg is a great command-line tool for dealing with audio and video files. Here are some useful commands:

1. Reduce the size of a file

Try passing the file straight through ffmpeg and check if the size reduces:

ffmpeg -i input.mp4 output.mp4

To reduce the size further, scale the video to half the width and height:

ffmpeg -i input.mp4 -vf "scale=iw/2:ih/2" output.mp4
2. Convert a MOV file to MP4
ffmpeg -i -vcodec h264 -acodec aac -strict -2 out.mp4
3. Create a video from an image by panning across it

If you have a landscape image, first set its height to 1600px, preserving aspect ratio (using an image editor such as IrfanView). Then run the following command to create a video which pans across the image from left to right:

ffmpeg -loop 1 -i input.jpg -vf crop=1200:ih:'min((iw/10)*t,9*iw/10)':0 -t 5 out.mp4

Wednesday, January 01, 2020 in 2019

Happy 2020, everyone!

I'd like to wish everyone a great start to an even greater new year!

In keeping with tradition, here's one last look back at in 2019.

During 2019, I posted 7 new entries on I am also thrilled that I have more readers from all over the world! Thanks for reading and especially for giving feedback.

Top 3 posts of 2019:

I'm going to be writing a lot more this year, so stay tuned for more great techie tips, tricks and hacks! :)

Related posts:

Saturday, November 02, 2019

Java 13: Enhancements to Switch Expressions

You may remember from my previous post that, in Java 12, the traditional switch statement was enhanced so that it could be used as an expression. In Java 13, there has been a further change to this feature. The break statement can no longer return a value. Instead, you have to use the new yield statement, as shown below:

final int result = switch (input) {
    case 0, 1 -> 1;
    case 2 -> 4;
    case 3 -> {
      System.out.println("Calculating: " + input);
      final int output = compute(input);
      System.out.println("Result: " + output);
      yield output;
    default -> throw new IllegalArgumentException("Invalid input " + input);

Note that this is still a preview language feature, which means that it must be explicitly enabled in the Java compiler and runtime using the --enable-preview flag.

Saturday, October 26, 2019

Java 13: Text Blocks

Java 13 has delivered the long-awaited multiline strings or Text Blocks. You no longer need to concatenate strings that span multiple lines or escape special characters, which really improves the readability of your code. Text blocks are a preview language feature, which means that they must be explicitly enabled in the Java compiler and runtime using the --enable-preview flag.

Here is an example of a text block:

String textBlock = """
        <p style="color:red">This is a text block</p>

As shown above, a text block is enclosed by three double quotes ("""). The opening """ cannot be followed by any non-whitespace characters i.e. the actual text must start on the line following the opening delimiter. You do not need to escape any special characters within the text block, which is great!

In previous versions of Java, you would have had to write it like this:

final String old = "<html>\n" +
    "\t<body>\n" +
    "\t\t<p style=\"color:red\">This is a text block</p>\n" +
    "\t</body>\n" +

In fact, in this example, textBlock == old because both have exactly the same content and refer to the same object in the String pool.

Now let's take a look at how leading whitespace is handled by considering the following two text blocks:

String textBlock1 = """
        <p style="color:red">This is a text block</p>
String textBlock2 = """
            <p style="color:red">This is a text block</p>

If you print out these two text blocks, the first one is printed out as:

    <p style="color:red">This is a text block</p>

and the second one as:

            <p style="color:red">This is a text block</p>

The leftmost non-whitespace character on any of the lines in the text block or the leftmost closing delimiter determines the "starting point" of the whole block and whitespace is preserved on each line from this starting point.

Another point to note is that trailing whitespace at the end of each line is removed in text blocks but you can use the octal escape sequence \040 to preserve it as shown below:

String octal = """
    line 1    \040
 line 2""";

Sunday, August 25, 2019

Switching Back to Windows 7 Style Outlook Email Alerts in Windows 10

In Windows 10, the Outlook 2016 desktop application sends email alerts to the Windows Notification Center. I don't like how big this email alert is and, more importantly, it's not possible to delete the email by clicking on the alert, which I could do in Windows 7. Instead, I have to go into Outlook and delete the email there.

The good news is that it is quite easy to switch back to the old-style email alert, which is smaller and has a delete button, as follows:

  1. Right-click the Outlook shortcut icon and choose "Troubleshoot Compatibility"
  2. In the Program Compatibility Troubleshooter dialog, select "Troubleshoot program"
  3. Select "The program worked in earlier versions of Windows but won't install or run now"
  4. Select "Windows 7"
  5. Press "Test the program..." which will launch Outlook. Send yourself an email to confirm that the email alert is now back to Windows 7 style
  6. Select "Yes, save these settings for this program"