Skip to content

Instantly share code, notes, and snippets.

@jrmgx jrmgx/
Last active Jun 28, 2017

What would you like to do?
Scripts to generate theses kind of images :

This will help you use the scripts

Step 1

You need to take a picture of the movie every second,
this can be done with ffmpeg

$ ffmpeg -i my_movie.mkv -vf fps=1 my_movie/img%06d.png

Step 2

Then you have to resize each picture to 100px x 100px,
we are going to use the resize.php script

$ for f in my_movie/*.png; do php resize.php $f; done
$ mkdir my_movie/100
$ mv my_movie/*-100.png my_movie/100

Step 3

You need to do a little clean up and remove the introduction and the generic.
Then edit the align.php file, and navigate to the images directory to start the script

$ cd my_movie/100
$ php ../../align.php

For reference

To take a list of images that are padded with zeros (pic0001.png, pic0002.png…. etc) use the following command:

ffmpeg -r 60 -f image2 -s 1920x1080 -i pic%04d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4

  • -r is the framerate (fps)
  • -crf is the quality, lower means better quality, 15-25 is usually good
  • -s is the resolution
  • -pix_fmt yuv420p specifies the pixel format, change this as needed
// This value have to be adapted for each movie
// it is the square root of the number of images for the movie
$loop = 87;
$width = 100;
$row = 0;
$col = -1;
$imageFinal = imagecreatetruecolor($loop * $width, $loop * $width);
$cpt = 0;
foreach (glob("*-100.png") as $file) {
$imageSource = imagecreatefrompng($file);
if ($cpt % $loop == 0) {
$row = 0;
else {
$x = $row * $width;
$y = $col * $width;
echo ".";
imagecopyresampled($imageFinal, $imageSource, $x, $y, 0, 0, $width, $width, $width, $width);
// If you want, you can save an intermediary image
//imagepng($imageFinal, "finale.png");
imagejpeg($imageFinal, "finale.jpg", 80);
echo "done\n";
// Image size
$width = $height = 100;
// Get the image data
$filename = $argv[1];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$destname = str_replace('.' . $ext, '', $filename);
$destname = strtolower($destname);
list($widthSource, $heightSource) = getimagesize($filename);
$min = min($widthSource, $heightSource);
// Resize the image
$imageInterm = imagecreatetruecolor($width, $height);
$imageSource = imagecreatefrompng($filename);
imagecopyresampled($imageInterm, $imageSource, 0, 0, ($widthSource-$heightSource)/2, 0, $width, $height, $min, $min);
// Save the image
imagepng($imageInterm, $destname . '-100.png');
echo "done\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.