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

cropdetect and ffplay - 2020

ffmpeg_new_logo_161_42.png




Bookmark and Share





bogotobogo.com site search:






cropdetect

cropdetec can auto-detect crop size.

It calculate necessary cropping parameters and prints the recommended parameters through the logging system. The detected dimensions correspond to the non-black area of the input video.

	
cropdetect=limit:round:reset

The crop filter accepts the following options
(see http://www.ffmpeg.org/ffmpeg-filters.html#cropdetect):

  1. limit
    Set higher black value threshold, which can be optionally specified from nothing (0) to everything (255). An intensity value greater to the set value is considered non-black. Default value is 24.
  2. round
    Set the value for which the width/height should be divisible by. The offset is automatically adjusted to center the video. Use 2 to get only even dimensions (needed for 4:2:2 video). 16 is best when encoding to most video codecs. Default value is 16.
  3. reset_count, reset
    Set the counter that determines after how many frames cropdetect will reset the previously detected largest video area and start over to detect the current optimal crop area. Default value is 0.
    This can be useful when channel logos distort the video area. 0 indicates never reset and return the largest area encountered during playback.





Sample

We're going to use a movie clip (The Good, the Bad and the Ugly) as a sample.

If we run the clip using a media player, we can see the black letter box both top and bottom:

TheGoodTheBadAndTheUgly.png

If we run ffmpeg to see what it tells us about the crop:

	
$ ffmpeg -i TheGoodTheBadAndTheUgly.mp4 -vf cropdetect=24:16:0 dummy.mp4
...
[Parsed_cropdetect_0 @ 0x3704360] x1:0 x2:639 y1:43 y2:317 w:640 h:272 x:0 y:46 pts:181320 t:181.320000 crop=640:272:0:46
...

It lets us know the area to crop.

So, we now can crop the movie clip to make a new cropped clip:

ffmpeg -i TheGoodTheBadAndTheUgly.mp4 -vf crop=640:272:0:46 cropped_TheGoodTheBadAndTheUgly.mp4

The crop filter takes four arguments:

crop=out_width:out_height:x:y

where:

  1. out_width:output_height - the cropped output width and height of the video.
  2. x:y - the start coordinate from the top left corner.

As we can see from the picture below, the new cropped movie clip (cropped_TheGoodTheBadAndTheUgly.mp4) do not have the black letter box any more:

cropped_TheGoodTheBadAndTheUgly.png





ffplay

We can also use ffplay to get the information about the crop:

$ ffplay -i TheGoodTheBadAndTheUgly.mp4 -vf cropdetect=24:16:0
...
[Parsed_cropdetect_0 @ 0x7ff30c004520] x1:0 x2:639 y1:43 y2:317 w:640 h:272 x:0 y:46 pts:11440 t:11.440000 crop=640:272:0:46
...

As we can see, ffplay also gives us the same information about the cropping.









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