Tuesday 15 November 2016

Video to GIF shell script

I like to capture my Xbox One gaming moments to share with friends and have been working on a shell script to quickly convert videos to animated GIFs, I've put together this fairly simple little shell script that takes an input video and uses ffmpeg to convert to an animated GIF.

The GIF file format has a colour limitation of 256 colours, so optimisation needs to be done to ensure a good quality output. The script utilises ffmpegs palettegen options to generate a pallete of colours to use in the second pass using the bayer dither option. This is what the pallete PNG file looks like (upscaled from 16x16):

The resulting animated GIF turns out quite nice, this was captured from my Xbox One in the Battlefield 1 beta, the file is 480x260 and 4.3MB at 15 frames per second:

More information on GIF optimisation and bayer dithering can be found here, this was also the basis of my original script:
http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

Just a warning, keep the input videos short, GIFs can get very large very quickly.

The script is available on github or copy and paste from below:

Monday 18 July 2016

Install Cura 2.1.2 on Fedora 23/24

Unfortunately for Fedora users Ubuntu is more popular which means packages that don't make it into repos often aren't available as RPM's but are sometimes available as DEB's, this was the case with Cura slicer from Ultimaker.

Luckily DEB's can be converted to RPM's with a package called Alien which can be installed through DNF.

Download your preferred version of Cura, I wrote this guide around the recently release version 2.1.2.
https://ultimaker.com/en/products/cura-software/list

Install Alien:
# dnf install -y alien

Convert the DEB to RPM:
# cd ~/Downoads
# alien -vr Cura-2.1.2-Linux.deb

Unfortunately at this point the RPM won't install successfully so it needs to be modified:
# dnf install -y rpmrebuild

Fix the RPM:
# rpmrebuild -pe cura-2.1.2-2.x86_64.rpm

After a short time rpmrebuild will open a file in vi, the below lines need to be removed (move cursor to appropriate line with arrow keys and press the d key twice):

# /opt can be found at the top of the %dir list:
%dir %attr(0755, root, root) "/opt"

# the remaining lines are at the bottom of the file:
%dir %attr(0755, root, root) "/usr"
%dir %attr(0755, root, root) "/usr/bin"
%dir %attr(0755, root, root) "/usr/share"
%dir %attr(0755, root, root) "/usr/share/applications"


Fedora 24 note:
If you are using Fedora 24 you will also need to remove this line and create a symlink, Fedora 24 shipped with Python 3.5 but Cura was built for Python 3.4, this step is not needed for Fedora 23:
Requires:      libpython3.4m.so.1.0()(64bit)

Now save and exit, press the : key then type wq and press enter (:wq), rpmrebuild will now now prompt to continue, press Y to build the modified RPM file.

Once rpmrebuild has finished building the new RPM it will return the location of the new RPM:
result: /home/user/rpmbuild/RPMS/x86_64/cura-2.1.2-2.x86_64.rpm

Fedora 24 note:
Before installing create a softlink to a file Cura will be expecting to find but doesn't exist, this step is not needed for Fedora 23:
# ln -s /usr/lib64/libpython3.5m.so.1.0 /usr/lib64/libpython3.4m.so.1.0

You can now install the new RPM using DNF:
dnf install '/home/user/rpmbuild/RPMS/x86_64/cura-2.1.2-2.x86_64.rpm'

And that should be it, run Cura from the Applications menu and if all went well it will open just fine.


Monday 11 July 2016

Plex playback failure on Linux


This is my first post on what I hope to be a useful resource for Linux Tips and Tricks.

This evening I had a disagreement with Plex Media Server on my HP Gen 8 Micro Server, it runs a Debian based distro called Open Media Vault, it's pretty slick, check it out.

When I first setup this server with Open Media Vault I used an 8GB USB drive connected to the internal USB port as I didn't think the install would go beyond that, but it turns out the databases and metadata behind Plex Media Server chew up quite a bit of space. So I moved the Plex Library onto a 240GB SSD that is used for VM storage, all was good for quite a while till this evening when I updated Plex and it failed to transcode media, direct play wasn't an issue however.

The log file showed this when ever I attempted to play files from a device that needed to transcode:
Jul 10, 2016 20:50:33.579 [0x7f40a53f9700] ? - [Transcoder] Unknown decoder 'h264'

Googling didn't help much, the best I found was this comment on the Plex forums:
http://forums.plex.tv/discussion/comment/1204390/#Comment_1204390

So I had a look at /etc/fstab and the drive that I moved the Plex Library to had the noexec option, noexec prevents execution of binaries and scripts, I remounted the drive with the exec option and Plex worked again!

Here's a quick run down on how you can resolve the issue:

Locate where your Plex Media Server is installed with the find command:
# find / -name 'libh264_decoder.so'

/media/fa7154d4-1137-43ab-8720-1ccfe9cad638/plexmediaserver/Library/Application Support/Plex Media Server/Codecs/2c361e4-1071-linux-ubuntu-x86_64/libh264_decoder.so

Check /etc/fstab for the offending entry using the path from the output of the find command:
# grep '/media/fa7154d4-1137-43ab-8720-1ccfe9cad638' /etc/fstab

UUID=fa7154d4-1137-43ab-8720-1ccfe9cad638 /media/fa7154d4-1137-43ab-8720-1ccfe9cad638 ext4 defaults,nofail,user_xattr,noexec,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0,acl 0 2

Before editing the fstab file you can test by remounting the filesystem with the exec option:
mount -o remount,exec /media/fa7154d4-1137-43ab-8720-1ccfe9cad638/

Use your favourite text editor to change it to exec or leave it out, note that the presence of the "user" option implies noexec unless overridden with exec.

I hope this is even slightly helpful to someone.