用Jython/Python创建电影

2024-10-01 07:21:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一部电影,同时通过一个循环创建帧。这是节省,但只有第一帧(它作为电影播放-短片!)我试过各种各样的东西,却不知道自己做错了什么。谢谢

def synthesiseFrame(folder):
  folder =r"D:\FOLDER"
  m=0.5
  for x in range(1,121):
    pic=makeEmptyPicture(960,540)
    for x in range (0,960):
      for y in range (0,540):
        r=#some code
        g=#some code
        b=#some code
        color =makeColor (r,g,b)
        px= getPixel (pic, x, y)
        setColor(px, color)
    numStr=str(x)

    m=m+0.0125
    if x<10:
      writePictureTo(pic, folder+"\pic00"+numStr+".png")
    if x >=10 and x<100:
      writePictureTo(pic, folder+"\pic0"+numStr+".png")
    if x>=100:
      writePictureTo(pic,folder+"\pic"+numStr+".png")

  return movie

movie=synthesiseFrame(folder)
folder =r"D:\FOLDER"
file=r"D:\FOLDER\pic00.png"
movie=makeMovieFromInitialFile(file)
writeQuicktime(movie,"D:\FOLDER\movie.mov", 30)
playMovie(movie)

Tags: inforif电影pngcoderangesome
2条回答

我改变了你的密码。在

  • 使用了“%03d”%x而不是if*3。在
  • 将“pic00.png”更改为“pic001.png”,因为synthesiseFrame中的循环从1开始。在
  • '\'->;os.path.join操作系统(..);如果没有,请放入import os

def synthesiseFrame(folder):
  m = 0.5
  for frameNumber in range(1,121):
    pic=makeEmptyPicture(960,540)
    for x in range (0,960):
      for y in range (0,540):
        r = #some code
        g = #some code
        b = #some code
        color =makeColor (r,g,b)
        px= getPixel (pic, x, y)
        setColor(px, color)
    m += 0.0125
    writePictureTo(pic, os.path.join(folder, 'pic%03d.png' % frameNumber)) # 3 if -> no if
  return movie

movie = synthesiseFrame(folder)
folder = r"D:\FOLDER"
file = r"D:\FOLDER\pic001.png" # 00 -> 001
movie=makeMovieFromInitialFile(file)
writeQuicktime(movie,"D:\FOLDER\movie.mov", 30)
playMovie(movie)

编辑

  • x(在外循环中)->;frameNumber

我在JES video functions和您的代码中的第一眼就告诉我类似(完全有效的示例):

import os
import random

def synthesizeFrameAndCreateMovie(folder):

  # Create an empty movie to receive the frames
  movie = makeMovie()

  # Compute & save the frames
  w = 40
  h = 25
  nb_frames = 60       # Will give 60 frames at 30 fps => movie duration : 2 sec.
  for z in range(0, nb_frames):
    pic=makeEmptyPicture(w, h)
    for x in range (0, w):
      for y in range (0, h):
        #makeColor() takes red, green, and blue (in that order) between 0 and 255
        r = random.randint(0, 255)
        g = random.randint(0, 255)
        b = random.randint(0, 255)
        color = makeColor(r,g,b)
        px = getPixel(pic, x, y)
        setColor(px, color)

    # Create one frame and inject in the movie object
    filename = os.path.join(folder, 'pic%03d.png' % z)
    writePictureTo(pic, filename)
    addFrameToMovie(filename, movie)

  # return the movie
  return movie

movie = synthesizeFrameAndCreateMovie("D:\\FOLDER")
print movie
#writeQuicktime(movie,"D:\\FOLDER\\movie.mov", 30)
playMovie(movie)


输出(帧):


……enter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description here。。。。。。在


编辑:

更有趣的是:动画一行(代码采用here)。。。在

^{pr2}$


输出(帧):


……enter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description here。。。。。。在


相关问题 更多 >