Python Forum
create a movie with python
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create a movie with python
#1
Dear all

I have some binary files with names ('Den_car_resample' +'sdf'+ str(n)+'.dat') where n changes from 0 to 25. 
I wrote a code to read these files and then plot the results with imshow command.
at the last step I want to create a movie . to do that, first, I saved the imshow plots in the .png Format and at the end of the program, I used the avconv command to stitch the images together .
unfortunately, my code creates a movie but it is empty. I don't know the reason exactly but I think, first, I have to define a frame to each plot and then create a movie.
now I have 2 questions:

1- would anyone please help me how can I finally create a movie with this code.
2- is there any method that without saving the figures, directly I create  a movie??

here is the code:

import os
import sys #exit the code at a specific line
import subprocess 
import sdf
import numpy as np
import matplotlib.pyplot as plt 
#import time
#import matplotlib.animation as animation
#from IPython import display
from matplotlib.font_manager import FontProperties
fp = FontProperties('Symbola')
 

##################### information from EPOCH input.deck
nx,ny= 1200, 1600
 
xmin=-100e-6
xmax = 110e-6
ymin = -200e-6
ymax = 200e-6
 
X =np.linspace(xmin,xmax,nx) #Generate linearly spaced vector. The spacing between the points is (x2-x1)/(n-1).
Y =np.linspace(ymin,ymax,ny)
#print len(X)
# print len(X)
 
 
#################
for n in range(0,5):
     nstr = str(n)#.zfill(4)
     #print nstr
######################..... reading Density of proton
 
     filename ="Den_pro_resample" +'_sdf_'+ str(n)+'.dat'
 
     with open(filename, 'rb') as f: #read binary file
     data = np.fromfile(f, dtype='float64', count=nx*ny) #float64 for Double precision float numbers
     Den_pro = np.reshape(data, [ny, nx], order='F')
     Den_pro = np.log10(Den_pro )
     #print Den_pro .max()

########################## Display proton density
     plt.subplot(312)
     fig2 = plt.imshow(Den_pro, extent=[X.min()*1e6, X.max()*1e6, Y.min()*1e6, Y.max()*1e6], vmin=24, vmax=30, cmap='brg',      aspect='auto') #cmap='jet', 'nipy_spectral','hot','gist_ncar'
#plt.suptitle('Den_pro')
     plt.title('sdf '+ str(n)+ '; Time= ' +str(n*50)+ 'ps',color='green', fontsize=15)
     plt.xlabel('x($\mu$m)')
     plt.ylabel('y($\mu$m)')
     plt.text(-80,-40,'Den_proton',color='red', fontsize=15)
     plt.colorbar()
 
     #plt.savefig( 'fig%04d.png' % n, bbox_inches='tight') #('test'+ str(n)+ '.png') 
 
     plt.pause(.1)
     plt.clf() 
 
 
############ create a movie

avconv -framerate 1 -i fig%04d.png -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p movie.mp4".split()
#ffmpeg -r 10 -i fig%04d.png -pix_fmt yuv420p movie.mp4".split()
Reply


Messages In This Thread
create a movie with python - by masoud - May-23-2017, 10:51 AM
RE: create a movie with python - by Ofnuts - May-23-2017, 12:26 PM
RE: create a movie with python - by masoud - May-23-2017, 02:17 PM
RE: create a movie with python - by Ofnuts - May-23-2017, 03:55 PM
RE: create a movie with python - by snippsat - May-23-2017, 03:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Video Movie Recommender oslagosboi 3 3,049 Feb-21-2023, 08:23 AM
Last Post: JhonSteve
  memory issue loading movie to numpy array djf123 1 2,343 Nov-07-2019, 06:19 AM
Last Post: ThomasL

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020