Bash reminder

I’m currently doing so much Bash scripting that I always end up googling the stuff I should know by now so it’s time for me to write it all down once and for all.

Looping through a text file

Sometimes you build up a list that you want to process, let’s say you want to wget a few URLs.

for read line; do
  wget "${line}"
done < ./urls.txt

It’s obviously a good idea to validate inputs but for the sake of this post it’s not necessary.

Redirecting STDERR

Redirecting to a file and just redirecting to STDOUT can be done two ways. I always forget the syntax so it’s always good to be reminded of it.

# STDERR to STDOUT
curl "${URL}" 2>&1

# STDERR and STDOUT to file
curl "${URL}" &> ./out.log

EOF syntax

In case you want to forward  a multi-line string to a variable you can invoke cat with the EOF syntax:

cat <<EOF
Hello World!
Why So Serious?
EOF

The syntax can actually be a bit tricky since you define on the first line the keyword that will end the multi-line string, in this case EOF.

Mounting a RAM disk

RAM disks are quick and ideal if you need a fast scratch disk, they can be mounted to any folders just like any other kind of device:

mkdir /mnt/ram
mount -t tmpfs tmpfs /mnt/ram -o size=4096M

You can now read and write on your RAM disk through /mnt/ram.

SSH tunnel

When you want to access services that are not available outside of a network you can open an SSH tunnel, which is like a VPN but not totally.

ssh -L 13306:127.0.0.1:3306 user@example.com

Here we bind the local port 13306 to the remote port 3306 through our localhost, we can then access a remote MySQL server through the SSH folder since there’s not good reason to have a MySQL server open to access on the internet.
Let’s manage ou MySQL server now:

mysql -h 127.0.0.1 -P 13306

Keep in mind that even though you can use this SSH command to proxy your network traffic, you will most certainly not achieve better performances than a standard VPN or OpenVPN setup.

Super Smash Bros. Ultimate: Review

Super Smash Bros. Ultimate has been released on December 7th 2018 and boy it’s good. The last game I’ve played was the 3DS version, it was fine and ran pretty nicely for the hardware.

I’ve purchased the collector edition with the GameCube gamepad and the adapter.

The game

As announced the character list is massive with over 70 characters in the base game and only the original roster unlocked on a fresh save, there are many characters to unlock and to fight with and against.

The menu is what you would expect since Brawl, you’ve got the main modes which are classic and versus, and you’ve got the adventure mode, World of Light.
Versus and classic are basically the same, with classic replacing bosses depending on the character you are playing.

World of light is the new adventure mode where you will be able to literally go on an adventure, more to follow below.

“Will it hurt?”

Performance

With the lowspec hardware of the Switch, one would expect that great engineering went into optimizing the game. It feels as smooth as it gets and look very nice while not dropping enough frames to notice.

There doesn’t seem to be more input lag than on the previous entries from what I’m used to with the GameCube controller.

Victory!

Controls

Being used to the feeling of the XBox 360 gamepad and the Joycons, I’ve rediscovered the Gamecube controller and have battled with it a bit. The good thing about the controls is that they are the same since melee, the bad thing is that we need the adapter which requires being in docked mode or a hub.

Adventure: World of Light

The trailer does a pretty good job showcasing the adventure. You start with only Kirby and you’ll smash your way through to awaken your allies in the quest to take down Galeem.

The adventure lasts at least 20 hours and has a couple of different challenge based around fighting. This isn’t the adventure of Melee.

When you win a fight you will earn a spirit that can be used to set certain skills on your fighter and buff his attack and defense.

Online versus

As experienced with Super Smash Bros 3DS the online experience will be different for everyone and against everyone. You can feel even the slightest lag and the game doesn’t seems to have proper matchmaking at the time of writing.
The experience can be really bad if you are stuck in a fight that is lagging so much that in game time is slower than real world time. No one wants to have a minute extented to 5.

As an example here are two fights that provide two different experiences. The first fight is a laggy fight, not really fun but it gives you time to see what you did wrong.
The second fight is what you should expect, performance wise, of a good and faire fight.

On the bright side of things you can have pretty good fights when everything goes well.

Conclusion

This game is fun. While I’m not very good I have enjoyed the adventure more than expected and I was surprised. The new characters feel really polished and I’ll be playing Ridley more seriously.

The changes to the already existing fighters are good, Link feels much more interesting to fight with his new bombs.

Can’t spell slaughter without laughter.

Going further with FFMpeg

This is my follow up to getting started with FFmpeg. I strongly recommend getting to know the tool better in my previous post about it.

Concatenate

Multiple clips can be merged together with the concat demuxer. The idea is to create a text file with a list of files to concatenate together (in order), the format is as follows:

# List of files in order
file './file1.mp4'
file './file2.mp4'
file './file3.mp4'

For the lazy people like me it’s possible to use shell scripting to generate this list:

for f in ./*.mp4; do
  echo "file '$f'" >> list.txt
done

Then you need to feed the file as an input and specify the format (-f) as concat:

ffmpeg -f concat -i list.txt -c copy output.mp4

The wiki page speaks more in detail about this feature.

Extracting the frames

It is quite simple to extract all the frames from a video as pictures.

ffmpeg -i input.mp4 frame_%03d.png

In this command we extract every frame from input.mp4 as PNG pictures. We use the printf format for the numbering of the frame (we pad with 0 the %d for 3 characters).

It’s possible to use the parameters for the start and length of the clip to extract part of the frames or just simply limit number of frames to extract with -vframes. We can also specify a different framerate to work with during this process with -vf fps=1.

Hardware acceleration encoding

For maximum speed it is possible to use a hardware encoder for H264, I will only cover how to do this with an NVidia GPU (NVENC).

First check that FFmpeg has not been configured with --disable-nvenc, this will appear in the banner when running FFmpeg if NVENC is disabled.

ffmpeg -ss 14:01 -i "input.mp4" \
  -c:v h264_nvenc               \
  -b:v 60000k                   \
  -t 0:30
  output.mp4

This looks exactly as encoding, except the codec on line 2 is different, it has _nvenc appended to it. This is really simple and will boost the encoding drastically.

Reading more

Please check out the following pages if you wish to know more:

Visual Studio Code sets core.filemode to true

Visual Studio Code is great customizable editor for Windows that is actually quite light compared to Visual Studio. It has support for multiple languages and SCM like Git.

But it has a major drawback, at least on Windows… It sets core.filemode to true in Git repositories. That’s bad because you might commit all the files that were not changed with the files that were changed because it sets the execution bit to true.

What is core.filemode?

Git tracks changes in files, even permissions. The setting core.filemode tells Git to track the file’s execution bit from its permissions. This can really mess up versioning.

Solution

You can either globally set core.filemode to false or set it on the current repository with the following command:

git config core.filemode false
git config --global core.filemode false # Sets it globally

Just to be sure I prefer to set it everytime I create a repository and I’ll be using Visual Studio Code.

Source

Nintendo Switch: hands on

With Pokémon Let’s Go Pikachu/Eevee and Super Smash Bros Ultimate coming out, I couldn’t pass any longer.

Handling the console

It’s quite wide. The joycons are not the most comfortable and need some serious getting used to, especially on games such as Monster Hunter Generations Ultimate!

The pro controller is not cheap at all, but since I didn’t buy it (yet?) I can’t speak about its comfort. It looks much better for using it while the console is standing or docked.

The triggers are awkward to use, the sticks are not placed ideally. It’s looks like a hot mess at first and getting used to it is part of the learning curve, not that it’s a good thing.

I’m a trained soldier though!

Get a glass screen protector

The screen glass is low quality compared to the smartphone glass, it will keep your fingerprint like the police just arrested you. It might scratch really easily too, especially if the dock is used a lot.

Any tempered glass screen protector should improve the screen durability, the biggest challenge will be placing it correctly with no dust or air bubbles. I have yet to master this skill.

No memory card included

As expected there’s no micro SD card included, I’d recommend getting at least a 32GB if you plan to screenshot a lot and purchase games from the eShop. Just to list storage requirements for a couple of games:

  • Super Smash Bros Ultimate: 14.7GB;
  • Zelda: Breath of the Wild: 14.5GB;
  • Xenoblade Chronicles 2: 14GB + 4.5GB (DLC);
  • Monster Hunter Generations Ultimate: 12GB;
  • Mario Odyssey: 5.6GB;
  • Stardew Valley: 1GB.

No one is safe from storage heavy games anymore.

The Nintendo eShop

The eShop should learn from other stores. There’s no way to get easily a list of free games or demo without resorting to the search features and ordering by price.

Sometimes by going back through the prompt instead of pressing B will throw you back to the eShop home, not what I though would happen when I started downloading a couple of demos.

Album

When saving screenshots and short clips of 30 seconds they are sent to the album which is the screenshot folder where nothing seems to be sorted. The only way to transfer these files is by ejecting the micro SD card, which is a fine option.
But there’s no way to upload videos to YouTube!

It’s possible to only share screenshots and videos through Twitter and Facebook, or you could buy a card reader and turn off the console then dump the micro SD card’s media onto your computer.

Not every screen can be screenshot and the output format is always JPEG, not the best quality.

Regrets

The red joycon doesn’t look red like on the pictures. It’s closer to a neon red than a bright red color. I’m nit-picking because I really like red. The controls are not as comfortable when getting started too, it’s like there’s a break in period for your hands.

Accessing the other region stores, like the Japanese one for Phantasy Star Online 2 Cloud (to get the Breath of the Wild items), requires adding another user. If you keep that user on the Switch you will be asked to select a user to launch at game… I’d prefer a default user in this case.

There’s no option to upload videos to YouTube as of right now.

Conclusion

As I have not had the opportunity to play a game online I can’t comment it just yet, same goes for cloud saves and any of the advertised features of the subscription. I just really hope that the sales won’t be lock behind the subscription since I don’t plan on paying until I get a game that can be played online (like Smash).

I’ve bought Super Mario Odyssey with the console and got Pokémon Let’s Go Pikachu when it came out, for now I feel satisfied since they are both great games and the upcoming line up is great.

There have been talks of new Switch hardware, I’m not sure how to react to that but an upgrade might be coming.

Pokemon Let’s Go Pikachu: review

No matter how old I get I still love these games. Pokémon Let’s Go Pikachu/Eevee are the latest games of the Pokémon series. Everybody knows about Pokémon, it’s like the Coca Cola of the gaming industry, but healthier.
You will walk 10Km to hatch that egg!

The screenshots and video recording are all done through the Switch’s feature, thus we are working with low bitrate video capped at 30 second, low quality JPEG screenshots. PNG lives matter!

Mainline game or spinoff?

This game is like the 12th time we had the opportunity to visit Kanto but it doesn’t get all that old. The game is solid and definitely is a mainline game. It plays the story like Yellow with come additions.

It’s not even my first time

Capture

The capture mechanic is the same as Pokemon GO at the exception of the way you throw the Poké Ball. You feel like you have less control than on the mobile game and it doesn’t always feel rewarding because you don’t battle Pokémons to catch them.

The wild Pokémons roam the world, no more random encounters unless they spawn on you. You get what you see.

In handheld mode you just press a button, but it seems you can aim the view with the gyroscopic features of the Switch. In detached mode and Poké Ball Plus you swing to send a Poké Ball.

Of course if there’s no battle mechanic that means that you can make wild Pokémons sleep and make catching them easier and that’s really a shame.
This is the core mechanic from the series.

It’s simple

Starting with generation 2 we were able to make our Pokémons hold items, this is missing. Since forever we had PC boxes to store Pokémons, this has been replaced by the bag.

This game seems to start on something new with Combat Points showing a value that represents all the stats of a Pokemon.

Poké Ball Plus

The Poké Ball Plus contains mew. It’s a 50€ piece of DLC and game controller. As a DLC is easy to use, just get the mystery gift inside it and you are done. As a game controller it’s not the best at all… It tends to rotate in the hand and some menus can’t be access since there are only two buttons.
While it’s possible to shake it to trigger a “third button” you can’t get more details on your moves during combat with it.

Against wild Pokémons you can swing it to throw a Poké Ball, just like with the detached joycon.

It also has more features, you can place a Pokémon on it and use the pedometer to gain more experience and some reward for walking around. When it’s linked to Pokémon GO you can have it vibrate when it spots Pokémons… Depending on your location it won’t stop vibrating.

I took Pikachu on a stroll and played some Pokémon GO

What’s missing?

So much is missing… First of all there are much less tactile interactions. You can pat Pikachu with the touchscreen and that seems to be it. You can’t navigate the menus or send Poké Balls with the touchscreen.

The abilities from the 3rd generation are missing too. This is good to avoid some of the weird quirks you’d face when battling certain Pokémons (like heatproof).

The Global Trading System (GTS) doesn’t exist, that’s a shame because it helped completing the Pokédex. No Wonder Trade (WT) but it’s not a big deal for that.
Trading and all other online features are locked behind a subscription.

Not as expensive as the others, but do we need that?

Conclusion

The game is pretty well made, going back to Kanto feels good and the additions in the story are not bad. I regret not being able to battle wild Pokémons to make them easier to catch though.

The framerate of the game feels smooth enough, this was hard to achieve with Sun & Moon and is really nice to look at.

I hope that the next entries to the series will bring back fighting wild Pokémon.

Getting started with FFmpeg

The tool I use the most to clip videos and (re)encode media is FFmpeg, a command line bundle of utilities and libraries that is very powerful but not necessarily intuitive.

This is a small guide about the most useful commands.

Basic command line

The basic command is composed by an input and an output:

# Conserve the same format
ffmpeg -i "./input.mp4" "./output.mp4"

# Conserve the same exact encoding settings
ffmpeg -i "./input.mp4" -c copy "./output.mp4"

# Conserve only the sound
ffmpeg -i "./input.mp4" "./output.mp3"

In the command line we have the input parameter marked by the -i option. The output is positioned at the end of the command.

The -c argument correspond to video and audio codecs when followed by copy to conserve the same streams as they were encoded in the input.

Argument quirks

FFmpeg uses the position of the arguments, the input cannot be place elsewhere than at the start of the line and all options related to the input must be placed before the input file.

The output options can be place after the inputs.

Extracting a clip

Sometimes you are proud of the way you handled a boss in a game or you just want to clip out a part of a movie, to do that you will need to provide the start of the clip and sometimes the length of the clip you wish to extract.

ffmpeg              \
  -ss 01:37         \ 
  -i "./input.mp4"  \
  -t 01:00          \
  "./output.mp4"

Let’s break down this command line by line:

  1. We call FFmpeg;
  2. We set the start of the clip with -ss and specifying a time code;
  3. We set the input file;
  4. We set the length of the clip;
  5. We set the output.

The start and length are expressed as a time code:

Hours Minutes Secondes Milliseconds
00 : 01 : 37 . 000

In our case we are working with minutes and seconds, but we can go as low a milliseconds. Keep in mind that if you do not re-encode you might end up with a couple of unwanted frames.

Encoding

More often than not encoding will be necessary if you want to publish online, reduce the file size or edit the media file. Here are a couple of snippets for different formats.

Implicitly convert

For the programmer lazy people like me it’s possible to quickly extract the sound or convert a video as a gif:

# Convert a video to an audio only file
ffmpeg             \
  -i "./input.mp4" \
  "./output.mp3"

# Convert to a gif
ffmpeg             \
  -i "./input.mp4" \
  "./output.gif"

This will use default settings, you can tweak the settings by going in-depth depending on the output format you choose (Encode/MP3).

Same codec, different bitrate

Changing the bitrate is possible, for a loss in quality.

# Convert to h264 with a bitrate of 
ffmpeg             \
  -i "./input.mp4" \
  "./output.mp4"

It’s also possible to run two passes by adding the parameter -pass with the argument 1 or 2 for the first and second pass.

# Convert to h264 with a bitrate of 
ffmpeg -i "./input.mp4" -c:v libx264 -b:v 2600k -pass 1 -an -f mp4 /dev/null
ffmpeg -i "./input.mp4" -c:v libx264 -b:v 2600k -pass 2 -c:a aac -b:a 128k "./output.mp4"

As you see on line 2 we use the argument -an to not treat the audio but during the second pass we specify a codec with -c:a and the audio bitrate -b:a, this is because the first pass only treats the video stream.
If you wish you can add the audio the the first pass, nothing is stopping you from doing so.

We still supply the video codec for both passes with -c:v and the bitrate -b:v.
Please note that bitrates can also be expressed in other units such as M for megabits.

We also don’t output the video stream to a file on line 2 because we are having FFmpeg generate a log file for the second pass. We also need to specify the output format to the encode with -f so that the second pass is not lost.

You can read more on h264 encode on the FFmpeg wiki.

What about the WebM format? Well it’s a bit the same but with different codecs:

# Convert to a webm (VP9)
ffmpeg             \
  -i "./input.mp4" \
  -c:v libvpx-vp9  \
  -crf 10          \
  -b:v 0           \
  -c:a libvorbis   \
  "./output.webm"

A new option on line 5 is the constant quality mode and this is the reason we have set the video bitrate to 0. Instead of imposing a fixed bitrate we will instead of have a variable bitrate used to target the quality we want.
It is possible to omit -crf and specify a video bitrate instead.

If you wish to target a lossless quality you can do so by setting the argument -lossless to 1.

VP9 does support two pass encoding and will work the same as h264.

Read more about VP9.

Editing

It’s also possible to reduce the frame rate and the resolution.

ffmpeg             \
  -i "./input.mp4" \
  -r 25            \
  -vf scale=160x90 \
  -c:v libvpx-vp9  \
  -b:v 2M          \
  -c:a libvorbis   \
  "./output.webm"

Here we reduce the frame rate to 25 with the option -r. The resolution is lowered with option -vf scale= to 160 by 90. It’s possible to keep the aspect ratio by specifying -1 in the scaling such as scale=1280x-1 to scale down to 720p from 1080p (assuming the aspect ratio was 16:9).

Conclusion

FFmpeg is a great tool that can basically do anything when working with media files. It’s very popular and used everywhere because of how powerful it is.

Enable the Windows 10 emoji picker

I’ve heard about the Emoji picker you can spawn by hitting Win Key + ; or Win Key + . but I was never able to see it until I tweaked the registry. It looks good and does what it’s supposed to.

This guide is about Windows 10 and was tested on build 1709.

Into the registry

Like always you can open the registry by hitting Win Key + R, this doesn’t change much.

Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Input\Settings and create a DWORD value called EnableExpressiveInputShellHotkey and set it to 1.

Run: regedit.exe

Source

This post was written after finding the Windows Central page about it.