I’m being sent videos by someone, and I need to remove a portion of the video from the front. For example, if the video is 1m30s, I might need only the last 1m of the video (in other words, I need to cut out the first 30s).
What I find in nearly every case is that when I play the cropped video with VLC, the first several seconds are badly pixelated (as much as 10 seconds). The sound quality is perfect, however.
The original video doesn’t have this problem at all.
Replicating this is a bit of a problem:
When I try to make a video for the purpose of replicating the problem, I usually don’t get the problem, which is frustrating!
The videos that I’m sent contain people who haven’t given permission for me to share publicly, so I can’t post an example here. However, I include a cropped screenshot from VLC to show how bad it is.
So, I’m wondering if there is a problem with the codec inside the videos that I’m sent? They are created on a Samsung phone, but they aren’t all from the same model. (My phone, which doesn’t seem to cause this problem, is a Pixel.)
Or, maybe — I’m no expert! — is there something about synchronising the video that gets missed in the front of the copy?
Most important, of course, is how can I fix this, please?
The issue occurs because when using -codec copy with -ss, FFmpeg can only cut at keyframes (I-frames) when stream copying. When you specify a timestamp that isn’t at a keyframe, FFmpeg will start at the nearest previous keyframe and the video player has to reconstruct the frames from there, leading to the pixelation you’re seeing.
This command will show you keyframe timestamps. You can then choose the nearest keyframe to cut from.
For your use case, I’d recommend starting with solution #1 (two-pass method) since it’s fast and usually resolves the pixelation issue without quality loss. If you still see problems, then try solution #2 (re-encode method).
Thank you for the advice and explanation, @popey . I learned a new term, “keyframe”.
Solution #1
This was strange. For the first few seconds, VLC simply showed its logo, as though there were no video at all! So, unfortunately, this doesn’t work for me.
Solution #2
This is perfect, thank you!
I experimented with using copy instead of aac (for the audio). The results both seemed, to my ear at least, identical, but the one with aac resulted in a file that was 22% smaller! It’s strange how the audio can make such a difference to a video file.
I’ll stick with copy for the audio, because these are relatively small videos, and space isn’t a problem, unless you suggest that I do otherwise.
In hindsight, I should have looked at the encoding of the original file. “Properties” in Nautilus shows these:
Original video
Video codec: H.264 (High Profile), 25.00 fps, 1268 kbps
I don’t know if there’s any point in trying to retain the fps in the re-encoding? I did try adding -r 25.00, and that unexpectedly made the video look slightly choppy, as if there were too few frames per second.