To loop a local video file to YouTube Live with an NVIDIA GPU, FFmpeg can repeat the input and encode the outgoing video with h264_nvenc. The command below is an illustrative template, not a tested recipe: it assumes a 1080p30 source, and you must check your FFmpeg build, GPU, source, and YouTube settings before relying on it.
The important adjustments are the input path, private stream key, output bitrate, frame rate and GOP length. A command that starts successfully is not proof that YouTube is receiving a stable stream, so test it in Live Control Room before leaving it unattended.
Review the illustrative command
ffmpeg -re -stream_loop -1 -i input.mp4 \
-c:v h264_nvenc -preset p4 \
-rc cbr -b:v 10M -maxrate 10M -bufsize 10M \
-g 60 \
-c:a aac -b:a 128k -ar 44100 \
-f flv "rtmps://a.rtmp.youtube.com:443/live2/STREAM_KEY"
Treat this as a starting point for inspection, not a paste-and-forget solution. The input is assumed to be a single local MP4 with video and audio, and the example’s -g 60 assumes 30 frames per second. It does not explicitly scale, crop, or convert frame rate; the file’s properties and the installed FFmpeg build affect what happens. If you need to standardise the output, first decide the desired resolution and frame rate, then add suitable output filters and options rather than assuming the example changes them.
The argument order has meaning. -re asks FFmpeg to read the input at its native rate rather than process it as fast as possible. -stream_loop -1 applies to the next input, while -i input.mp4 identifies that input. The -c:v option selects the video encoder, the following rate-control options describe its target behaviour, and -c:a selects audio encoding. Finally, -f flv selects the container format used for this RTMP-style output.
YouTube lists RTMP and RTMPS as ingest protocols and recommends RTMPS for encrypted transport. It also publishes settings for codecs, frame rates, keyframes and bitrates; use its current live encoder settings and bitrate guidance rather than treating the example’s numbers as universal. NVIDIA’s FFmpeg and GPU acceleration guide documents h264_nvenc, but its examples are not a validation of this combined live command on your machine.
Replace the input and stream key
Change input.mp4 to the actual file path. On Linux, a file in the current directory can be named directly; a file elsewhere needs its path, such as /home/user/videos/loop.mp4. On Windows, quote a path containing spaces, for example "C:\Users\Name\Videos\loop.mp4". Keep the -i option immediately after the loop option so that looping applies to this input.
Replace STREAM_KEY with the key for the intended YouTube broadcast. The destination shown is an RTMPS ingest address; check the current stream setup in YouTube if it provides a different address or key. Do not post a command containing the real key in a public chat, screenshot, script repository, or support ticket. If the key is exposed, rotate it in YouTube rather than assuming nobody has copied it.
The command assumes one input file and does not establish a playlist, transition, or continuous sequence of different videos. If your channel needs to change the media while keeping the broadcast live, the input arrangement is a separate problem; see the practical considerations in changing files in a YouTube live loop. For a single-file devotional or music stream, check that you have permission to broadcast the audio and images you are using, and confirm YouTube’s current rules for your channel.
Enable file looping
-stream_loop -1 tells FFmpeg to repeat the input indefinitely. It belongs before the -i it governs. The -1 value means no fixed repeat count, so FFmpeg continues reading the same file again after reaching its end, subject to the process and connection continuing to run.
Looping is not the same as stitching several files together. A single file that starts and ends with a visible jump or a silence may repeat that moment each cycle. Listen across the end-to-start boundary before broadcasting; inspect whether the final frame and first frame make a distracting cut. A long devotional recording with a clean musical cadence may be more suitable than a short clip whose first frame contains a title card or whose audio begins abruptly.
The -re option is useful here because a file can otherwise be read faster than real time. It does not make the connection reliable, repair a damaged file, or synchronise unrelated media. If your goal is an always-on channel, also plan what you will do if the computer, network, encoder process or YouTube ingest stops. A walkthrough such as running a 24/7 sleep music radio station can help frame the broader operating decisions beyond this one FFmpeg command.
For multiple files or transitions, do not simply add more -i options and assume the same loop behaviour. Concatenation and playlist handling depend on how the inputs are encoded and whether you need seamless audio and video boundaries. This template covers one input only; test a different construction separately and monitor the result before using it for a long broadcast.
Understand NVENC and rate settings
h264_nvenc selects NVIDIA’s H.264 encoder in an FFmpeg build that exposes it and on hardware that supports the requested encoding. NVENC is hardware encoding on supported NVIDIA GPUs, but that fact alone does not establish compatibility among your specific GPU, driver, operating system, FFmpeg build and source. NVIDIA’s NVENC application note describes its hardware encoding capabilities; it does not specify one GPU model as required for this template.
Before changing unrelated settings, check whether the encoder exists in your installation:
ffmpeg -encoders
ffmpeg -h encoder=h264_nvenc
Look for h264_nvenc in the first output and inspect the encoder help for options available in your build. FFmpeg options can vary across versions and builds. If the encoder is absent, a different bitrate value will not fix that; investigate the build and supported hardware first. The FFmpeg installation guide for Ubuntu and YouTube Live may be useful if you are preparing a Linux machine, but installation instructions do not confirm that a given build includes NVENC.
The example uses -preset p4, but available preset names and their behaviour depend on the installed encoder implementation and FFmpeg version. Inspect the local encoder help rather than assuming a preset will be accepted everywhere. A preset is a quality and processing choice, not a substitute for selecting an appropriate output resolution and bitrate.
-rc cbr requests constant bitrate rate control. The example sets -b:v, -maxrate and -bufsize all to 10M; these are illustrative values, not a recommendation for every resolution. YouTube’s table gives, for example, H.264 recommendations of 14 Mbps for 1080p30 and 17 Mbps for 1080p60. The corresponding minimum figures are 5 and 6 Mbps. These are YouTube’s published ingest settings, not an independent quality measurement. Match the row to the actual output codec, resolution and frame rate; the table may be updated, so recheck it when configuring a real broadcast.
| Intended H.264 output | YouTube recommended video bitrate | YouTube minimum video bitrate |
|---|---|---|
| 720p30 | 8 Mbps | 3 Mbps |
| 720p60 | 8 Mbps | 3 Mbps |
| 1080p30 | 14 Mbps | 5 Mbps |
| 1080p60 | 17 Mbps | 6 Mbps |
| 1440p30 | 21 Mbps | 7 Mbps |
| 1440p60 | 34 Mbps | 8 Mbps |
| 2160p30 | 42 Mbps | 11 Mbps |
| 2160p60 | 50 Mbps | 14 Mbps |
The table’s figures come from YouTube’s current published guidance, accessed on 3 October 2026, and should be checked against the official settings page before you set a live output. A higher resolution or frame rate increases the bandwidth requirement. Allow for the full outgoing stream, including audio and protocol overhead, and leave headroom on the available upload connection; an internet plan’s advertised download speed does not tell you its sustained upload capacity.
The -bufsize value affects rate-control buffering and the trade-off between how bitrate is managed and how promptly changes are reflected. NVIDIA’s guide uses equal -b:v, -maxrate and -bufsize values in one real-time example for a one-second buffer, and separately describes a one-frame buffer for low latency. Those are different choices. Do not combine buffer advice from different workflows without understanding the intended latency and rate-control behaviour; for a prerecorded loop, follow YouTube’s current ingest guidance and test rather than treating the sample buffer as mandatory.
Match output settings to the source
The example does not set an explicit output frame rate or resolution, so inspect the input before copying its GOP or bitrate values. Use ffprobe if available, or another media inspector, to find the video dimensions, frame rate, pixel format and audio properties. Decide what YouTube should receive. If the intended output is 1080p30, ensure the actual encoded output is 1080p30; a 1080p file recorded at another frame rate does not become 30 fps merely because the sample’s GOP is 60.
The -g option sets the GOP length in frames. YouTube recommends a two-second keyframe frequency and lists four seconds as the maximum interval. Thus, 60 frames corresponds to two seconds at 30 fps, while 120 frames corresponds to two seconds at 60 fps. If you choose another output rate, calculate the frame count from that rate. For fractional frame rates, use the actual output rate and check the resulting interval rather than rounding casually. The sample’s -g 60 is not universal and is not a guarantee that other encoder options or inputs will produce the intended result.
YouTube lists H.264, H.265 and AV1 as supported video codecs, but this command selects H.264. Do not change the codec name simply because another codec is supported: confirm that your FFmpeg build, NVIDIA encoder and YouTube ingest configuration support the particular choice. Codec support and bitrate recommendations are a connected decision, and the table above is specifically for H.264.
Audio is set to AAC at 128 Kbps and 44.1 kHz, with -ar 44100 requesting that sample rate. YouTube’s guidance specifies stereo AAC at 44.1 kHz and 128 Kbps. If the source has no audio, or has multiple tracks, the example’s assumptions need revisiting; inspect the file and make an explicit stream-selection decision. An unexpected silent stream or wrong language track is an operational error even if the video encoder works.
If you have to lower the output because your upload connection cannot sustain the target, reduce resolution or frame rate deliberately and then use the matching YouTube bitrate row and GOP calculation. Do not set a 2160p target at a bitrate chosen for 720p and expect the same result. The guide to YouTube live buffering and bitrate on JioFiber explains the practical relationship between connection limits and output settings; the same principle applies on other networks.
Protect the key and test carefully
First run the command while you can watch both FFmpeg’s output and YouTube Live Control Room. Check that FFmpeg opens the file, selects the expected encoder and continues sending data without errors. Then confirm YouTube recognises the stream and that the preview has picture, sound, the intended resolution and no recurring warnings. A process running in a terminal does not prove the platform has received an acceptable stream.
If FFmpeg says h264_nvenc is unavailable, check ffmpeg -encoders, the output of ffmpeg -h encoder=h264_nvenc, and whether the GPU and driver support the encoder. Avoid changing bitrate and audio options at random when the encoder itself cannot be opened. If YouTube rejects or flags the stream, verify the ingest address and key, selected codec, CBR configuration, output dimensions and frame rate, audio format and GOP interval against its current guidance.
Once the stream is accepted, observe it long enough to see whether the upload connection and machine can sustain the intended output. Then test a deliberate stop and restart so you know what recovery involves. This is especially important for a 24/7 channel: an FFmpeg command is a process on a particular machine, and a power cut, operating-system update, lost connection or process failure can interrupt it. Keep a copy of the exact command with the key removed so you can troubleshoot without exposing credentials.
Running FFmpeg on your own computer leaves you responsible for the computer staying powered, the network remaining available, and the process being restarted if it stops. If that is the specific burden you are trying to remove, StreamNeo takes an uploaded file and your YouTube stream key and runs the broadcast with your computer switched off, with monitoring and automatic restart if it drops. It is YouTube-only, so this does not replace a workflow that needs other destinations or the flexibility of a locally managed FFmpeg pipeline.
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
How do I loop a video on YouTube Live with FFmpeg?
Place -stream_loop -1 before the -i input it applies to, then configure an output suitable for YouTube and send it to the current ingest address with your stream key. The command in this article is an untested template with specific input assumptions, so verify the source, encoder and actual received stream first.
How do I use NVENC with FFmpeg to stream to YouTube?
Use -c:v h264_nvenc only if your GPU and FFmpeg build support that encoder. Check the local build with ffmpeg -encoders and ffmpeg -h encoder=h264_nvenc; the flag does not guarantee compatibility with every NVIDIA setup.
Is 10 Mbps the right bitrate for a 24/7 stream?
Not by itself. The example’s 10 Mbps is illustrative and differs from YouTube’s H.264 recommendation for 1080p30, which is 14 Mbps in the published guidance cited here. Choose the row matching the intended codec, resolution and frame rate, then confirm that your connection can sustain the output.
What should I do if YouTube does not accept the stream?
Check the key and ingest URL, then compare codec, CBR settings, resolution, frame rate, audio and GOP interval with YouTube’s current official page. Also look at FFmpeg’s error output and verify that the chosen encoder is available; acceptance cannot be guaranteed by a command template.