Log in | Register
Forum > Site Discussion > Thread

Editing and rotating videos (and fixing the aspect ratio) losslessly

Aug 26, 2019 - edited Sep 10, 2022 - permalink
There are a lot of ways to download videos from Youtube and other sites, I generally use the Video DownloadHelper Firefox extension or the Internet Download Manager desktop app/extension myself, depending on the site (Instagram videos are a special case- see this thread).

After downloading, if the video needs to be cut down in length, combined with other segments, or rotated correctly, I like to do it without lossy re-encoding of the video stream if possible, since that lowers the original video quality.

Rotating/Cropping-
For lossless rotation of videos filmed sideways and such, the best thing I've found is the free program FFmpeg Batch, which is basically a graphical frontend for the FFmpeg command-line suite, and quite powerful (it comes with its own version of FFmpeg so you don't need to download anything else).  The default rotation parameters it comes with also do format conversion, but I found out you can use the parameters:

-metadata:s:v rotate="-90" -codec copy

instead, which seems to work fine without messing with the original data.  The "-90" (90 degree clockwise rotation) can be changed to "-180" or "-270" depending on how far the video needs to be rotated.  If you're working with .mp4 files, make sure the format field is set to mp4 also.

FFmpeg Batch can be used to do pretty much anything FFmpeg can, including non-lossless stuff like cropping, example parameters for cropping a video: 

-filter:v "crop=640:420:0:0" -crf 10

where 640x420 is the final size you want and 0:0 (x:y) is the starting point, top-left; it would be 640:420:0:200 if you wanted to start the crop box 200 pixels down, for instance.  The "-crf 10" part sets a Constant Rate Factor of 10 which should be nearly lossless quality, and is a useful thing to add for any function that isn't inherently lossless, i.e. not the rotation command above.

Trimming/Combining Videos-
For losslessly trimming down the length of a video or combining multiple videos into one (the latter is useful for Instagram Stories, where often a single video is spread into multiple 15-second clips), I like the program Machete.  It's paid, but only costs $20 (there's a free version, but it doesn't work with mp4 files).  The only limitation is that you have to cut the videos at the keyframe points, which aren't always exactly where you want them, but they're usually close enough.  A good free alternative to Machete is Avidemux, just be sure it's set to copy mode, use the keyframe buttons to select the edit points, and have the output format set to MP4 (if that's what you're editing).  This page lists a bunch of other alternative programs.

EDIT:  Added a free alternative to Machete for trimming, and more detail in the cropping section.
Chainer
Aug 26, 2019 - permalink
Thanks, stickied
tamarok
Jan 04, 2021 - permalink

Another app worth checking out is Handbrake, which is available for macOS, Linux and Windows. It is free and open source.

Jan 04, 2021 - permalink

I tried Handbrake a while ago, but from what I remember it always re-encodes and doesn't really do lossless conversions even when it should be possible (i.e. moving a video stream from an .mkv container format to .mp4, etc)

tamarok
Jan 05, 2021 - permalink

That's true, though it does afford many people a relatively easy way convert. Tools like ffmpeg will offer better options, but the need for command-line knowledge will put it out of the reach of many people.

Mar 17, 2021 - edited Mar 17, 2021 - permalink

Does anyone at GWM ever crop or reformat those tall skinny videos that are increasingly being downloaded from tik-tok? When downloaded as is, the frames are so skinny the subjects hardly have room for any kind of horizontal movements like flexing unless the camera is an undesirable long way from the action. They are so tall they can't be enlarged on GWM pages that are mainly horizontal; indeed most of them appear to be effectively shrunk to fit. This might not be such an issue were it not for the fact that tik-tok is becoming such a dominant source of videos for GWM, the older (and, for me at least, preferable) enlargeable wide angle format is becoming something of an endangered species. Unfortunately cropping or reformatting tik-tok videos won't make them any wider, but it can make them a lot less tall and maybe more enlargeable.

tamarok
Mar 17, 2021 - edited Mar 17, 2021 - permalink

I am not aware of staff doing so and if they did it would show as a staff member having uploaded the video. Tik-Tok videos as far as I am aware use 1080x1920 pixel dimensions.

The only ‘editing’ that you may see is change of the thumbnail to use another frame.

Edit: Just did a quick search and 1080x1920 is indeed the size to be used: https://tiktoktip.com/tiktok-size/

Mar 17, 2021 - permalink

If using another frame can involve vertically cropping all the waste space at the tops and/or bottoms of most tik-tok videos, I would certainly welcome that.

[deleted]
Mar 23, 2021 - permalink

Another app worth checking out is Handbrake, which is available for macOS, Linux and Windows. It is free and open source.

shoot i haven't used handbrake in like a decade lol maybe more

Jul 12, 2021 - edited Apr 18, 2023 - permalink

Fixing the aspect ratio on videos losslessly

 

I thought I had already made a post about this, but apparently not (at least, not one that I can find).

So, sometimes you'll run across a video with an incorrect aspect ratio, it happens most often with clips from television or some other nonstandard source. Here's an example that was uploaded to the site previously:

Obviously, it's stretched vertically from what it should look like. To avoid re-encoding it at the correct aspect ratio, which would lower the quality, it's possible to fix it losslessly by setting correct aspect ratio flags in the file's metadata instead, which basically tells any video player how it should be displayed without touching the actual video data.

I like to use FFmpeg Batch for this, a very useful graphical frontend for FFmpeg that lets you use all its functions without having to type out a command line each time.

The first step is to determine what the correct aspect ratio should be for the video, basically a matter of playing around with it in any video player that lets you set one manually until it looks correct (be sure to set it back to auto afterwards so you can tell when the video is actually fixed). It's usually 4:3 or 16:9, occasionally you'll run into something more exotic from this list. In this case, it should be 16:9.

There are actually two commands to set the aspect ratio in the metadata using FFmpeg, I'll give the simpler one first:

-c:v copy -c:a copy -aspect 16:9

This would be copied and pasted into the "parameters" box in FFmpeg Batch, and could be renamed and saved as a new preset. The 16:9 can be changed to 4:3 or 3:2 or whatever else is needed.

Depending on the nature of the original video and how its metadata was set up, the second command might be needed as well, it's a little harder to use:

-c copy -bsf:v "h264_metadata=sample_aspect_ratio=640/456"

The way it works is that you take the horizontal resolution of the original video and put that as the denominator of the fraction (in this case the video is 456x360, so 456), and for the numerator you put what the horizontal resolution should be if the video were stretched to the correct aspect ratio, based on the original vertical resolution. An online aspect ratio calculator like this makes that easy. In this case I pick 16:9 for the ratio in the calculator, put the original vertical resolution of 360 as "Pixels height", and it tells me the horizontal resolution should be 640, so that goes before the slash in the command.

Here's the corrected video:

I believe one of these commands is technically setting the Display Aspect Ratio (DAR) and the other the Pixel Aspect Ratio (PAR) and which one is needed depends on whether the video is supposed to have square pixels, but honestly that was getting into the weeds in a way I didn't need to make them functional for everything I played the videos back in. I just use the first one since it's easier, and if that doesn't work I apply the second one to the resulting file.

EDIT: Note, I now just use a combined command to set both at once, saves time:

-c:v copy -c:a copy -aspect 4:3 -bsf:v "h264_metadata=sample_aspect_ratio=640/720"

(That's the one for correcting a 720x480 video to 4:3, comes up a lot since that's a standard DVD resolution)

Aug 17, 2024 - permalink

[The rotation Parameters given in the opening post are now deprecated and no longer work with FFmpeg Batch, and I wanted to make some other changes, but the opening post can't be updated due to being imported from the old forum, so I'm locking and unstickying this thread to make a new one]

Thread locked by chipperpip.
« first < prev Page 1 of 1 next > last »