Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Linux
  3. can I trim the black margins of several mkv files on debian 12.11 with ffmpeg or mkvtoolnix?

can I trim the black margins of several mkv files on debian 12.11 with ffmpeg or mkvtoolnix?

Scheduled Pinned Locked Moved Linux
linux
9 Posts 9 Posters 11 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M This user is from outside of this forum
    M This user is from outside of this forum
    [email protected]
    wrote on last edited by [email protected]
    #1

    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?

    C B woelkchen@lemmy.worldW juipeltje@lemmy.worldJ F 6 Replies Last reply
    7
    • M [email protected]

      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?

      C This user is from outside of this forum
      C This user is from outside of this forum
      [email protected]
      wrote on last edited by
      #2

      https://ffmpeg.lav.io/

      1 Reply Last reply
      0
      • M [email protected]

        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?

        B This user is from outside of this forum
        B This user is from outside of this forum
        [email protected]
        wrote on last edited by
        #3

        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
        
        M 1 Reply Last reply
        11
        • M [email protected]

          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?

          woelkchen@lemmy.worldW This user is from outside of this forum
          woelkchen@lemmy.worldW This user is from outside of this forum
          [email protected]
          wrote on last edited by
          #4

          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.

          G 1 Reply Last reply
          0
          • woelkchen@lemmy.worldW [email protected]

            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.

            G This user is from outside of this forum
            G This user is from outside of this forum
            [email protected]
            wrote on last edited by
            #5

            mpv still works.

            1 Reply Last reply
            1
            • M [email protected]

              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?

              juipeltje@lemmy.worldJ This user is from outside of this forum
              juipeltje@lemmy.worldJ This user is from outside of this forum
              [email protected]
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M [email protected]

                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?

                F This user is from outside of this forum
                F This user is from outside of this forum
                [email protected]
                wrote on last edited by
                #7

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

                1 Reply Last reply
                1
                • M [email protected]

                  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?

                  D This user is from outside of this forum
                  D This user is from outside of this forum
                  [email protected]
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  1
                  • B [email protected]

                    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
                    
                    M This user is from outside of this forum
                    M This user is from outside of this forum
                    [email protected]
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    2
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups