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

Basic slide show from images - 2020

ffmpeg_new_logo_161_42.png




Bookmark and Share





bogotobogo.com site search:






Images files

Because I have image files with different resolutions, I need to make them to have the same size. So, I run the following script for around 43 files (e01.jpg-e39.jpg). The output png files' resolution is set to 480x360 and with the same name as input files:

import os
import subprocess 

def resize_files(fname):
	# ffmpeg -i a.jpg -vf scale=640:480 a.png	
	out_fname = fname.replace('jpg','png')
	#print out_fname
	subprocess.call(['ffmpeg', '-i', fname, '-vf', 'scale=640:480', out_fname ])	

def listFiles(dir):
	basedir = dir
	subdirlist = []
	for item in os.listdir(dir):
		fullpath = os.path.join(basedir,item)
		if os.path.isdir(fullpath):
			print  'dir item=',fullpath
			subdirlist.append(fullpath)
		else:
			print 'file item=',fullpath
			if item.endswith('.jpg'):
				resize_files(fullpath)

	for subdir in subdirlist:
		listFiles(subdir)

if __name__ == '__main__':
	listFiles('.');

So, the code will generate files with the same resolution. (e01.png-e39.png).




Making slideshow

Now, it's time to create a video (using the encoder libx264) from series of numerically sequential images such as e01.png, e02.png, e03.png, etc.

As explained in Create a video slideshow from images , we can specify two frame rates:

  1. The rate according to which the images are read, by setting -r before -i. The default for reading input is -r 25 which will be set if no -r is specified.
  2. The output frame rate for the video stream by setting -r after -i, or by using the fps filter. If we want the input and output frame rates to be the same, then just declare an input -r and the output will inherit the same value.

By using a separate -r (frames per second) for the input and output we can control the duration at which each input is displayed and tell ffmpeg the frame rate we want for the output file. If the input -r is lower than the output -r then ffmpeg will duplicate frames to reach our desired output frame rate. If the input -r is higher than the output -r then ffmpeg will drop frames to reach your desired output frame rate.

ffmpeg -r 1/5 -i e%02d.png -c:v libx264 -r 30 -pix_fmt yuv420p EinsteinSlideShow.mp4
  1. -r 1/5: each image will have a duration of 5 seconds (the inverse of 1/5 frames per second).
  2. e%02d.png: sequential image input.
  3. -c:v: video coder.
  4. libx264: encoder library.
  5. -r 30: will have a frame rate of 30 fps by duplicating the frames accordingly.
  6. -pix_fmt yuv420p: pixel format.
    "Y'UV420p is a planar format, meaning that the Y', U, and V values are grouped together instead of interspersed. The reason for this is that by grouping the U and V values together, the image becomes much more compressible. When given an array of an image in the Y'UV420p format, all the Y' values come first, followed by all the U values, followed finally by all the V values." - wiki.
    "By default when using libx264, and depending on your input, ffmpeg will attempt to avoid color subsampling. Technically this is preferred, but unfortunately almost all video players, excluding FFmpeg based players, and many online video services only support the YUV color space with 4:2:0 chroma subsampling. Using the options -pix_fmt yuv420p or -vf format=yuv420p will maximize compatibility." - ffmpeg.org.
  7. EinsteinSlideShow.mp4: output video file name.




Slideshow Transcoding

To display the slide show for several browsers, we need to convert mp4 to webm and ogv:

ffmpeg -i EinsteinSlideShow.mp4 EinsteinSlideShow.webm
ffmpeg -i EinsteinSlideShow.mp4 EinsteinSlideShow.ogv

Here is the slide show:

Your browser does not support the video tag.



Files are here

Get all the files including each slide picture and the output slideshow files: SlideShow.zip.

Or the output slide show:

  1. EinsteinSlideShow.mp4
  2. EinsteinSlideShow.ogv
  3. EinsteinSlideShow.webm








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