BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Image/Video Cropping - 2020

ffmpeg_new_logo_161_42.png




Bookmark and Share





bogotobogo.com site search:






Cropping syntax

In this chapter, we'll crop the input video to given dimensions.

The command syntax looks like this:

	
ffmpeg -i before.mp4 -vf "crop=w:h:x:y" after.mp4

The crop filter accepts the following options:

  1. w
    Width of the output video (out_w). It defaults to iw. This expression is evaluated only once during the filter configuration.
  2. h
    Height of the output video (out_h). It defaults to ih. This expression is evaluated only once during the filter configuration.
  3. x
    Horizontal position, in the input video, of the left edge of the output video. It defaults to (in_w-out_w)/2. This expression is evaluated per-frame.
  4. y
    Vertical position, in the input video, of the top edge of the output video. It defaults to (in_h-out_h)/2. This expression is evaluated per-frame.



Sample
Your browser does not support the video tag.
  1. blue_umbrella.mp4
  2. blue_umbrella.ogv
  3. blue_umbrella.webm

The original mp4's resolution is 1280x534 and I cropped the width to 712. That makes the aspect ratio 4:3.


ffmpeg -i blue_umbrella.mp4 -vf "crop=712:534" cropped_blue_umbrella.mp4

Your browser does not support the video tag.
  1. cropped_blue_umbrella.mp4
  2. cropped_blue_umbrella.ogv
  3. cropped_blue_umbrella.webm




Fixed value cropping

This will give us the same result as in the previous section.

To achieve the same effect, we need to crop our video (1280-712)/2 = 284px on left/right and 0px on top/bottom use this configuration crop=iw-568:ih:284:0. The parameter iw-568 is the cropped output width (out_w) calculated by the input width - 568px as we wanted to crop 284px from each side. The same could be done for the output height (out_h), but in this case, we want to keep it untouched. The starting coordinates are x = 284 and y = 0.

We do the cropping with an image instead of a video;

blue_umbrella_025.png

ffmpeg -i blue_umbrella_025.png -vf "crop=712:ih:284:0" cropped_blue_umbrella_025.png


cropped_blue_umbrella_025.png









Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







FFmpeg image & video processing



Image/video scaling

Image/video cropping

Cropdetect and ffplay

Speeding-up & slowing-down video

Basic slide show from images

Advanced slide show from images

Thumbnails -Selecting specific frames : I-frame extraction etc.

Creating a mosaic/tile of screenshots from a movie

Seeking and cutting sections of a video & audio

Concatenating two video files or two audio files

Transitions : fade-in & fade-out for 1 slide

Transitions : python script for fade-in & fade-out with two slides

Concatenate slides

Creating test videos

Screen Recording on Ubuntu A

Active window capture with Python on Ubuntu B




Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







OpenCV 3 -

image & video processing



Installing on Ubuntu 13

Mat(rix) object (Image Container)

Creating Mat objects

The core : Image - load, convert, and save

Smoothing Filters A - Average, Gaussian

Smoothing Filters B - Median, Bilateral






OpenCV 3 image and video processing with Python



OpenCV 3 with Python

Image - OpenCV BGR : Matplotlib RGB

Basic image operations - pixel access

iPython - Signal Processing with NumPy

Signal Processing with NumPy I - FFT and DFT for sine, square waves, unitpulse, and random signal

Signal Processing with NumPy II - Image Fourier Transform : FFT & DFT

Inverse Fourier Transform of an Image with low pass filter: cv2.idft()

Image Histogram

Video Capture and Switching colorspaces - RGB / HSV

Adaptive Thresholding - Otsu's clustering-based image thresholding

Edge Detection - Sobel and Laplacian Kernels

Canny Edge Detection

Hough Transform - Circles

Watershed Algorithm : Marker-based Segmentation I

Watershed Algorithm : Marker-based Segmentation II

Image noise reduction : Non-local Means denoising algorithm

Image object detection : Face detection using Haar Cascade Classifiers

Image segmentation - Foreground extraction Grabcut algorithm based on graph cuts

Image Reconstruction - Inpainting (Interpolation) - Fast Marching Methods

Video : Mean shift object tracking

Machine Learning : Clustering - K-Means clustering I

Machine Learning : Clustering - K-Means clustering II

Machine Learning : Classification - k-nearest neighbors (k-NN) algorithm



Matlab Image and Video Processing



Vectors and Matrices

m-Files (Scripts)

For loop

Indexing and masking

Vectors and arrays with audio files

Manipulating Audio I

Manipulating Audio II

Introduction to FFT & DFT

Discrete Fourier Transform (DFT)



Digital Image Processing 2 - RGB image & indexed image

Digital Image Processing 3 - Grayscale image I

Digital Image Processing 4 - Grayscale image II (image data type and bit-plane)

Digital Image Processing 5 - Histogram equalization

Digital Image Processing 6 - Image Filter (Low pass filters)

Video Processing 1 - Object detection (tagging cars) by thresholding color

Video Processing 2 - Face Detection and CAMShift Tracking












Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master