dsveen / gif_and_video_art_engine

A GIF and Video art engine that will allow you to generate multi-layer GIFs or Video from single GIFs or Video as layers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GIF and Video Art Engine

Introduction

That's an art engine that will allow you to create spectacular Gifs and Videos generated by overlapping multiple gif or video. The code was created by me, by taking ispiration from the one written by Hashlips, that for the moment only supports static images. I created this code to generate my own Gifs and to help others do the same for their projects.

If you found my work useful for any of your projects, please make some donations to support me. I would really appreaciate that.

MetaMask address: 0xaE9d8FD177c22D88159F2773998dB07CAf40693d

Phantom address: A1U2hsvAANsmXGhm9vEvQz5T1JvExACWZpM8ckqpwDRc

Discord username: luffy2023#2742 -> contact me if you need help

These are some GIFs/Videos that people generated with my engine:

Alt Text Alt Text Alt Text

example2.mov
example4.mp4

Important notes before starting

  • The code was tested with FFmpeg version 4.2.4.

  • Each Gif/Video you put as layer should have the same size, length and number of frames of the others. If this condition won't be respected some layers will probably become static after a period of time.

  • Every video file must have the audio track, even if it is empty.

  • I'm really sorry if you will find some bugs trying to run the code. If you find some, please open an issue, so i can know what the problem is and i can fix it, in my free time.

What does the code allow you to do?

When you have downloaded the code you will be able to generate your own GIFs and Videso using GIFs or Videos as layers. What the code will do is overlay all the GIFs or Videos you have chosen in the desired order and generate n final GIFs or Videos. This is an example of generating a gif with five separate layers:

Layer number Layer Name Gif
1 Background f8f9f9.gif Alt Text
2 Character zombie-male.gif Alt Text
3 Head tophat.gif Alt Text
4 Eyes bigshades.gif Alt Text
5 Mouth lipstick-party_pink.gif Alt Text

Output:

Alt Text

What functionality does it offer?

  • Generate GIFs/Videos uniquely or not, randomly or by selecting a rarity for each individual layer.

  • Generation of a preview GIF containing the first n GIFs generated.

  • Modification of JSON (Metadata) after generating the media.

  • After generating a collection you will automatically find in the output folder a file called rarity-list.txt that will tell you the actual percentage of presence of each layer in the collection.

  • You can combine video and audio files to generate video + audio files.

  • If the video files you are trying to overlapping contains an audio track, even this will be overlapped with the others audio traces

Installation, compilation and execution

Note: the code was not tested on macOS, but i know someone succeeded to run this code on macOS

Requirements: Windows or Linux operating system

On windows to install the Ubuntu bash/terminal watch this video: https://www.youtube.com/watch?v=1ap3hL-UR9I

Then open the terminal and run this three commands:

sudo apt-get update
sudo apt-get install g++ -y
sudo apt-get install ffmpeg -y

If you have git installed and you want to clone the project, run this command:

git clone https://github.com/Goldo02/gif_and_video_art_engine.git

After that, open the terminal and move to the folder where you cloned the project.

To compile the main.cpp file use the command:

g++ ./library/dna_generator.cpp ./library/metadata_function.cpp ./library/my_ffmpeg_conversion.cpp ./library/utils.cpp main.cpp -o main

To run the code and generate the art with opensea standard metadata:

./main ETH 

To run the code and generate the art with solana standard metadata:

./main SOL

To update your metadata following the opensea standard:

./main ETH update_info

To update your metadata following the solana standard:

./main SOL update_info

To generate a preview gif:

./main ETH preview_gif

To combine video with audio:

./main ETH combine_video_with_audio

Note: remember that every time you modify the file you must also recompile it before running it, otherwise you will run the program out of date with the changes you made.

Usage

To use the algorithm and modify it according to your needs you must open the file main.cpp. That's the part of the code to change:

const int scale = 240;
const string outputFormat = "gif";
const bool randomized = false;
const bool unique = true;
const bool shuffleOutput = true;
vector<int> collectionSize = {10, 4};
const vector<vector<string>> layerDir = 
{
{"1-background", "2-character", "3-head", "4-eyes", "5-lip"},
{"1-background", "2-character", "3-head"}
};

const string name = "SUrrty Peasy YouTube test";
const string description = "i love u";
const string baseUri = "https://twittercom/elonmusk";
const vector<pair<string,string>> extraMetadata = 
{
{"Compiler", "CeloPunks compiler"},
{"Github Author", "Goldo02"}
};

Description of variables:

  • scale: is the output width, the height will be self-determined.

  • outputFormat: is the format of the output files. If you are operating with GIFs, it should be gif, if u are operating with video should be a video format.

  • randomized: set this parameter to true if you want the algorithm to choose random raritys, to false if not.

  • unique: set this parameter to true if you want that each GIF or Video is unique, to false if you want that there is the possibilites that a GIF or a Video appear more than one time.

  • shuffleOutput: shuffle the final output. Only set this to true if you have sub collections.

  • collectionSize: contains the number of media u want to generate for each collection. This number is linked to the lines of the layerDir variable.

  • layerDir: contains the layers to consider for each collection. You don't need to specify every single layer, but each layers name cannot have spaces, if you want to put spaces in the metadata you hae to put the character '_' instead. The rarity is specified in the single layer name after the '#' character, after this character you can insert the percentage of presence of the trait. This number must be an integer.

  • name: is the name of the collection.

  • description: is the description of the collection.

  • baseUri: is the place where all your media will be hosted. Usually people host their media on their server or on Pinata IPFS.

  • extraMetadata: contains some extra metadata you can choose to add at the end of each .json file.

Remember: recompile the program before running it after modifying it.

Update metadata

To update the metadata you need to change this part of the code accordly to your needs, then you need to recompile the code, and then you can execute the code.

const string name = "SUrrty Peasy YouTube test";
const string description = "i love u";
const string baseUri = "https://twittercom/elonmusk";
const vector<pair<string,string>> extraMetadata = 
{
{"Compiler", "CeloPunks compiler"},
{"Github Author", "Goldo02"}
};

There are two commands to update the metadata, you can find them in the Installation, Build and Run part of the readme.

Creating a gif preview

To create a preview gif you need to change this part of the code accordly to your needs, then you need to recompile the code, and then you can execute the code. Example:

const int firstMedia = 0;
const int numbOfMediaToGen = 10;
const int fps = 30;

Description of variables:

  • firstMedia: is the position of the first GIF.

  • numbOfMediaToGen: number of gifs to be considered for preview_gif generation. The first gif will have firstMedia as initial position.

  • fps: is the encoding speed, choose it according to the fps of your gifs.

This is an example of a user-generated preview_gif:

Alt Text

Combine video and audio

To Combine video and audio you need to change this part of the code accordly to your needs, then you need to recompile the code, and then you can execute the code.

const int firstMedia = 0;
const int numbOfMediaToGen = 10;
const string inputVideoForm = "mp4";
const string inputAudioForm = "mp3";
const string outputVideoForm = "mp4";

All the video and audio you want to combine should be placed in the tmp directory. You will find the output under ./output/video-with-audio

About

A GIF and Video art engine that will allow you to generate multi-layer GIFs or Video from single GIFs or Video as layers.

License:MIT License


Languages

Language:C++ 98.5%Language:Makefile 1.5%