Beispiel #1
0
def main(options):
  '''
  Video to img2text
  '''
  if(options.video is not None):
    # 1) Extract frames
    extract_frames(options.video, TEMP_DIR, FPS)

    # 2) Run model with images. Send batches of 100.
    imgs = glob(TEMP_DIR + '/*.jpg')
    amount = len(imgs)
    batches = [[]]
    for i in range(len(imgs)):
      if (i is not 0 and i%100 == 0):
        batches.append([imgs[i]])
      else:
        batches[-1].append(imgs[i])

    imgs_batches = []
    for batch in batches:
      imgs_batches.append(','.join(batch))
  
    # 3) Run model
    model = im2text(TEMP_DIR, TRANSCRIPT_DIR, options.name, imgs_batches, amount)
    if (options.api):
      return model

  if(options.input_data is not None):
    # 4) Make a movie
    make_movie(OUTPUT_DIR, options.input_data, options.input_seconds, options.transform_src, options.transform_data, False)
def convert(input_url, output_file, max_frames, rate=-1):
	if os.path.exists(tmp_dir):
		shutil.rmtree(tmp_dir)
	os.mkdir(tmp_dir)
	start = datetime.datetime.now()
	get_mjpeg.get(input_url, tmp_dir, max_frames)
	end = datetime.datetime.now()
	delta = end - start
	if rate == -1:
		rate = int(max_frames / delta.total_seconds())
	make_movie.make_movie(tmp_dir, output_file, max_frames, rate)
def convert(input_url, output_file, max_frames, rate=-1):
    if os.path.exists(tmp_dir):
        shutil.rmtree(tmp_dir)
    os.mkdir(tmp_dir)
    start = datetime.datetime.now()
    get_mjpeg.get(input_url, tmp_dir, max_frames)
    end = datetime.datetime.now()
    delta = end - start
    if rate == -1:
        rate = int(max_frames / delta.total_seconds())
    make_movie.make_movie(tmp_dir, output_file, max_frames, rate)
def convert_mp4(input_file, output_file):
    if os.path.exists(tmp_dir):
        shutil.rmtree(tmp_dir)
    os.mkdir(tmp_dir)

    cmd = [
        ffmpeg_location, '-i', input_file, '-threads', '2', '-y',
        '%s/%%05d.jpg' % tmp_dir
    ]
    subprocess.call(cmd)
    make_movie.make_movie(tmp_dir, output_file, 99999, 30)
def convert_mp4(input_file, output_file):
	if os.path.exists(tmp_dir):
		shutil.rmtree(tmp_dir)	
	os.mkdir(tmp_dir)

	cmd = [ffmpeg_location,
		'-i', input_file,
		'-threads', '2', '-y', 
		'%s/%%05d.jpg' % tmp_dir
		]
	subprocess.call(cmd)
	make_movie.make_movie(tmp_dir, output_file, 99999, 30)
def run():
	Nx = 100
	tEnd = 20
	CFL = 0.2
	xmin = -1
	xmax = 1
	dx = xmax-xmin / float(Nx)

	x = np.linspace(xmin,xmax,Nx)

	u0 = InitialConditions(x).get_sin_IC()

	t = 0

	u = u0

	frames = []

	while t < tEnd:
		dt = CFL*dx/max(np.abs(u))-CFL*dx/max(np.abs(u))/2
		if (t+dt > tEnd) or (dt == tEnd-t):
			break

		t=t+dt

		uo = u
		flux , dflux = Flux().linear(u)
		flux = map(flux, u)
		dflux = map(dflux,u)
		S = np.zeros([len(u),1])

		# 1st stage RGKT
		dF = WENO5resAdv1d(u,flux,dflux,S,dx)
		u = uo-dt*dF
		
		flux , dflux = Flux().linear(u)
		flux = map(flux, u)
		dflux = map(dflux,u)
		# 2nd Stage
		dF = WENO5resAdv1d(u,flux,dflux,S,dx)
		u = 0.75*uo+0.25*(u-dt*dF)

		flux , dflux = Flux().linear(u)
		flux = map(flux, u)
		dflux = map(dflux,u)
		# 3rd stage
		dF = WENO5resAdv1d(u,flux,dflux,S,dx)
		u = (uo+2*(u-dt*dF))/3

		frames.append(u)
		
	mov.make_movie(frames,x)
def run():
    Nx = 100
    tEnd = 20
    CFL = 0.2
    xmin = -1
    xmax = 1
    dx = xmax - xmin / float(Nx)

    x = np.linspace(xmin, xmax, Nx)

    u0 = InitialConditions(x).get_sin_IC()

    t = 0

    u = u0

    frames = []

    while t < tEnd:
        dt = CFL * dx / max(np.abs(u)) - CFL * dx / max(np.abs(u)) / 2
        if (t + dt > tEnd) or (dt == tEnd - t):
            break

        t = t + dt

        uo = u
        flux, dflux = Flux().linear(u)
        flux = map(flux, u)
        dflux = map(dflux, u)
        S = np.zeros([len(u), 1])

        # 1st stage RGKT
        dF = WENO5resAdv1d(u, flux, dflux, S, dx)
        u = uo - dt * dF

        flux, dflux = Flux().linear(u)
        flux = map(flux, u)
        dflux = map(dflux, u)
        # 2nd Stage
        dF = WENO5resAdv1d(u, flux, dflux, S, dx)
        u = 0.75 * uo + 0.25 * (u - dt * dF)

        flux, dflux = Flux().linear(u)
        flux = map(flux, u)
        dflux = map(dflux, u)
        # 3rd stage
        dF = WENO5resAdv1d(u, flux, dflux, S, dx)
        u = (uo + 2 * (u - dt * dF)) / 3

        frames.append(u)

    mov.make_movie(frames, x)
    def Advec1D(self, FinalTime, movie=0):
        """ Integrate 1D advection until FinalTime starting with
        initial the condition, u """

        time = 0

        u0 = self.conditions.ic()
        #Runge-Kutta residual storage
        resu = np.zeros([self.Np, self.K])
        # compute time step size
        xmin = min(abs(self.x[0, :] - self.x[1, :]))
        CFL = 0.5
        dt = CFL / (2 * np.pi) * np.transpose(xmin)[0][0]
        dt = .5 * dt

        Nsteps = np.ceil(FinalTime / float(dt))
        dt = FinalTime / float(Nsteps)

        a = 2 * np.pi  # advection speed

        frames = []
        times = []
        step = 0
        for tstep in range(0, int(Nsteps)):
            #for INTRK in range(0,5):
            #    # Runge kutta time integration 4 stage 4th order
            #    timelocal = time + self.rgkt['rk4c'][INTRK]*dt
            #    rhsu = self.AdvecRHS1D(u0, timelocal, a)
            #    resu = self.rgkt['rk4a'][INTRK]*resu + dt*rhsu
            #    u0 = u0 + self.rgkt['rk4b'][INTRK]*resu
            u0 = self.SSP(u0, time, a, dt)
            times.append(time)
            time = time + dt
            frames.append(u0.flatten()[0])

        if movie:
            mov.make_movie(frames,
                           self.x.flatten()[0], times,
                           "dg_pulse_ssp" + str(self.N))
        return u0
Beispiel #9
0
    def Advec1D(self, FinalTime, movie=0):
        """ Integrate 1D advection until FinalTime starting with
        initial the condition, u """

        time = 0
       
        u0 = self.conditions.ic()
        #Runge-Kutta residual storage
        resu = np.zeros([self.Np, self.K])
        # compute time step size
        xmin = min(abs(self.x[0,:]-self.x[1,:]))
        CFL = 0.5
        dt = CFL/(2*np.pi)*np.transpose(xmin)[0][0]     
        dt = .5*dt
        
        Nsteps = np.ceil(FinalTime/float(dt))
        dt = FinalTime/float(Nsteps)
        
        a = 2*np.pi # advection speed
        
        frames = []
        times = []
        step = 0
        for tstep in range(0, int(Nsteps)):
            #for INTRK in range(0,5):
            #    # Runge kutta time integration 4 stage 4th order
            #    timelocal = time + self.rgkt['rk4c'][INTRK]*dt
            #    rhsu = self.AdvecRHS1D(u0, timelocal, a)
            #    resu = self.rgkt['rk4a'][INTRK]*resu + dt*rhsu
            #    u0 = u0 + self.rgkt['rk4b'][INTRK]*resu
            u0=self.SSP(u0, time,a,dt)
            times.append(time)
            time = time+dt
            frames.append(u0.flatten()[0])

        if movie:
            mov.make_movie(frames, self.x.flatten()[0], times, "dg_pulse_ssp"+str(self.N))
        return u0
Beispiel #10
0
def create_output():
    '''
  Create a new video given the input video and a user selected film in the database.
  '''

    input_data = "{}/{}.json".format(TRANSCRIPTS_VIDEOS_PATH,
                                     request.form["name"])
    duration = "0,{}".format(int(float(request.form["duration"])))
    movie = glob(VIDEOS_PATH + '/{}.*'.format(request.form["movie"]))[0]
    movie_data = glob(TRANSCRIPTS_VIDEOS_PATH +
                      '/{}.*'.format(request.form["movie"]))[0]

    movie = make_movie(OUTPUT_VIDEOS_PATH, input_data, duration, movie,
                       movie_data, True)
    return jsonify(status="200", movie=movie)
Beispiel #11
0
star_vmin = 1E-3
star_vmax = 1E0
gas_vmin  = 0.1 * star_vmin
gas_vmax  = 0.1 * star_vmax

data_dir = 'data/'

name = base + '-' + lvl + '_w' + "{:.01f}".format(width) + '_n' + str(nres)
proj = data_dir + name + '.hdf5'

mov_gasxy = 'movies/' + name + '_gas_xy.mp4'
mov_gasxz = 'movies/' + name + '_gas_xz.mp4'
mov_starxy = 'movies/' + name + '_star_xy.mp4'
mov_starxz = 'movies/' + name + '_star_xz.mp4'
mov_4panel = 'movies/' + name + '_4panel.mp4'

make_movie(proj, 0, 'xy', mov_gasxy, vmin=gas_vmin, vmax=gas_vmax)
make_movie(proj, 0, 'xz', mov_gasxz, vmin=gas_vmin, vmax=gas_vmax)
make_movie(proj, [2, 3, 4], 'xy', mov_starxy, vmin=star_vmin, vmax=star_vmax)
make_movie(proj, [2, 3, 4], 'xz', mov_starxz, vmin=star_vmin, vmax=star_vmax, plot_time=True)

if os.path.exists('movies/' + name + '_4panel.mp4'):
    os.remove('movies/' + name + '_4panel.mp4')

ffmpeg_call = 'ffmpeg -i ' + mov_gasxz + ' -i ' + mov_starxz + ' -i ' + mov_gasxy + ' -i ' + mov_starxy
ffmpeg_call = ffmpeg_call + ' -filter_complex "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack[out]" -map "[out]" '
ffmpeg_call = ffmpeg_call + mov_4panel

os.system(ffmpeg_call)

Beispiel #12
0
star_vmin = 1E-3
star_vmax = 1E0
# gas_vmin  = 0.1 * star_vmin
# gas_vmax  = 0.1 * star_vmax

data_dir = 'data/'

name = base + '-' + lvl + '_w' + "{:.01f}".format(width) + '_n' + str(nres)
proj = data_dir + name + '.hdf5'

mov_starxy = 'movies/' + name + '_star_xy.mp4'
mov_starxz = 'movies/' + name + '_star_xz.mp4'
mov_testxy = 'movies/' + name + '_test_xy.mp4'
mov_testxz = 'movies/' + name + '_test_xz.mp4'
mov_4panel = 'movies/' + name + '_4panel.mp4'

make_movie(proj, [2, 3], 'xy', mov_starxy, vmin=star_vmin, vmax=star_vmax, plot_time=True)
make_movie(proj, [2, 3], 'xz', mov_starxz, vmin=star_vmin, vmax=star_vmax)
make_movie(proj, 5, 'xy', mov_testxy, vmin=star_vmin, vmax=star_vmax)
make_movie(proj, 5, 'xz', mov_testxz, vmin=star_vmin, vmax=star_vmax, plot_time=True)

if os.path.exists('movies/' + name + '_4panel.mp4'):
    os.remove('movies/' + name + '_4panel.mp4')

ffmpeg_call = 'ffmpeg -i ' + mov_starxz + ' -i ' + mov_testxz + ' -i ' + mov_starxy + ' -i ' + mov_testxy
ffmpeg_call = ffmpeg_call + ' -filter_complex "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack[out]" -map "[out]" '
ffmpeg_call = ffmpeg_call + mov_4panel

os.system(ffmpeg_call)