Posted: . At: 4:57 PM. This was 11 months ago. Post ID: 18041
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Another very nice way to crop a video using mpv.


This simple trick is a nice way to crop a video with mpv. This is a good alternative to using ffmpeg.

┗━━━━━━━━━━┓ john@localhost ~/Downloads
           ┗━━━━━━━━━━━━━╾ ╍▷ mpv --vf=lavfi=[crop=290:220:30:0] --start=01:01:01 myvideo.mkv -o me.mp4

This will start at 01:01:01 and then crop out a square of the video.

To preview this effect, use this command.

┗━━━━━━━━━━┓ john@localhost ~/Videos
           ┗━━━━━━━━━━━━━╾ ╍▷ mpv --vf=lavfi=[drawbox=0:240:400:500:invert:1] rusty.mp4 
 (+) Video --vid=1 (*) (h264 608x1080 25.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 608x1080 => 810x1080 yuv420p
AV: 00:00:03 / 00:00:30 (12%) A-V:  0.000
 
Exiting... (Quit)

Once I was satisfied with the result, I could copy the crop values to the actual command. This is to crop a 240:500 pixel area of the video.

┗━━━━━━━━━━┓ john@localhost ~/Videos
           ┗━━━━━━━━━━━━━╾ ╍▷ mpv --vf=lavfi=[crop=240:400:500] --start=00:00:10 rusty.mp4 -o me.mp4
 (+) Video --vid=1 (*) (h264 608x1080 25.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
[ao/lavc] Opening encoder: AAC (Advanced Audio Coding) [aac]
AO: [lavc] 48000Hz stereo 2ch floatp
VO: [lavc] 240x400 => 320x400 yuv420p
[vo/lavc] Opening encoder: libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [libx264]
[encode] Opening output file: me.mp4
[encode] Opening muxer: MP4 (MPEG-4 Part 14) [mp4]
AV: 00:00:29 / 00:00:30 (100%) A-V: -0.029 {0.0min 213.2fps 2.3MB}
 
[encode] video: encoded 2454671 bytes
[encode] audio: encoded 320458 bytes
[encode] muxing overhead 16496 bytes
Exiting... (End of file)

This is a very painless endeavor and would be very useful indeed, to crop out a section of video and not require reecoding.

This will even work when you are streaming television or any other online stream, this is a nifty way of watching TV…

┗━━━━━━━━━━┓ john@localhost ~/Videos
           ┗━━━━━━━━━━━━━╾ ╍▷ mpv https://i.mjh.nz/7-per1ml.m3u8 --vf=lavfi=[crop=640:480:0] --no-resume-playback

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.