Skip to content
streamneo.
Setup Guides14 min read

How to Loop Videos on a Raspberry Pi and Stream Them to YouTube

Loop a local video on a Raspberry Pi and send it to YouTube Live with FFmpeg, correct ingest settings and practical preflight checks.

sn.
StreamNeoPublished 3 October 2026
Worth sharing?

A Raspberry Pi can read a prerecorded video from local storage, repeat it with FFmpeg and send the result to YouTube Live. That is a file-playback workflow, not the same as streaming a Raspberry Pi camera, and uploading a file or making it loop does not start a live broadcast by itself.

The reliable approach is to check the media first, configure a YouTube encoder broadcast, run FFmpeg at the file’s natural pace, and test the complete path before leaving it unattended. The Pi, the file, the upload connection and the YouTube settings all affect whether the stream keeps working through the night.

Choose the local-file workflow

Start by deciding what your source actually is. If you have bhajan.mp4, lofi-night.mkv or another prerecorded file on the Raspberry Pi, FFmpeg should read that file as its input and repeat it. The Pi is acting as a small playback and encoding computer.

A camera workflow begins somewhere else. Raspberry Pi’s camera documentation describes rpicam-vid for creating camera-originated video and sending it over a network. That is useful when the source is a live camera, but it does not solve the problem of repeating a completed local video. Keep the two workflows separate rather than adapting a camera command to a file.

This distinction matters because the checks are different. A file has a known duration, video stream, audio stream and end boundary. A camera has changing content and no normal end-of-file event. For a devotional channel, local news loop, study screen or ambience station, the file path is usually easier to test because the input does not change while you are diagnosing it.

You can preview the file locally before involving YouTube. Full Raspberry Pi OS includes VLC and supports many common media formats with hardware acceleration, according to Raspberry Pi’s audio and video documentation. Raspberry Pi OS Lite does not include VLC by default; Raspberry Pi documents vlc-bin and vlc-plugin-base for headless use.

VLC and FFmpeg have different jobs here. VLC helps you see and hear what the file contains. FFmpeg is the part that can read the input at live pace, repeat it and produce an output stream for YouTube. A file playing correctly in VLC does not prove that the Pi can encode and upload it in real time.

If your actual aim is to run the same programme on several platforms, first resolve the YouTube path on its own. The workflow in how to stream the same video to YouTube and Facebook at once involves additional destinations and should not be mixed into the first troubleshooting test.

Check the file’s video and audio streams

Before writing an FFmpeg command, inspect the media. You need to know whether it has video, audio, both or neither, and which codecs and frame characteristics it uses. A file that looks normal in a desktop player may still have an unusual audio layout, variable frame rate or a codec that is too demanding for the particular Pi.

You can ask FFmpeg to report the file without producing an output:

ffmpeg -i input.mp4

The command prints information about the input and normally ends with an error because no output was specified. In this case, the diagnostic text is what you want. Look for a video stream, an audio stream, the video dimensions, frame rate and the audio format. If the file has no audio, decide whether silence is acceptable for the channel or whether you need to prepare a soundtrack before streaming.

Do not assume that a file extension tells you enough. mp4 describes a container, not the complete processing requirement. Two MP4 files can contain different video codecs, frame rates, audio codecs and channel layouts. The Pi may play one comfortably and struggle with another when FFmpeg has to decode, possibly encode and upload it continuously.

The source file’s frame rate is also relevant to the -re option described below. The purpose is to make FFmpeg consume the file at its intended playback speed instead of sending as much data as the Pi can read. A live platform expects a time-based stream, not a fast transfer of the entire file.

Make a short copy or test segment if the full programme is long. Include representative material: speech if the channel has speech, music if it has music, still images if the file contains long still sections and the loudest normal passage. You are testing the actual audio and movement that viewers will receive, not just a title card.

Do not infer a suitable Raspberry Pi model, resolution or maximum quality from the fact that VLC plays the file. Local playback and live encoding are different workloads. The exact board, operating system, source format, output format and upload connection need to be tested together.

If you are replacing a one-off file with a playlist or several segments, consider the failure mode at each boundary. How to keep FFmpeg streaming to YouTube after a video ends is relevant to end-of-file handling, but an infinite input loop is simpler when one prepared file is the complete programme.

Use FFmpeg’s input looping option

FFmpeg documents -stream_loop as the number of times to loop an input stream. A value of -1 means infinite looping. Place it before the input so it applies to the file being read.

A practical command shape is:

ffmpeg -re -stream_loop -1 -i input.mp4 \
  -c:v libx264 -c:a aac \
  -f flv rtmps://<youtube-ingest>/<stream-key>

This is a workflow outline, not a copy-and-run guarantee. The codec choices, output dimensions, frame rate, bitrate, keyframe settings and protocol endpoint must match the file, the Pi’s available processing capacity and YouTube’s current requirements. You may need to choose different output options after inspecting the source and checking the encoder settings available for your broadcast.

The important pieces have separate purposes. -re asks FFmpeg to read the file at its native rate, which is generally appropriate when a file is being used as a live-paced source. -stream_loop -1 tells FFmpeg to continue reading the input after it reaches the end. -i input.mp4 names the local file. The codec options determine how the output is packaged, and -f flv selects the output format commonly used for this ingest workflow.

The loop is not necessarily seamless. At the boundary, the output may briefly repeat a frame, pause, change audio continuity or show a visible cut, depending on the source and the way FFmpeg reopens and processes it. A file with a quiet fade-out and fade-in may make the boundary less distracting, but it does not remove the need to test it.

Keep the stream key private. Do not put it in a public screenshot, paste it into a forum post or commit the complete command to a public repository. If the key is exposed, use YouTube’s controls to replace or reset it as appropriate.

Run the command in a session that will remain available while you test. Watch the terminal for decode errors, broken-pipe messages, timestamp warnings and repeated reconnect attempts. A command that starts without an error can still fail when the file reaches its first boundary or when the network becomes less stable.

A Raspberry Pi is not automatically a suitable encoder for every source. If the output is too demanding, you may see late frames, increasing delay, dropped frames or an overloaded system. Lowering the output demand may help, but choose changes deliberately and confirm them in YouTube’s stream health rather than judging only by the local preview.

Configure YouTube Live ingest

Create or open the YouTube Live broadcast in YouTube Studio and select the encoder option. YouTube’s guide for creating a live stream with an encoder explains where to obtain the server URL and stream key. Those values belong in FFmpeg’s output destination.

The server URL and key are paired with the broadcast. Copy them carefully, including the protocol and punctuation. Do not substitute a watch-page URL, a channel URL or a normal video-upload URL. Those addresses are for viewing or managing content, not for receiving the encoder feed.

YouTube recommends RTMPS, which is the secure extension of RTMP. Use the ingest address shown by YouTube and confirm that the Pi’s FFmpeg build and network can make the required connection. If the available endpoint or protocol differs from the command outline, follow the current value displayed in the Live Control Room rather than forcing the example unchanged.

Starting FFmpeg does not necessarily make the public broadcast live immediately. Depending on the broadcast setup, YouTube may show an incoming preview first and require you to start the event in Studio. Check the status in the Live Control Room and follow the controls shown there. A successful local process and a receiving preview are not the same as a public live event.

There is also a difference between the ingest connection and the channel presentation. The incoming stream supplies moving audio and video. The title, description, thumbnail, visibility, schedule and other broadcast settings are managed in YouTube. Set these separately and verify the intended visibility before you start.

For a channel that needs to remain active after a single programme ends, the always-live checklist is useful alongside this technical setup. It covers operational checks that a command alone cannot perform, such as what happens when power, networking or the source file changes.

Match output settings to YouTube guidance

YouTube’s current encoder guidance lists H.264, H.265/HEVC and AV1 as video codec options, and AAC or MP3 for audio. It also lists support for frame rates up to 60 frames per second. That does not mean every Raspberry Pi can encode every listed combination in real time. Treat the available choices as platform guidance, then test the selected combination on your exact hardware.

YouTube recommends a two-second keyframe frequency and says not to exceed four seconds. A keyframe interval that does not match the platform’s guidance can affect how the stream is processed or how quickly a viewer can begin receiving usable pictures. Set it explicitly when your FFmpeg configuration allows it, and verify the resulting stream rather than assuming a default is suitable.

YouTube also recommends constant bitrate encoding. In practice, this means planning an output bitrate that the Pi can sustain and the internet connection can upload continuously. The correct setting is not simply the highest number the source file can support. A lower, steady output is more useful than a higher setting that causes congestion or encoder overload.

Use the output settings as a coordinated group:

Setting What to check Why it matters
Resolution Whether the Pi can process the chosen output continuously A large frame requires more work and upload capacity
Frame rate Whether it matches the programme and encoder capability Unnecessary conversion can add processing load
Video codec Whether FFmpeg and YouTube support the selected path A codec can be valid on YouTube but impractical on a particular Pi
Audio codec Whether the file and output contain usable audio Incorrect mapping can leave viewers with silence
Bitrate mode Use constant bitrate where required by the platform guidance Variable output can make upload planning harder
Keyframes Aim for YouTube’s two-second recommendation and stay within its limit Regular keyframes help the ingest stream handle the programme predictably
Protocol Prefer the RTMPS endpoint YouTube provides It is YouTube’s recommended secure ingest route

Do not copy settings from a different channel just because the source looks similar. A devotional image sequence, a camera-like music video and a local news bulletin can have different motion and audio demands. The file’s content affects the encoder workload, while the chosen output affects the upload workload.

If you want the channel to be discoverable as a repeating programme, presentation still matters after the transport works. Making a loop discoverable with playlists, chapters and the watch page covers the viewer-facing side without changing the FFmpeg process.

Run a short preflight test

Do not make the first test an overnight broadcast. Run the complete path for long enough to observe startup, ordinary playback, audio, a representative busy scene and, if possible, the point where the file repeats. YouTube recommends testing with sound and movement similar to the eventual stream.

A useful preflight has three views. First, watch the FFmpeg terminal on the Pi. Check that the process remains active and that errors do not accumulate. Second, open the YouTube Live Control Room and check whether the preview is arriving and whether stream health reports a problem. Third, watch the viewer-facing page from another device or network so you can hear the audio and see the actual delay and picture quality.

Check the upload connection while the test is running. YouTube recommends checking upload speed and monitoring the stream health during the event. Your connection needs enough consistent upstream capacity for the chosen output, with room for normal variation. A speed test taken when the network is idle is not proof that the connection will remain suitable while other people use it.

Listen for more than the presence of sound. Check that dialogue is understandable, music is not distorted, both intended channels are present and there is no unexpected silence after a transition. Watch for a picture that freezes while the terminal continues, or a preview that remains connected while the audio has stopped.

Test the restart path as well. Stop FFmpeg deliberately, then start it again using the correct broadcast details. Observe whether YouTube receives the new connection and whether the broadcast controls behave as expected. This does not guarantee recovery from every failure, but it reveals whether your notes and command are sufficient for a manual restart.

Check the Pi’s physical conditions during the test, including power stability, storage availability and network connection. Avoid claiming that any particular accessory is required without evidence for your board and setup. The practical question is whether this exact Pi can remain powered, connected and responsive for the planned run.

If the stream is intended for a small business, remember that the technical feed is only one part of the project. The decision to keep a prerecorded channel running should also account for maintenance and audience purpose, as discussed in what a 24/7 stream is worth to a small business.

Check the preview and repeat boundary

When YouTube shows the incoming preview, compare it with the local file. Look for changes in aspect ratio, cropped edges, stretched faces, missing audio or an unexpected colour shift. A local VLC preview can confirm the source, but only YouTube’s preview confirms the complete decode, encode, upload and ingest path.

Let the file approach its end during the test. The most important moment is not the first minute after startup; it is what happens when FFmpeg has to loop. Watch the final seconds, the first seconds after the repeat and the stream-health messages at the same time.

A visible cut may be acceptable for a simple news loop or information board. It may be distracting for meditation, devotional music or a long ambience recording. If the boundary is poor, edit the source file to create a more suitable ending and beginning, or use a prepared programme with a transition. Do not describe the result as seamless until you have observed it repeatedly on the actual output.

A brief interruption can also have more than one cause. It might come from the source file, decoder timing, encoder load, network congestion or YouTube ingest. Change one thing at a time and repeat the test so you know which adjustment helped. Replacing the file, changing the codec and changing the bitrate simultaneously makes the result difficult to interpret.

Once the test is acceptable, write down the working file path, FFmpeg command, broadcast name, output settings and the steps for replacing the stream key. Keep the secret key out of the document if the notes will be shared. Record what the preview looked like at startup and at the repeat boundary.

For people who would rather not leave a Raspberry Pi powered and monitored, StreamNeo removes the need to keep the playback computer running by taking an uploaded video, the YouTube stream key and the continuous broadcast operation into one hosted workflow. It is still your responsibility to prepare the media, choose suitable YouTube settings and check the result.

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 I use rpicam-vid to loop an MP4 file?

Not for this workflow. rpicam-vid belongs to Raspberry Pi’s camera-originated streaming path, while an MP4 loop should use a file input handled by an encoder such as FFmpeg. Choose the command based on the source, not on the fact that both workflows run on a Raspberry Pi.

Does uploading the video to YouTube make it a 24/7 live stream?

No. A normal upload and a live encoder broadcast are different YouTube workflows. You need a live broadcast configured for encoder input, the correct server URL and stream key, and an active FFmpeg process sending the repeated file.

Will -stream_loop -1 make the repeat seamless?

It makes FFmpeg repeat the input indefinitely, but it does not guarantee an invisible boundary. The ending and beginning of the media, timestamps, encoding load and ingest behaviour can all affect what viewers see. Test the actual repeat in YouTube’s preview before relying on it.

Is every Raspberry Pi powerful enough for this setup?

The available guidance does not establish a universal minimum model or a guaranteed maximum quality. The result depends on the board, source file, chosen output, encoder workload and upload connection. Test the exact combination you intend to leave running, including the file boundary and a representative audio section.

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 ↗