Timelapse/Processing: Difference between revisions
From charlesreid1
| Line 23: | Line 23: | ||
=Wrangling Large Numbers of Files= | =Wrangling Large Numbers of Files= | ||
When I finished with my first timelapse, I was left with 16,636 jpg files over an approximately 9 hour period. | When I finished with my first timelapse, I was left with 16,636 jpg files over an approximately 9 hour period. That's a pretty unwieldy number of files, and at 200 KB a pop, it's also a lot of disk space. That means stitching together movies, applying effects, &c will take a long time. | ||
Normally, I would turn all the photos into a "baseline" movie - one that shows everything, and makes it easy to narrow in on the interesting parts. However, with 16,000 files, this would be a long, big movie. I decided to throw out half the photos (can get more later). | |||
===Getting the filename list=== | |||
With 16,000 files, if you try and run <code>ls *.jpg</code>, ls will raise an error (too many arguments). Instead, just list everything (no arguments), and search for jpg files: | |||
<pre> | |||
/bin/ls -1 | grep jpg > files | |||
</pre> | |||
Now if you examine files you'll see the interval between photos is very erratic - it was programmed to be 2 seconds, but it is all over the place - sometimes 3, sometimes 2. | |||
I wanted to throw out every other photo, and I couldn't do it based on the digits or the numbering. The intervals were uneven, and there were multiple hours of photos. So, I decided to just cut out every other photo. | |||
===Chopping up the filename list=== | |||
To remove every other file, I needed to feed the output of the above command, <code>ls -1 | grep jpg</code>, to a program that would print out every other line - good task for a one-liner in sed or awk. | |||
Here's an awk one-liner to print only odd lines (only the even lines in awk, which numbers lines starting at 0): | |||
<pre> | |||
awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}' | |||
</pre> | |||
Here's that script in action: | |||
<pre> | |||
$ cat multiline | |||
line1 | |||
line2 | |||
line3 | |||
line4 | |||
line5 | |||
line6 | |||
line7 | |||
line8 | |||
line9 | |||
line10 | |||
$ cat multiline | awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}' | |||
line1 | |||
line3 | |||
line5 | |||
line7 | |||
line9 | |||
</pre> | |||
Now that can be applied to an external file, | |||
<pre> | |||
$ awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}' files | |||
</pre> | |||
This prints out a list of files to keep. The easiest way to do this is probably to make a directory to hold the downsampled photos, and (if desired) delete the remaining photos. To move the list of photos obtained in the prior step, you can use xargs to feed the filenames to the "mv" command: | |||
<pre> | |||
$ mkdir my_timelapse | |||
$ xargs -I% mv % my_timelapse/. | |||
</pre> | |||
To stitch it all together, save your odd-numbered files in a directory, and remove all the other remaining photos: | |||
<pre> | |||
$ mkdir my_timelapse | |||
$ awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}' files | |||
</pre> | |||
=Applying Effects= | =Applying Effects= | ||
Revision as of 22:58, 30 July 2016
Overview
Procedure
The procedure for post-processing videos looks like this:
- Obtain and wrangle a large number of sequentially numbered jpeg files (xargs)
- Turn mass of jpeg files into video (ffmpeg)
- Downsample (xargs/unix)
- Figure out what effects to apply - single jpeg file (lightroom)
- Apply desired effects en-masse - all jpeg files (lightroom)
- Make more videos (ffmpeg)
Tools
ffmpeg: One of the most useful tools for post-processing video is ffmpeg. There are some notes on ffmpeg on the wiki already: Ffmpeg. Most of the material here will be a variation on that.
xargs: Another useful tool for post-processing video is xargs. Notes on xargs on the wiki already: Xargs. This is a unix command-line utility that forks a single process or single command to multiple inputs. This is extremely useful to streamlining image processing, which can be done in parallel. (It is also useful for mass-renaming files.)
ImageMagick: the command-line "convert" tool is the interface for Image Magick, and this is an extremely handy tool if you need to do any mass-manipulation of images from the command line - for example, shrinking, cropping, stretching, filtering, masking, sharpening, blurring. You name it, you can probably do it with ImageMagick. When combined with convert and xargs, you become unstoppable.
There are also some interesting side topics, such as image averaging using the Python_Imaging_Library. This allows for smoother, more stretched-out timelapse videos.
Wrangling Large Numbers of Files
When I finished with my first timelapse, I was left with 16,636 jpg files over an approximately 9 hour period. That's a pretty unwieldy number of files, and at 200 KB a pop, it's also a lot of disk space. That means stitching together movies, applying effects, &c will take a long time.
Normally, I would turn all the photos into a "baseline" movie - one that shows everything, and makes it easy to narrow in on the interesting parts. However, with 16,000 files, this would be a long, big movie. I decided to throw out half the photos (can get more later).
Getting the filename list
With 16,000 files, if you try and run ls *.jpg, ls will raise an error (too many arguments). Instead, just list everything (no arguments), and search for jpg files:
/bin/ls -1 | grep jpg > files
Now if you examine files you'll see the interval between photos is very erratic - it was programmed to be 2 seconds, but it is all over the place - sometimes 3, sometimes 2.
I wanted to throw out every other photo, and I couldn't do it based on the digits or the numbering. The intervals were uneven, and there were multiple hours of photos. So, I decided to just cut out every other photo.
Chopping up the filename list
To remove every other file, I needed to feed the output of the above command, ls -1 | grep jpg, to a program that would print out every other line - good task for a one-liner in sed or awk.
Here's an awk one-liner to print only odd lines (only the even lines in awk, which numbers lines starting at 0):
awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}'
Here's that script in action:
$ cat multiline
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
$ cat multiline | awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}'
line1
line3
line5
line7
line9
Now that can be applied to an external file,
$ awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}' files
This prints out a list of files to keep. The easiest way to do this is probably to make a directory to hold the downsampled photos, and (if desired) delete the remaining photos. To move the list of photos obtained in the prior step, you can use xargs to feed the filenames to the "mv" command:
$ mkdir my_timelapse $ xargs -I% mv % my_timelapse/.
To stitch it all together, save your odd-numbered files in a directory, and remove all the other remaining photos:
$ mkdir my_timelapse
$ awk 'NR % 2 {print} !(NR % 2) && /pattern/ {print}' files
Applying Effects
Single photo
En masse
Creating Video from Image Files
These notes are based on the notes at the Ffmpeg page.
Renaming Files
One of the quirks of ffmpeg is that, if you are converting a large number of files, they have to be sequentially numbered, STATING WITH 0 OR 1.
If you have sequentially-numbered images but they do not start with 0 or 1, you have two choices:
- Hack it - create multiple copies of the very first frame, and back-number them until they go to 1.
- Be more sophisticated - list all files in order, then append a _1, _2, _3, etc.