ThisCalculator

Everyday

24/7 Animated Story Stream with FFmpeg

Updated · Standard formula, shown below

This guide shows you how to run a 24/7 animated story stream using only FFmpeg and a few free tools. You’ll create a looping video from images and audio, then stream it continuously to a platform like YouTube or Twitch. The process is fully automated once set up, and you can run it on a cheap VPS or an old PC.

What You’ll Need

  • A computer or VPS that stays on 24/7 (any OS: Linux, Windows, macOS).
  • FFmpeg installed (see step 1).
  • A set of story images (PNG or JPG) and an audio file (MP3 or AAC) for the story.
  • A streaming platform account (YouTube, Twitch, etc.) and a stream key.
  • Optional: A text editor to create a playlist file.

Step-by-Step

  1. Install FFmpeg
    Download FFmpeg from the official website or use your package manager. On Ubuntu/Debian: sudo apt install ffmpeg. On Windows, download the static build and add it to PATH. Verify with ffmpeg -version.
  2. Prepare your assets
    Place all story images in a folder, named sequentially (e.g., img001.png, img002.png). Ensure they are the same resolution (e.g., 1920×1080). Convert any audio to a compatible format: ffmpeg -i story.mp3 -c:a aac -b:a 128k story.aac.
  3. Create a playlist file
    Create a text file playlist.txt with one line per image, using the file syntax:
    file 'img001.png'
    duration 5
    file 'img002.png'
    duration 5
    ...

    Make sure the paths are correct. The duration is in seconds.

  4. Generate a looping video from images
    Use FFmpeg to create a video from the playlist. Run:
    ffmpeg -f concat -safe 0 -i playlist.txt -vf "scale=1920:1080,format=yuv420p" -c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p -c:a aac -b:a 128k -shortest story_loop.mp4
    This creates a video that matches the audio length. If you want the video to loop indefinitely, you can skip this step and use the images directly in the stream command, but a pre-made loop is easier to manage.
  5. Test the loop locally
    Play the generated video with a media player to ensure it looks and sounds correct.
  6. Set up the streaming command
    Use FFmpeg to stream the video to your platform. Replace STREAM_KEY with your actual key and STREAM_URL with the RTMP URL (e.g., rtmp://a.rtmp.youtube.com/live2 for YouTube).
    ffmpeg -re -stream_loop -1 -i story_loop.mp4 -c copy -f flv STREAM_URL/STREAM_KEY
    The -re flag reads the input at native speed, -stream_loop -1 loops forever.
  7. Run the stream in the background
    To keep it running after you log out, use a tool like tmux or screen on Linux, or run it as a service. For example, with tmux: tmux new -s stream, then run the command, then detach with Ctrl+B D.
  8. Monitor and maintain
    Check the stream periodically to ensure it’s still running. Set up a simple cron job to restart it if it crashes (e.g., check every minute if ffmpeg is running).

Common Mistakes

  • Incorrect playlist paths: Use absolute paths or run FFmpeg from the folder containing the images.
  • Mismatched resolutions: Images with different sizes cause scaling issues. Use the scale filter to force a uniform size.
  • Audio/video length mismatch: If the video is shorter than the audio, the stream will cut off. Use -shortest when creating the loop, or loop the video indefinitely.
  • Forgetting -re: Without it, FFmpeg sends frames as fast as possible, overloading the server.
  • Using the wrong stream key: Double-check the key and URL; a mistake causes connection errors.

Tips

  • Use -preset veryfast to reduce CPU usage; for lower CPU, use ultrafast but with a higher CRF.
  • Add a text overlay with drawtext to show the current story title or chapter.
  • To change the story, replace the images and audio, and regenerate the loop video.
  • Schedule the stream to start/stop using cron or a simple script.
  • Use a VPS with a good upload speed (at least 5 Mbps for 1080p).

Troubleshooting

  • Stream disconnects after a few minutes: Check your internet stability. Reduce the bitrate with -b:v 2500k if needed.
  • Video is black: Ensure the pixel format is yuv420p, and the resolution is even (e.g., 1920×1080).
  • Audio is out of sync: Use -c:a copy only if the audio codec is compatible with FLV (AAC). Otherwise, re-encode audio.
  • FFmpeg crashes with ‘moov atom not found’: When streaming, the video must be streamable; use -movflags frag_keyframe+empty_moov if you’re not using -c copy.
  • Permission denied on playlist: Use -safe 0 to allow any file path.

Frequently Asked Questions

Can I use a single image instead of a video?

Yes, you can stream a single image with audio using the loop filter: ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -f flv ...

How do I add subtitles to the stream?

Use the subtitles filter: -vf "subtitles=story.srt". Ensure the subtitle file is in the same folder.

Can I run this on a Raspberry Pi?

Yes, but use a lower resolution (720p) and -preset ultrafast to avoid overheating.

What bitrate should I use?

For 1080p, use 4500k video bitrate and 128k audio. For 720p, 2500k is enough. Adjust based on your upload speed.

How do I rotate the story images?

You can use a shell script to rename files, or use FFmpeg’s glob pattern with a random order (but that’s more complex).

Is it legal to stream copyrighted stories?

Only stream content you own or have permission to use. Copyright infringement can lead to takedowns.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.