Tutorial · FFmpeg · YouTube Live

Pre-encode once on your computer, then stream with -c copy: under 1% CPU on 2 vCPUs in our test, versus more than half the machine for live encoding.

Updated 5 November 2026 · About 20 minutes · Tested with FFmpeg 6.1 on 2 vCPUs

A 24/7 lo-fi stream does not need a powerful server or OBS running on your desk. The trick is to do all the video encoding once, on your own computer, and let the server only join finished files and pass them on. In our test on 2 vCPUs, that took under 1% CPU; encoding the same stream live took more than half the machine.

Tested with: FFmpeg 6.1 on a 2-vCPU Linux machine (Intel Xeon 2.8 GHz), 1080p24 picture at about 1.3 Mbps, AAC 160 kbps audio. The scripts are the ones in our lo-fi channel kit; the commands below are their essentials.

The idea: encode once, stream with -c copy

Per track you prepare two files: a 10-second video segment (the animated background with a “now playing” panel) and the whole track as AAC audio. The server keeps two text playlists and FFmpeg joins them on the fly without touching the encoded data:

Snowy cabin lo-fi scene with a NOW PLAYING panel showing the track title
A frame from one of our 10-second segments: a looping, code-drawn scene plus the track panel. This one segment repeats for the length of its track.
Stored on the server per trackSize in our test (90 s test track)
ep01_01_seg.mp4 – 10 s of picture1.6 MB
ep01_01.m4a – the track1.8 MB (about 1.2 MB per minute at 160 kbps)

That is why a small disk is enough: on the original channel, 27 full-length tracks came to about 240 MB of segments and audio, against roughly 1.8 GB as full-length MP4s.

Step 1 – Encode segments that can be joined

Joining files with -c copy only works if every segment has identical encoding settings, and cuts must land on keyframes. These are the settings our build script uses:

ffmpeg -i bg_snow.mp4 -i overlay.png -filter_complex "[0:v][1:v]overlay=0:0,format=yuv420p" -t 10 \
  -c:v libx264 -preset medium -profile:v high -pix_fmt yuv420p -r 24 \
  -b:v 1300k -maxrate 1400k -bufsize 2800k \
  -g 48 -keyint_min 48 -sc_threshold 0 -x264-params open-gop=0 -an ep01_01_seg.mp4

ffmpeg -i track01.wav -vn -af "loudnorm=I=-14:TP=-1.5:LRA=11,aresample=48000,afade=t=in:d=2,afade=t=out:st=SECONDS-3:d=3" \
  -c:a aac -b:a 160k -ar 48000 -ac 2 ep01_01.m4a
  • -g 48 -keyint_min 48 -sc_threshold 0 at 24 fps = a keyframe exactly every 2 seconds. YouTube recommends a 2-second keyframe interval and says not to exceed 4.
  • open-gop=0 keeps each segment self-contained, so the join has no glitch.
  • loudnorm evens out loudness between tracks; the fades stop clicks at track changes.

We checked the keyframes of a finished segment:

$ ffprobe -v error -select_streams v -skip_frame nokey -show_entries frame=pts_time -of csv=p=0 ep01_01_seg.mp4
0.000000, 2.000000 4.000000 6.000000 8.000000

Step 2 – Two playlists, kept in sync

The audio list names each track once. The video list repeats each track’s segment until the picture is as long as the sound; the last repeat is trimmed with outpoint in 2-second steps, so every cut is on a keyframe:

# alist.txt
file 'src/ep01_01.m4a'
file 'src/ep01_02.m4a'

# vlist.txt  (track 1 is 90 s: nine full segments)
file 'src/ep01_01_seg.mp4'
file 'src/ep01_01_seg.mp4'
...

Rounding to 2 s per track would slowly drift, so our playlist script carries the remainder over to the next track; with three 90-second test tracks over 40 rounds the final picture/audio drift was +0.00 s.

Step 3 – The streaming command

#!/bin/bash
# 24/7 stream: join the video-segment list and the audio list live and send them unchanged (-c copy) to YouTube over RTMPS
D="$(cd "$(dirname "$0")" && pwd)"
KEY_FILE="$D/stream.key"
[ -s "$KEY_FILE" ] || { echo "missing $KEY_FILE (write your YouTube stream key into it)"; exit 1; }
KEY=$(tr -d ' \r\n' < "$KEY_FILE")
exec ffmpeg -hide_banner -loglevel error \
  -re -f concat -safe 0 -i "$D/vlist.txt" \
  -re -f concat -safe 0 -i "$D/alist.txt" \
  -map 0:v -map 1:a -c copy -f flv -flvflags no_duration_filesize \
  "rtmps://a.rtmps.youtube.com:443/live2/$KEY"

-re reads both inputs at real-time speed, -map takes picture from one list and sound from the other, and -c copy sends them on unchanged. YouTube recommends RTMPS, hence the rtmps:// URL. Keep the stream key in a file with chmod 600, never in the script.

What it costs in CPU: measured

We ran the copy command and a live re-encode of the same picture and audio for 120 seconds each, writing to a local file instead of YouTube so the network didn’t skew the numbers:

copy:     wall=119.7s cpu=2.1s   avg 0.9% of 2 vCPU   max RSS 65 MB   output 1459 kbps
reencode: wall=119.9s cpu=128.1s avg 53.4% of 2 vCPU  max RSS 342 MB  output 1475 kbps

Live encoding (x264 veryfast, same bitrate) used about 60 times the CPU and five times the memory. Real streaming adds TLS and network work on top: on the original channel’s 2-vCPU VM, which also ran Docker and nginx, the copy stream used around 20% CPU and 40-55 MB of memory.

Step 4 – Keep it running with systemd

[Unit]
Description=YouTube 24/7 live stream
After=network-online.target
Wants=network-online.target

[Service]
User=__USER__
WorkingDirectory=__DIR__
ExecStart=__DIR__/stream.sh
Restart=always
RestartSec=10
Nice=10
CPUQuota=60%
MemoryMax=600M
IOSchedulingClass=idle

[Install]
WantedBy=multi-user.target

Restart=always brings the stream back after a network drop or when the playlist ends (ours is 40 rounds of the track list, then FFmpeg exits and systemd starts it again after 10 seconds). Nice, CPUQuota and IOSchedulingClass=idle make the stream give way if the VM also runs other things.

In YouTube Studio, choose Go live → Streaming software, turn Auto-start on and Auto-stop off so a reconnect continues the same live stream, then paste the key on the server:

$ read -rsp "Paste the stream key: " K && echo "$K" > ~/yt-live/stream.key && chmod 600 ~/yt-live/stream.key
$ sudo systemctl enable --now yt-live

Bitrate, picture quality and monthly data

Our segments are about 1.3 Mbps. That is well below YouTube’s recommendation for 1080p30 H.264 (5 Mbps minimum, 14 Mbps recommended), and Studio may flag the stream’s bitrate. We accept it because a slowly animated scene compresses very well and because every bit is paid for as outbound data, 24 hours a day:

Measured outputPer 30 daysGoogle Cloud Standard Tier egress
~1.46 Mbps (picture + sound)~473 GB (~440 GiB)first 200 GiB free, then $0.085/GiB ≈ $20/month
5 Mbps (YouTube’s 1080p minimum)~1.6 TB (~1,510 GiB)≈ $111/month

Prices are from Google’s Network Service Tiers pricing page (Standard Tier, per account per month) as of November 2026; Premium Tier and other clouds price differently, and the VM itself is extra. If your scene has more motion and the picture breaks up, raise -b:v, -maxrate and -bufsize together and re-encode the segments – the server side doesn’t change.

Day-to-day checks

TaskCommand
Statussystemctl status yt-live --no-pager
Errorsjournalctl -u yt-live -n 50 --no-pager
Test the playlists without going liveffmpeg -f concat -safe 0 -i vlist.txt -f concat -safe 0 -i alist.txt -map 0:v -map 1:a -c copy -t 400 -f flv /dev/null
Studio shows “No data”sudo systemctl restart yt-live

Before you go live: check the music’s licence for 24/7 streaming and say in the description if it is AI-generated – YouTube asks creators to disclose realistic altered or synthetic content. Rules change, so read YouTube’s current policies and your music generator’s terms.

Get the streaming kit

The free sample has 20 Suno prompts for instrumental lo-fi and one animated scene. The full kit adds 143 prompts, five seamless code-drawn scenes, the 1-hour video pipeline with chapters, thumbnails and Shorts, and everything above as ready scripts: segment builder, playlist generator, stream.sh, the systemd unit, a setup script and a cost calculator.

FAQ

Can I stream from my own computer instead?

Yes, the same command works anywhere FFmpeg runs. A VM simply keeps going when your computer sleeps or your home connection drops.

Why not loop one long video?

You can, but a long MP4 per track costs disk space and you lose the per-track “now playing” title. Ten-second segments keep the server small and the titles correct.

Does the music have to be AI-generated?

No. Any tracks you have the rights to stream work – the pipeline only needs audio files.

Sources

AI Stack Nav is independent. Product names are trademarks of their owners.