[PYTHON] Attempt of automatic speed adjustment of time-lapse movie (Part 1)

motivation

I rented a car a little in the United States in the summer I bought a suction cup mount and took pictures at regular intervals. (I think it was every 5 seconds)

Below is the first half of the Lime Laps on the way from Chicago to Pittsburgh.

The bar at the high speed gate does not go up near 0:34 and is backing up. Play slowly where such an event is occurring Plays nicely fast where other endless roads continue I wanted you to do something automatically.

However, I feel that the service area of 1:08 is a little too long. It's about 2 seconds, but it's long, so I'd like to make it about 1 second at the longest.

https://youtu.be/BOHDtW9_tlQ

ffmpeg

Generate video from serial number image with ffmpeg / Generate serial number image from video ~ How to prevent dropped frames ~ --Qiita I made a video with reference to the above site.

ffmpeg -framerate 30 -start_number 416 -i ./data/images/001/DSC%05d.JPG -vframes 6000 -vcodec libx264 -pix_fmt yuv420p -r 60 out.mp4

Suppose the images you want to time-lapse are from DSC00416.JPG to DSC03415.JPG. Output video using 30 images per second with a frame rate of 60 Since one image is used twice, I think it means a total of 6000 frames. I think you don't have to specify the -vrames option, but I specified 180 when I wanted to do a small test.

$ ffmpeg --help | grep -E "(-framerate)|(-start_number)|(-vframes)|(-vcodec)|(-pix_fmt)|(-r )"
-pix_fmts           show available pixel formats
-vframes number     set the number of video frames to output
-r rate             set frame rate (Hz value, fraction or abbreviation)
-vcodec codec       force video codec ('copy' to copy stream)

$ ffmpeg -pix_fmts | grep -E "(FLAGS NAME)|(yuv420p )"
FLAGS NAME            NB_COMPONENTS BITS_PER_PIXEL
IO... yuv420p                3            12

See ffmpeg --help full for details.

phash

Previously, when I searched for similar images

A brief summary of similar image search --Qiita

I used the library that uses phash introduced above from ruby. This time I wanted to link using ʻopencvfrom python, so I searched for one that can usephash` from python.

https://github.com/JohannesBuchner/imagehash

was.

Plot the hash value distance between each frame I tried to match the time-lapse movie. The middle is phash. https://youtu.be/oIoNYs4yLio

The sky is hiding in the bridge and it's blurry sweat Screen Shot 2016-12-11 at 17.45.18.png

I want to extract this area. .. .. Screen Shot 2016-12-11 at 17.47.01.png

I want to shorten here! (I feel like this is good) Screen Shot 2016-12-11 at 17.50.20.png

To the second part

I'd like to decide the window size and try various things such as local distribution. To be honest, I think there are people doing the same thing It's information gathering before spending time.

reference

Recommended Posts

Attempt of automatic speed adjustment of time-lapse movie (Part 1)
Attempt to automatically adjust the speed of time-lapse movies (Part 2)