0

I have a directory with a set of YYYY-MM-DD-dated files in as so:

pictures/
    2010-08-14.png
    2010-08-17.png
    2010-08-18.png

How can I use Python GStreamer to turn these files into a video? The filenames must remain the same.

I have a program that can turn incrementally numbered PNGs into a video, I just need to adapt it to use dated files instead.

Zaz
  • 46,476
  • 14
  • 84
  • 101
  • How much do you know how to do -- is this a question about GStreamer, Python, the bindings, what? – Katriel Aug 19 '10 at 10:00
  • @katrielalex: Just the date-specific part. I've updated the question. – Zaz Aug 19 '10 at 14:00
  • Still not enough information, I'm afraid -- *how* does your program take in these incrementally-numbered PNGs? That is, do you want a script to rename them? To sort the list of filenames? To make symlinks? – Katriel Aug 19 '10 at 14:07
  • @katrielalex: I'm asking *you* how my program should take in the PNGs. – Zaz Aug 19 '10 at 15:29
  • `os.listdir()`? If you want them sorted code is below. – Katriel Aug 19 '10 at 16:16

3 Answers3

0

The easiest would be to create link/rename those file to a sequence number (that should be easily doable with a n=0 for f in $(ls * | sort); do ln -s $f $n && $n=$((n+1))

Then you should be able to do:

gst-launch multifilesrc location=%d ! pngdec ! theoraenc ! oggmux ! filesink location=movie.ogg

It would have more sense to use a different encoder than theora perhaps, to have all pictures as keyframe, perhaps with MJPEG?

elmarco
  • 31,633
  • 21
  • 64
  • 68
0

It's easy enough to sort the filenames by date:

import datetime, os

def key( filename ):
    return datetime.datetime.strptime( 
        filename.rsplit( ".", 1 )[ 0 ], 
        "%Y-%m-%d"
    )

foo = sorted( os.listdir( ... ), key = key )

Maybe you want to rename them?

count = 0
def renamer( name ):
    os.rename( name, "{0}.png".format( count ) )
    count += 1

map( renamer, foo )
Katriel
  • 120,462
  • 19
  • 136
  • 170
0

Based on the Bash code elmarco posted, here's some basic Python code that will symlink the dated files to sequentially numbered ones in a temporary directory:

# Untested example code. #

import os tempfile shutil

# Make a temporary directory: `temp`:
temp = tempfile.mkdtemp()  

# List photos:
files = os.listdir(os.path.expanduser('~/.photostory/photos/'))

# Sort photos (by date):
files.sort()

# Symlink photos to `temp`:
for i in range(len(files)):
    os.symlink(files[i], os.path.join(temp, str(i)+'.png')  

# Perform GStreamer operations on `temp`. #

# Remove `temp`:
shutil.rmtree(temp)
Community
  • 1
  • 1
Zaz
  • 46,476
  • 14
  • 84
  • 101