-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lossless crop, flip, rotate, aspect ratio in video bitstream or container format metadata #643
Comments
Note that, in MKVToolNix GUI, additionally to "Cropping", "Display width/height" must be set to the new video size for distortion-free cropping (should also be possible via "Set aspect ratio"). (This brings us to the idea that Matroska medadata would also make possible the following: aspect ratio correction [spacial stretching/compressing]; adjusting audio delay; temporal stretching/compressing by setting stretch factors and/or FPS per track [even for synced combination of, say, 24-fps video track with English audio track of file 1 and sped-up German audio track of 25-fps video file 2].) |
Hello, You'd lose some accuracy on the crop dimensions depending on the size of the blocks, but I think that would still be very usable way to crop video and the benefits of not having to transcode are massive |
For an alternative, some codecs like H264 and HEVC also have crop metadata. E.g. for H264 |
Wow that would be great ! I just needed to re-frame a scene and didn't want to recompress, losing quality, this would be perfect, to draw a crop rectangle on the screen and move it around at various key frames ! |
nice find! i wonder if it works on the most popular video players and tools like
|
Hello, Please note where was a typo in @Craftyawesome 's command
should be
FFmpeg output
Hmm, I might need a more concrete test video, but it's doing something |
My bad, copied it from one of the related issues in that vlc issue link without checking myself.
As mentioned in the issue link vlc seems to interpret left and top as an additional right and bottom. Try almost any other player, it seems to be quite compatible barring vlc. |
Ok, I have found a more suitable test file testvideo.mp4I have run the following commands to crop it different ways for testing
Here is the console output of that And here are the test files testvideo.metacropped.cropbottom500.mp4testvideo.metacropped.cropcenter.mp4testvideo.metacropped.cropmiddlehorizon.mp4testvideo.metacropped.cropmiddlevertical.mp4testvideo.metacropped.cropright500.mp4testvideo.metacropped.croptop500.mp4testvideo.metacropped.cropleft500.mp4Here is mediainfo about these files. |
thanks for researching. maybe if we could make a summary/table of each player and how well it works for them, then we could look into whether it's worth implementing |
Yes, there needs to be a more visual test pattern, make all outputs standard sized and in the same order, so at a glance the difference between players can be seen. I'm also very curious to know, if I cut up the test pattern video into multiple chunks, set different crop factors for each chunk and then re-assemble them, Will the crop factor change on the fly. Also all these tests need to be tried with all codecs that support metadata cropping (at least h.265 and AV1) to see whether this feature is getting improvements over new codecs. Having lossless cropping would be awesome, when I started doing videos it was my second most used action and 3rd was masking. |
I found that this method works perfectly for YouTube since it respects metadata when transcoding uploaded videos. In my case, I've cut out exactly 108 pixels from the left. By the way, it seems like it's impossible to achieve the same result using So @h-h-h-h, thanks a lot! |
Apologies bumping this but I assume there's stuff I still need to look into fixing for wacup? Just wanted to check which file(s) I should be testing against or if there's anything else I need to be thinking about, thanks. |
Hello dr0biwan If you scroll back enough, you will find the test files in this post. This thread was an exploration in cropping with metadata, a lossless form of crop (but the data does stay behind, it doesn't get nulled out) In this exploration you can see that support for this rather obscure feature is not uniform accross all players. Reading my notes from back then. In the single test I had performed, WACUP failed to play the video instead getting stuck on the first frame. Keep in mind this was more than a year ago, I imagine things have changed. For this thread, once most players support this feature well, it would be interesting to see if we can change the crop metadata values over the timeline of the video. Perhaps create something like a "dolly pan" "dolly zoom" effect and maybe other combination of effects |
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:
Supported in VLC and MacOS QuickLook/QuickTime (tested by me). See also #493
Matroska specific metadata
Crop
#504 (comment)
Aspect ratio / SAR / DAR
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.
-bsf:v h264_metadata
-bsf:v hevc_metadata
-bsf:v mpeg2_metadata
Crop (
crop_left
,crop_right
,crop_top
,crop_bottom
)Supported by H264 and H265.
#38 (comment)
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
display_aspect_ratio
width
/height
("Set width and height after crop" - not sure if the same)The text was updated successfully, but these errors were encountered: