Advertisement
shihab2196

make_video_from_image

Jan 26th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Author: Shihab Ahmed
  4. Created on Fri Jan 26 01:17:27 2024
  5. """
  6.  
  7. import os
  8. import imageio
  9.  
  10. # Path to the GIF file
  11. folder_path = r'C:\Users\arup2\OneDrive - University of California Merced\Desktop\LAMMPS\Post Processing\lammps_processing\python_outputs\pathway'
  12.  
  13. # Output GIF file name (e.g., output.gif)
  14. output_video = folder_path+'\\output.mp4'
  15.  
  16. # Create a list of PNG file paths sorted by filename
  17. png_files = sorted([os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith('.png')],
  18.                    key=lambda x: x[-10:])
  19.  
  20. # Create a list to store the frames
  21. frames = []
  22.  
  23. # Read each PNG file and append it to the frames list
  24. for png_file in png_files:
  25.     img = imageio.imread(png_file)
  26.     frames.append(img)
  27.  
  28. # Create the video using imageio
  29. imageio.mimsave(output_video, frames, fps=1.3)  # Adjust the fps (frames per second) as needed
  30.  
  31. print(f"Video '{output_video}' created successfully.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement