我有一组目录 YYYY-MM-DD- 以下情况:

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

如何使用Python Gstreamer将这些文件转换为视频?文件名必须保持不变。

我有一个可以将逐渐编号的PNG变成视频的程序,我只需要调整它以改用过时的文件即可。

有帮助吗?

解决方案

最简单的是创建链接/将这些文件重命名为序列编号(应该可以轻松地使用 n=0 for f in $(ls * | sort); do ln -s $f $n && $n=$((n+1))

那么您应该能够做:

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

也许使用与Theora不同的编码器,将所有图片作为关键帧,也许使用MJPEG有更多的意义?

其他提示

在日期之前对文件名进行排序非常容易:

import datetime, os

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

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

也许您想重命名它们?

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

map( renamer, foo )

基于 Bash代码Elmarco发布了, ,以下是一些基本的Python代码,可以将日期文件链接到临时目录中的依次编号:

# 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)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top