ducatimpeg4enc: avoid casting before checking if the cast is valid