Encoding fixes

Reported-by: Mehdi Laouichi <laouichi.mehdi@gmail.com>
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>