moviepy slideshow with transitions, stuck at adding crossfade transition - moviepy

Making a slideshow in moviepy works without issue but i just cant figure out how to add a crossfade transition between each frame. I'm very new to python and moviepy and could really use some help. Thanks
img_clips = []
path_list = []
for image in os.listdir('E:/moviepy'):
if image.endswith(".png"):
path_list.append(os.path.join('E:/moviepy/', image))
# creating slide for each image
for img_path in path_list:
slide = ImageClip(img_path, duration=0.2)
img_clips.append(slide)
# concatenating slides
video_slides = concatenate_videoclips(img_clips, method='compose')
# exporting final video
video_slides.write_videofile("E:/moviepy/output_video.mp4", fps=30)

Related

Moviepy's TextClip displays gibberish

What I am trying to do is to add a short text at specific timeframe of a mp4 video.
I have this code:
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("video.mp4")
# clipping of the video
# getting video for only starting 10 seconds
clip = clip.subclip(0, 5)
# Reduce the audio volume (volume x 0.8)
clip = clip.volumex(0.8)
text = "Hello world!"
# Generate a text clip
txt_clip = TextClip(text, fontsize = 75, color = 'black')
# setting position of text in the center and duration will be 10 seconds
txt_clip = txt_clip.set_pos('center').set_duration(2).set_start(3)
# Overlay the text clip on the first video clip
video = CompositeVideoClip([new_clip, txt_clip])
# showing video
video.ipython_display(width = 280)
Everything works well except that the text changes suddenly to something like '#/tmp/tmpq5b_zzvf.txt' which is obviously not the intended effect.
Beside googling, I tried dir(txt_clip) to see if I could change it manually, and it does have a txt attribute associated with it. but inserting txt_clip.txt = "Hello world" right afterward does not do anything.
What could be the culprit?

Adobe Indesign Script to Crop Selected Images

Looking for some help in figuring out how to write a script to crop images in Indesign. The images are of two sides of an object, so usually I drag the image in from the folder, copy it and crop both images vertically so I end up with separate objects for the left-hand(front) and right-hand(back) sides of whatever I'm playing with.
I had a search of forums but most of the scripts I found were aimed at a simple resize rather than basically cutting an image in half vertically while leaving the size unchanged - can anyone help me get started on this?
Thanks!
Try this:
var sel = app.selection[0];
app.copy();
var gb = sel.geometricBounds;
gb[3] -= (gb[3]-gb[1])/2;
sel.geometricBounds = gb;
app.pasteInPlace();
var sel = app.selection[0];
var gb = sel.geometricBounds;
gb[1] += (gb[3]-gb[1])/2;
sel.geometricBounds = gb;
It 'crops' selected image (left-hand half), copy/pastes (inplace) the image again and crops its again (right-hand half)

MiniMagick Resize Image

I'm trying to use MiniMagick to resize 2 images and overlay one on top of the other. Heres the code I am using
require "mini_magick"
first_image = MiniMagick::Image.new("spider.jpg")
first_image = first_image.resize("250x250")
second_image = MiniMagick::Image.new("q.png")
second_image = second_image.resize("250x250")
result = first_image.composite(second_image) do |c|
c.compose "Over" # OverCompositeOp
c.gravity "center"
# c.resize("250x250")
end
result.write "output.jpg"
This overlays the images but neither is resized and the overlay image ends up awkwardly cropped. Ive tried making both the same size, making the bigger overlay image smaller and the smaller image bigger, but none seem to work. Any advice would be highly appreciated.

Corona - create regular display objects from sprite sheets?

This is normal way of displaying an image:
local img = display.newImage("image.png");
But doesn't it save memory to put all your images in one large image and export from Zwoptex? There is documentation for creating animated sprites from sprite sheets, but what about just pulling a single image from a sprite sheet?
local zwoptexData = require "sheet1"
local data = zwoptexData.getSpriteSheetData()
//then what?
The commands to make a static image from a tile sheet look like this:
local tileSheet = sprite.newSpriteSheet("tiles.png", 64, 64)
local tileSet = sprite.newSpriteSet(tileSheet, 1, 10)
local tile = sprite.newSprite(tileSet)
tile.currentFrame = 5
That assumes all the tiles on the sheet are 64x64 but you could easily adapt those commands to use your sprite sheet data. The important things to note are newSprite() and .currentFrame
EDIT: You commented that you can't figure out how to use sprite data with this, so the modified code is
local data = require("tiles.lua")
local tileSheet = sprite.newSpriteSheetFromData("tiles.png", data.getSpriteSheetData())
local tileSet = sprite.newSpriteSet(tileSheet, 1, 3)
local tile = sprite.newSprite(tileSet)
tile.currentFrame = 2
To learn how this works refer to
http://developer.anscamobile.com/reference/sprite-sheets

Speed up image display

I am using the PIL (python image library) to crop a very large image and present the cropped area to the interface. The problem Im having is that the process is taking too long. When the user clicks on the image to crop it, the image takes quite a long time to show up on the sizer I attach it to.
I tried doing this two ways: First I tried saving the cropped area as an image to the disk, and loaded it on the fly into the sizer. The second attempt was to create an empty image and convert the pil image into the wx image and load that onto the sizer. Surprising to me is that the first method of writing to the disk feels faster than the second method of managing it in memory. Here are the code samples:
First method:
area = image_object.crop(self.cropxy)
area.save(CROP_IMAGE, 'jpeg')
crop_image = wx.Image(CROP_IMAGE, wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
crop_bitmap = wx.StaticBitmap(self.crop_panel, bitmap=crop_image, name="Cropped Image")
crop_bitmap.CenterOnParent()
crop_bitmap.Refresh()
Second method:
area = image_object.crop(self.cropxy)
image = wx.EmptyImage(area.size[0], area.size[1])
image.SetData(area.convert("RGB").tostring())
crop_image = wx.BitmapFromImage(image)
crop_bitmap = wx.StaticBitmap(self.crop_panel, bitmap=crop_image, name="Cropped Image")
crop_bitmap.CenterOnParent()
crop_bitmap.Refresh()
Is there a better way to do this so that the image will now show up so slowly?
So in order to solve something somewhere else in the interface, when I queue up my images I decided to pre-load the wxImage objects. Never had to before when they were much smaller.
Anyway - I found some code on google that would allow me to convert between wxImage objects and PIL objects and by doing so, I can convert the in-memory wxImage object to the PIL object, crop it, and convert it back to the image just in time to display it. This is 'Blazing' fast by comparison. You just hardly take your finger off the mouse and the crop shows just fine.
Here are the conversion routines:
def pil_to_image(self, pil, alpha=True):
""" Method will convert PIL Image to wx.Image """
if alpha:
image = apply( wx.EmptyImage, pil.size )
image.SetData( pil.convert( "RGB").tostring() )
image.SetAlphaData(pil.convert("RGBA").tostring()[3::4])
else:
image = wx.EmptyImage(pil.size[0], pil.size[1])
new_image = pil.convert('RGB')
data = new_image.tostring()
image.SetData(data)
return image
def image_to_pil(self, image):
""" Method will convert wx.Image to PIL Image """
pil = Image.new('RGB', (image.GetWidth(), image.GetHeight()))
pil.fromstring(image.GetData())
return pil

Resources