I'm creating a sprite sheet for my website which will be used as an animated background mask on a button hover. The only issue I'm having is creating the sprite sheet mask

I have 297 720p images I want to put as one long line, so I am using ffmpeg's tile_complex

ffmpeg -i %04d.png -filter_complex tile=297x1 output.png

I get this output, which basically says the image resolution is too high and therefore it can't encode

Picture size 380160x720 is invalid
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Any ideas?

For the buttons, I can descale the resolution a lot as they will appear small using this

ffmpeg -i %04d.png -vf scale=iw/6:-1 %04d.png

However, with the title that appears large on the screen, I don't want a loss of quality

I am following Kevin Powell's video on it:

The mask he uses he draws by hand, so he doesn't show how to take a pre-existing image sequence and use it

2 Answers 2


While ffmpeg is a powerful tool for video and image processing, it may not be the best option for creating sprite sheets with large image sequences due to the limitation you've encountered. However, there are other tools and libraries that can help you automate the process of creating sprite sheets without reducing the image resolution.

One such tool is TexturePacker, which is a commercial software that allows you to create sprite sheets from image sequences, with the ability to customize the layout, compression, and other settings. TexturePacker also supports multiple output formats and can generate CSS code for easy integration with your website or application.

Another option is to use a library like Phaser, which is an open-source game development framework that includes built-in support for sprite sheets. With Phaser, you can load your image sequence and automatically create a sprite sheet, which can be used to animate your game objects or as a background mask in CSS.

If you prefer a command-line approach, you can use a scripting language like Python or Node.js to automate the process of creating sprite sheets. For example, you can use the Pillow library in Python to load and manipulate images, and then generate a sprite sheet using the Pygame library or a custom script. Similarly, you can use the Jimp library in Node.js to load and process images, and then generate a sprite sheet using a custom script.

In summary, while ffmpeg may not be the best tool for creating sprite sheets with large image sequences, there are other options available that can help you automate the process without reducing the image resolution, such as TexturePacker, Phaser, or custom scripts using Python or Node.js.


Using jimp (js)

const Jimp = require('jimp');
const path = require('path');

async function createSpriteSheet(inputPath, frameCount, frameWidth, frameHeight, outputFilePath) {
  // Create a new image to hold the sprite sheet
  const spriteWidth = frameWidth * frameCount;
  const spriteHeight = frameHeight;
  const sprite = new Jimp(spriteWidth, spriteHeight);

  // Iterate over the frames and append them to the sprite sheet
  for (let i = 0; i < frameCount; i++) {
    const framePath = path.join(inputPath, `frame_${i}.png`);
    const frame = await Jimp.read(framePath);
    sprite.blit(frame, i * frameWidth, 0);

  // Save the sprite sheet to disk
  await sprite.writeAsync(outputFilePath);

// Example usage:
const inputPath = 'path/to/image/sequence';
const frameCount = 10;
const frameWidth = 1280;
const frameHeight = 720;
const outputFilePath = 'path/to/sprite_sheet.png';

createSpriteSheet(inputPath, frameCount, frameWidth, frameHeight, outputFilePath);

// Example usage:
createSpriteSheet(10, 1280, 720, 'path/to/sprite_sheet.png');

This code defines a function called createSpriteSheet that takes four arguments: frameCount, frameWidth, frameHeight, and outputFilePath. The frameCount argument specifies the number of frames in the image sequence, the frameWidth and frameHeight arguments specify the dimensions of each frame, and the outputFilePath argument specifies where to save the resulting sprite sheet.

To use this function, simply call it with the appropriate arguments. In the example usage above, the function is called with frameCount set to 10, frameWidth set to 1280, frameHeight set to 720, and outputFilePath set to 'path/to/sprite_sheet.png'. You should replace these values with the actual dimensions and file paths of your image sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.