Code Monkey home page Code Monkey logo

mp4-generator's Introduction

MP4-Generator

A simple class to generate MP4 video by mixing images, videos and audio tracks

File[] imageFiles = new File("images").listFiles();
ArrayList<Frame> frameArray = new ArrayList<>();
int duration = 20;		

for(File f : imageFiles)
{
	System.out.println("image " + f.getName());

	try 
	{
		BufferedImage baseImage = ImageIO.read(f);

		int w = baseImage.getWidth();
		int h = baseImage.getHeight();

		for(int i = 0; i < 8; i++)
		{
			BufferedImage image = baseImage;

			int x = 0;
			int y = 0;
			int w0 = w;
			int h0 = h;

			// crop if needed
			if(w > W)
			{
				int dx = (w - W);
				int offset = (int)(Math.random() * (double)dx); 
				x = x + offset;
				w0 = W;
				System.out.println("dx: " + dx + " offset: " + offset + " x: " + x + " w0: " + w0 + " w: " + w);

			}
			'''

			if(h > H)
			{
				int dy = (h - H);
				int offset = (int)(Math.random() * (double)dy); 
				y = y + offset;
				h0 = H;

				System.out.println("dy: " + dy + " offset: " + offset + " y: " + y + " h0: " + h0 + " h: " + h);
			}

			if(x != 0 || y != 0)
			{
				image = image.getSubimage(x, y, w0, h0);						
			}


			Image image1 =  image.getScaledInstance(W, H, Image.SCALE_SMOOTH);

			ImageFrame imageFrame = new ImageFrame();
			imageFrame.bitmap = toBufferedImage(image1);
			imageFrame.durationmSec = 400;

			frameArray.add(imageFrame);					
		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

MP4GeneratorJCodec mp4gen = new MP4GeneratorJCodec();


try {
	mp4gen.init("photo", "16/9", "audio.aac", frameArray, "myvideo.mp4");

	mp4gen.generate();

} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
    

mp4-generator's People

Contributors

ugochirico avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

biangkerok32

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.