使用 Python+GST 从一组“YYYY-MM-DD”日期的图片制作视频

发布于 2024-09-15 18:19:56 字数 286 浏览 6 评论 0原文

我有一个目录,其中包含一组 YYYY-MM-DD 日期的文件,如下所示:

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

How can I use Python GStreamer to put those files into a video?文件名必须保持相同。

我有一个程序可以将递增编号的 PNG 转换为视频,我只需要对其进行调整以使用日期文件即可。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

双马尾 2024-09-22 18:19:56

最简单的方法是创建链接/将这些文件重命名为序列号(这应该可以通过 $(ls * | sort) 中的 f 的 n=0 轻松实现;do ln -s $f $n & & $n=$((n+1))

那么你应该能够这样做:

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

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

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?

鯉魚旗 2024-09-22 18:19:56

按日期对文件名进行排序很容易:

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 )

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 )
命比纸薄 2024-09-22 18:19:56

基于 elmarco 发布的 Bash 代码,这里有一些基本的 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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文