Lossless annoyances

“lossless” in Shotcut export does not imply the image goes through the engine untouched. It simply means that the codec is lossless or in lossless mode. The engine does not support every pixel format and color space in existence – only a few. Often sources get converted going through the engine. In your case, the source is RGB, but the engine defaults to yuv422 unless it has an mlt_image_format specified in Export > Other. For your 6SrK4.mp4, you would need mlt_image_format=rgb24 Also, in order to avoid image changes, you must use a Video Mode that matches the source and must not use any effecs (multiple video tracks, transitions, filters). (A mismatching video mode can cause automatic deinterlace, colorspace conversion, scaling, and padding).

lossless/H.264 & codec=libx264rgb 10.1 MB, lossy, with major glitches.

Yes, obviously this mode is broken and a bug. We would appreciate your help to debug it.

intermediate/DNxHR HQ 139 MB, lossy.

Intermediate is not lossless. So, skipping those.

alpha presets, which produced lossless output

These all use mlt_image_format=rgb24a as mentioned above.

I reproduced this one. First, I check what ffmpeg does since we are using its codec:
ffmpeg -i 6SrK4.mp' -codec:a copy -codec:v qtrle -pix_fmt argb qtrle.mov
It shows 7.4 MB
Then, I made an export in Shotcut from the Source player with Video Mode Automatic, but in Export > Audio I disabled the audio to prevent that from being a cause: 80.1 MB. Why? I compared the output of mediainfo against both and found this:
Bit rate : 8 343 kb/s
vs.
Bit rate : 91.3 Mb/s
:astonished:
Not sure what that is about. I tried changing some rate control options, but they did not affect it.

In any case alpha is not your target. How about Ut Video? Choose that preset, disable audio again, and in Other change:

mlt_image_format=rgb24
pix_fmt=gbrp

And I get lossless (as far as I have determined) but 144 .5 MB. Next, I use ffmpeg for comparison:
ffmpeg -i 6SrK4.mp4 -an -codec:v utvideo -pix_fmt gbrp 'ffmpeg utvideo gbrp.mkv'
I get lossless 144.5 MB. So, the same! But still not small like you want. Not all lossless codecs are designed for maximum compression, but FFV1 should be much better. Pick that preset in Shotcut, disable audio, and in Other:

coder=1
context=1
pix_fmt=bgr0
mlt_image_format=rgb24

(rgb24 is not a supported pix_fmt for ffv1).
24.7 MB. Now, that is much better. And ffmpeg, for comparison, 24.7 MB:
ffmpeg -i 6SrK4.mp4 -an -codec:v ffv1 -pix_fmt bgr0 -g 1 -coder 1 -context 1 'ffmpeg ffv1 bgr0.mkv'

I had to add -g 1 to make the file sizes match. Otherwise, ffmpeg was slightly less. Maybe that is the reason for big difference on Quicktime Animation. Yes, I return to that ffmpeg command line and add -g 1 and now the size is slightly more than Shotcut’s at 80.2 MB. So, again, the same.

I found that changing GOP to 250 for FFV1 also reduces the size further, but I suppose all these are inferior to x264rgb. I did verify that using ffmpeg with libx264rgb lossless and long GOP does produce a small file: 405.2 kB.

In summary,

  • libx264rgb in Shotcut is a real bug
  • as a workaround, use FFV1, but
    • increase GOP to 250
    • remove intra=1
    • add pix_fmt=bgr0
    • add mlt_image_format=rgb24
2 Likes