30
submitted 3 weeks ago* (last edited 3 weeks ago) by merompetehla@lemmy.ml to c/linux@lemmy.ml

when I say trim I don't mean to time trim a file, like getting rid of the last 2 minutes of the mkv file, but to picture trim every frame of the mkv file to get rid of black margins to both left and right of the actual image.

Files were originally recorded on 4:3 aspect ratio (some are movies from the 1950's) but the encoder somehow created / copied huge black margins to both left and right of the actual image. I want to get rid of these.

Some of my files are 30 minutes long but others 2 hours.

if ffmpeg is the application I need, could anyone knowledgeable enough write the actual command?

can it be done for several files automatically?

top 8 comments
sorted by: hot top controversial new old
[-] beerclue@lemmy.world 16 points 3 weeks ago

Ffmpeg is totally capable of doing this. Something like ffmpeg -i in.mkv -vf "crop=width:height:x:y" out.mkv might work. You would need to specify the crop area (x:y), which you can get with ffmpeg's cropdetect. Here's an article about it. To automate this, I would use a for loop in a shell script, for more control, or just a one liner if width, height and x:y are the same for all:

for file in *.mkv; do ffmpeg -i "${file}" -vf  "crop=width:height:x:y" "cropped_${file}"; done
[-] MoonMelon@lemmy.ml 3 points 3 weeks ago

If people want to fart around with ffmpeg filters this site is great: https://ffmpeg.lav.io/

[-] flx 3 points 3 weeks ago

Handbrake has the option to autodetect black bars and crop them out. But you have to reencode the file, unfortunately.

[-] domi@lemmy.secnd.me 3 points 3 weeks ago

Besides modifying the file, mpv can also automatically crop the videos with their autocrop script while playing: https://github.com/mpv-player/mpv/blob/master/TOOLS/lua/autocrop.lua

I use it for playing 21:9 content inside a 16:9 video file on a 21:9 screen.

[-] juipeltje@lemmy.world 1 points 3 weeks ago

Kinda unrelated to the question but i was actually looking for a linux native way to convert blu ray audio discs to seperate flac audio tracks after ripping them with makemkv. I could only find ffmpeg which seemed a bit daunting to me, but it looks like mkvtoolnix might be able to do what i want.

[-] catloaf@lemm.ee 1 points 3 weeks ago
[-] woelkchen@lemmy.world 1 points 3 weeks ago

MKVToolNix has a great cropping feature that completely lossless because it just writes an information into the file how many pixels to leave out.

The massive problem since quite some time is that I'm not aware of any media player respecting this. VLC used to support it but a decade ago suddenly stopped: https://code.videolan.org/videolan/vlc/-/issues/13982

If you have the originals, maybe encode them again. HandBrake has a nice preview feature.

[-] GenderNeutralBro@lemmy.sdf.org 2 points 3 weeks ago

mpv still works.

this post was submitted on 30 May 2025
30 points (100.0% liked)

Linux

55630 readers
1164 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS