Сделайте видео, используя Python+GST из набора картин `yyyy-mm-dd` dd`
Вопрос
У меня есть каталог с набором YYYY-MM-DD
-Дюмеруемые файлы как SO:
pictures/
2010-08-14.png
2010-08-17.png
2010-08-18.png
Как я могу использовать Python Gstreamer, чтобы превратить эти файлы в видео? Имена файлов должны оставаться прежними.
У меня есть программа, которая может превратить постепенно пронумерованные PNG в видео, мне просто нужно адаптировать ее для использования устаревших файлов.
Решение
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?
Другие советы
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 )
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)