Skip to content
streamneo.
Setup Guides14 min read

How to Use FFmpeg for a YouTube Loop Stream on a VPS in India

A practical guide to looping a media file with FFmpeg, publishing to YouTube Live from a VPS, and keeping the stream healthy over time.

sn.
StreamNeoPublished 3 October 2026
Worth sharing?

A VPS in India can run FFmpeg continuously, repeat a prepared video file and send the result to YouTube Live. The reliable part is not the loop itself, but matching the file, encoder, bitrate, network and process monitoring so the stream still works after several hours.

This guide builds that workflow step by step. You will need a Linux VPS, an existing video file, an FFmpeg installation, a YouTube channel enabled for live streaming and the stream details supplied by YouTube.

How the FFmpeg loop workflow works

FFmpeg is the software encoder and media process in this setup. It reads a file from the VPS, repeats the input, selects its video and audio streams, encodes them into a format YouTube accepts, and publishes the output to YouTube's live ingestion address.

The VPS is simply the computer that remains available while the broadcast runs. Your home computer does not need to stay switched on once the file has been uploaded and the process is working. This is useful for a devotional replay, a bhajan channel, a local information loop or a study ambience stream where the same prepared material needs to run for long periods.

A looped file is still a live broadcast from YouTube's point of view. FFmpeg does not upload the video as a normal YouTube file. It sends a continuous stream to the live event using the stream key and ingestion information from YouTube Live Control Room.

The workflow has five separate parts:

  1. Prepare a media file with the intended picture, sound and duration.
  2. Copy it to the VPS and check that FFmpeg can read it.
  3. Create or configure a YouTube Live event and obtain its stream key.
  4. Start FFmpeg with real-time pacing, looping and explicit output settings.
  5. Watch the process and YouTube's stream health rather than assuming that a running command means a healthy broadcast.

The complete 24/7 streaming guide is useful for decisions around scheduling, channel presentation and the wider operating routine. This article concentrates on the FFmpeg and VPS layer.

Prepare and store the media file

Start with the source rather than with the command. Check what the file actually contains, because a command copied from another setup may expect a video stream, an audio stream or codecs that your file does not have.

On the VPS, run a probe such as:

ffprobe -hide_banner /srv/stream/channel-loop.mp4

ffprobe is normally installed with FFmpeg. The output should show the video codec, audio codec, dimensions, frame rate, duration and audio sample details. It should also show whether the file has both video and audio. If the file has no audio, do not add audio options as if a track exists. If it has several tracks, decide which one you want before building the final command.

Use a clear, protected directory rather than placing the file in a temporary download folder. For example:

/srv/stream/channel-loop.mp4

The file should be complete before FFmpeg starts. A partially copied file may open successfully but fail when the process reaches the unfinished section. Copy it with a tool that can resume or verify the transfer, then compare the source and destination file sizes. For a larger file, a checksum gives you a stronger check that the copy is complete.

You also need to consider rights and suitability. A file that you are allowed to upload is not automatically suitable for indefinite public rebroadcast. Music, prayers, speeches, television material and background footage can each have separate rights or platform-policy considerations. YouTube's current rules and the permissions for your material should be checked before you leave the stream unattended. The guidance in reused content and 24/7 loops covers the channel-side risks that are separate from FFmpeg's technical operation.

Keep the first test simple. One video stream and one audio stream are easier to diagnose than a file containing subtitles, multiple language tracks and several metadata streams. If you need a different resolution or a consistent frame rate, make a test version first and inspect it before sending it to YouTube.

Set up Linux VPS access securely

Choose a Linux VPS based on the work the process must perform, not only on storage. Continuous re-encoding uses CPU continuously. A stream-copy workflow can use much less CPU, but only when the source streams already match the destination requirements and the ingestion configuration.

When comparing providers, verify the current region, sustained CPU allowance, outbound transfer policy, network limits, support terms and restart behaviour. The research for this guide does not establish a particular Indian provider, Indian VPS price or regional performance result, so a server described as being in India should not be treated as proof of a suitable route to YouTube.

Use SSH keys where possible. Create a separate, non-root account for the streaming process and give it ownership of the media directory. Avoid logging in as root for normal operation. A minimal sequence might look like this after your provider has supplied the server address:

ssh-keygen -t ed25519
ssh streamuser@YOUR_SERVER_IP

The exact account and firewall steps depend on the Linux distribution and provider. Keep SSH available from your own network, install security updates, and avoid opening unrelated services to the public internet. You do not need a web server or public file download service merely to publish an FFmpeg stream.

Install FFmpeg from the distribution's supported packages or from the FFmpeg project's documented options. Then check the installed build:

ffmpeg -version
ffmpeg -encoders | grep -E 'libx264|aac|h264'
ffmpeg -protocols | grep -E 'rtmp|rtmps'

The available encoders and protocols vary by build. If libx264, AAC or RTMPS support is absent, the example command may not work unchanged. The FFmpeg documentation explains the command structure, while the protocol documentation covers protocol-specific options.

Do not put a real stream key in a public script, screenshot, repository or shared shell history. A practical approach is to keep it in a protected environment file readable only by the streaming account:

chmod 600 /home/streamuser/.stream-env

The file might contain a value such as YOUTUBE_STREAM_KEY=replace_this_value. Treat the key as a password. If it is exposed, replace it in YouTube Live Control Room rather than continuing to use a secret that other people can read.

Create the YouTube Live event

Open YouTube Studio and create or configure the live broadcast. YouTube supplies the stream key and the server or ingestion address for the event. Copy those values from the current live setup rather than relying on an old command saved from another channel.

YouTube recommends RTMPS, which is RTMP sent through an SSL connection. YouTube Help states: “We recommend streaming to YouTube Live with RTMPS, a secure extension to the popular RTMP video streaming protocol.” Use the current RTMPS details shown by YouTube and consult its live encoder settings if the interface or available options differ from this article.

There are two things to distinguish:

  • The live event is the YouTube-side container for the broadcast.
  • The stream key and ingestion address tell FFmpeg where and how to publish the signal.

If you reuse an existing key, confirm that it belongs to the intended channel and event. The YouTube Live Streams API documentation describes the live stream resource and its ingestion information. You do not need to use the API for a basic manual setup, but the documentation helps clarify which details YouTube expects.

Before starting a long run, make a short test broadcast. Confirm that the video appears, audio is audible, the aspect ratio is correct and the stream health indicator does not show a persistent warning. A command that connects successfully can still produce an unsuitable frame rate, missing audio or insufficient bitrate.

Configure FFmpeg to loop and publish

The basic loop mechanism is FFmpeg's input stream-loop option. For a file input, -stream_loop -1 requests indefinite repetition. The -re option reads the file at approximately its normal presentation rate instead of sending it as quickly as the VPS can process it. Without real-time pacing, a file-based input can be consumed too quickly and does not behave like a live source.

Here is a starting pattern for a file that contains one video stream and one audio stream:

source /home/streamuser/.stream-env

ffmpeg -hide_banner -loglevel info \
  -re -stream_loop -1 -i /srv/stream/channel-loop.mp4 \
  -map 0:v:0 -map 0:a:0 \
  -c:v libx264 -preset veryfast -pix_fmt yuv420p \
  -b:v 8M -maxrate 8M -bufsize 16M \
  -r 30 -g 60 -keyint_min 60 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv "rtmps://YOUR_INGESTION_ADDRESS/app/$YOUTUBE_STREAM_KEY"

This is a template, not a universal command. Replace the ingestion address and path with the values supplied by YouTube. Some FFmpeg builds use different encoder names, and the correct output URL depends on the ingestion details you receive. Test the command with your own file before treating it as an unattended service.

The example targets 720p at 30 frames per second with an 8 Mbps video rate. YouTube Help lists 8 Mbps as its published recommended H.264 bitrate for 720p at 30 fps and also lists 8 Mbps for 720p at 60 fps. It lists 14 Mbps for 1080p at 30 fps and 17 Mbps for 1080p at 60 fps. These are recommendations for the matching formats, not universal requirements. Use YouTube's current table for the exact codec, resolution and frame rate you select.

The -g 60 and -keyint_min 60 settings correspond to a two-second keyframe interval at 30 fps. YouTube recommends a two-second interval and says it should not exceed four seconds. If you select 60 fps, the corresponding two-second interval would use a different frame count. The keyframe calculation must match the actual output frame rate.

The command re-encodes both streams. That gives you control over the output format but requires the VPS to encode continuously at real-time speed. Watch CPU usage during the test. If the process falls behind, frames may be delayed or dropped.

Stream-copying with -c:v copy or -c:a copy can reduce CPU use, but it is not a safe shortcut for every file. The source codec, pixel format, frame rate, audio format, keyframe pattern and container behaviour must all be compatible with the chosen YouTube settings. If you need predictable output, re-encoding is usually easier to reason about. If your source is already suitable, test stream copying separately rather than changing a working command without checking the result.

For a command that should survive a disconnected SSH session, use a process manager such as systemd, tmux or screen. A detached shell does not by itself diagnose failures or guarantee that a process will restart. The next section deals with that distinction.

Keep the process healthy over time

A loop option only addresses the end of the file. It does not repair a damaged input, a lost route, an expired event, an exhausted transfer allowance or an FFmpeg process that has exited. Long-running streaming needs observation and a deliberate response when something goes wrong.

First, run the command in a visible test session and read the log. Look for messages showing the input streams, output mapping, frame rate, encoded bitrate and connection status. The output should advance at roughly the intended real-time pace. If the speed repeatedly falls below real time, investigate CPU contention, an unsuitable preset, disk access or a source that is more complex than expected.

After the test, create a systemd service or use another process supervisor. A simple service can restart FFmpeg after an unexpected exit, but that is not the same as recovering from every possible failure. Repeated restarts can also make diagnosis harder, and a process may remain running while the YouTube broadcast is unhealthy.

A systemd unit might contain the following general shape:

[Unit]
Description=YouTube loop stream
After=network-online.target
Wants=network-online.target

[Service]
User=streamuser
WorkingDirectory=/srv/stream
EnvironmentFile=/home/streamuser/.stream-env
ExecStart=/usr/bin/ffmpeg -hide_banner -loglevel info -re -stream_loop -1 -i /srv/stream/channel-loop.mp4 -map 0:v:0 -map 0:a:0 -c:v libx264 -preset veryfast -pix_fmt yuv420p -b:v 8M -maxrate 8M -bufsize 16M -r 30 -g 60 -keyint_min 60 -c:a aac -b:a 128k -ar 44100 -f flv rtmps://YOUR_INGESTION_ADDRESS/app/$YOUTUBE_STREAM_KEY
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Check the paths, user permissions, encoder availability and URL before enabling it. Keep the service definition private because it references the stream key environment. Use journalctl to inspect logs, and do not assume that Restart=on-failure proves the public stream has recovered.

YouTube's own stream health page remains important. Check it after startup and at intervals during the first unattended run. Also set an alert or a simple external check that tells you when the VPS is unreachable, the process has stopped or the broadcast is no longer receiving data. The check should prompt a human investigation rather than repeatedly restarting blindly.

A sensible test sequence is:

  1. Run FFmpeg manually for a short period.
  2. Confirm picture, sound and stream health in YouTube Studio.
  3. Stop the process and verify that the service manager records the event.
  4. Start it through the service manager.
  5. Observe CPU, memory, disk and outbound traffic before leaving it overnight.
  6. Confirm what happens after a deliberate network interruption or process stop.

If a loop reaches its end and begins again, the transition may be visible. You can reduce the surprise by preparing the file with a clean ending and beginning, but no FFmpeg option can make two unrelated scenes feel continuous. For a devotional or ambience channel, a short fade or a deliberately repeated segment may be preferable to an abrupt cut.

Check network and hosting trade-offs

The output bitrate is a sustained outbound requirement. A stream configured at 8 Mbps needs more than 8 Mbps of usable upload capacity in practice because network conditions and protocol overhead leave less room than the nominal figure suggests. YouTube recommends testing with a speed test and monitoring stream health. Do not select a VPS solely because its advertised port speed appears larger than the chosen video bitrate.

For an India-based channel, the useful questions are conditional rather than geographic assumptions:

  • Is the VPS region currently available in the location you want?
  • Does the plan allow continuous outbound traffic for this use?
  • Is CPU capacity sustained or shared in a way that affects real-time encoding?
  • What happens when the process runs for several days?
  • Does the provider document traffic limits, suspension rules and restart behaviour?
  • Does a real test from that VPS maintain the chosen bitrate to YouTube?

No specific Indian provider, price or route should be treated as established by this guide. Provider terms change, and a server's advertised location does not prove the quality of its route to YouTube. Read the provider's current documentation and run your own test before committing.

Choice Main benefit Main trade-off
720p at 30 fps Lower published H.264 bitrate recommendation and generally lighter encoding demand Less detail than 1080p for text, artwork or a news layout
1080p at 30 fps More room for fine text and detailed visuals YouTube lists a higher H.264 bitrate recommendation, increasing sustained bandwidth and potentially CPU demand
Re-encoding Consistent control over codec, frame rate, bitrate and keyframes Continuous CPU work and more settings to test
Stream copying Lower CPU demand when the source is already compatible Less control and a greater risk that the source does not meet destination requirements
RTMPS YouTube's recommended secure ingestion method Requires a build and URL configuration that support the chosen protocol

The table uses the H.264 recommendations listed by YouTube Help. It does not predict picture quality, regional performance or provider capacity. For a channel with small text, compare a short 720p and 1080p test in YouTube's player rather than choosing from resolution labels alone. The 720p versus 1080p bitrate guide gives more context on long-run bitrate decisions.

There is also a simpler operating choice. If maintaining Linux access, encoder compatibility, process supervision and network checks is more work than you want, a managed workflow can remove the VPS maintenance from the job. StreamNeo is designed for the narrower case where you upload the video, provide the YouTube stream key and let the broadcast run without your computer remaining on; it does not replace YouTube policy checks or remove the need to use media you are entitled to broadcast.

Before committing, compare the operating options on the pricing page. When the file and channel are ready, start free — 24-hour trial, no card.

FAQ

Can FFmpeg loop an MP4 indefinitely?

Yes. For a file input, -stream_loop -1 requests indefinite repetition. You still need -re for real-time pacing, and the file must contain streams that the output command can map and encode. The option does not fix a damaged file or reconnect a failed YouTube session.

Should I use 720p or 1080p on an Indian VPS?

Choose the output that your source, CPU and tested outbound connection can sustain. YouTube Help lists 8 Mbps as its recommended H.264 bitrate for both 720p at 30 fps and 720p at 60 fps, while it lists 14 Mbps for 1080p at 30 fps and 17 Mbps for 1080p at 60 fps. Those figures do not establish what any particular Indian VPS can deliver, so test the exact configuration.

Does FFmpeg restart the YouTube stream after a failure?

FFmpeg can report connection errors, but it is not a complete monitoring system. A process supervisor can restart it after an exit, while YouTube Live Control Room can show whether the platform is receiving a healthy signal. Recovery depends on the failure, and no setup should be described as recovering from every failure automatically.

Is RTMPS required?

YouTube recommends RTMPS and supplies the ingestion details for the live setup. Use the current address and stream key shown in YouTube rather than copying an old URL. Confirm that your installed FFmpeg build supports the protocol you intend to use.

YOU’VE REACHED THE END

Keep the ideas coming.

More guides, useful tools and a little help for your next broadcast.

Back to the journal ↗
YOUR NEXT READ

A little more to explore.

More Setup Guides guides ↗ · All topics ↗