mifi/lossless-cut

Lossless crop, flip, rotate, aspect ratio in video bitstream or container format metadata

Open

#643 opened on Feb 5, 2021

View on GitHub
 (25 comments) (9 reactions) (0 assignees)TypeScript (39,342 stars) (1,912 forks)batch import
enhancementhelp wanted

Description

Format metadata

This is metadata that affects presentation of the video, and is stored in the container format (not in the individual streams).

Display aspect ratio (-aspect)

From ffmpeg.org:

-aspect: If used together with -vcodec copy, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists.

Supported in VLC and MacOS QuickLook/QuickTime (tested by me). See also #493

Matroska specific metadata

Crop

PixelCropBottom=40
PixelCropTop=0
PixelCropLeft=240
PixelCropRight=40

https://github.com/mifi/lossless-cut/issues/504#issuecomment-773986073

Actually, this is possible with a Matroska container. I've done it multiple times in the past with MKVToolNix GUI, and it plays perfectly fine in MPC-BE. For not supporting players like VLC, bug reports should be filed.

The only caveat is that the video data stays the same and the file size is not reduced. But for playing purposes, it's very useful.

In MKVToolNix GUI, import a video file, click the video track, and hover over the text box of "Video properties > Cropping" for help. There's no visual cropping tool, though. That's why Lossless Cut should have it.

I wish this would be implemented. You'd just have to communicate that the feature is limited to MKV output, and that it's just the cropping information that is saved, so the file size isn't reduced and the player is responsible for the actual cropping.

If FFMPEG is the problem (can't it set metadata in the output file?), maybe it must be adapted or a multi-tool solution with the command line equivalent of the MKVToolNix GUI header editor might be the way to go.

Aspect ratio / SAR / DAR

PixelWidth=320
PixelHeight=240
DisplayWidth=320
DisplayHeight=240

Status: Matroska crop and aspect metadata seems to be not supported by FFmpeg yet.

https://trac.ffmpeg.org/ticket/4489 https://trac.ffmpeg.org/ticket/5301 https://forum.videohelp.com/threads/346278-MKVToolnix-cropping-or-changing-display-width-height https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2016-October/201451.html

MP4 specific metadata

CLAP atom / aperture width / height

Status: Seems to be supported in FFmpeg some time after 11 july 2024, however I can't find any sample file that has this, and I don't know how to use it.

https://trac.ffmpeg.org/ticket/7437 https://trac.ffmpeg.org/ticket/1485

Codec video stream metadata (-bsf)

This is metadata stored in the individual video streams themselves. aka. bitstream filters.

Crop (crop_left, crop_right, crop_top, crop_bottom)

Supported by H264 and H265.

https://github.com/mifi/lossless-cut/issues/38#issuecomment-1864479088

Supported in windows media player

Rotate (rotate)

See also display_orientation.

Flip (flip)

See also display_orientation.

Sample aspect ratio (sample_aspect_ratio)

Supported by H264 and H265. #493

Display aspect ratio

  • MPEG-2: display_aspect_ratio
  • HEVC width/height ("Set width and height after crop" - not sure if the same)

Lossless frame rate reduction

Encoded P-frames merging

See #2586

Contributor guide