To loop a prerecorded video as a YouTube Live stream with FFmpeg, put -stream_loop -1 before the input and pace that input with -re. For NVENC, choose output settings against YouTube’s current guidance, then confirm the actual feed in YouTube Studio; no single preset suits every source, GPU and upload connection.
The command below is a starting structure, not a tested production recipe. Check what your local FFmpeg build and NVIDIA hardware support, replace the placeholders with values for your intended output mode, and test privately before scheduling a public broadcast.
Check the prerequisites before building the command
You need a prerecorded file, an FFmpeg build that exposes the NVIDIA encoder you intend to use, compatible NVIDIA hardware and driver support on the host, and a YouTube live stream configuration that supplies an ingestion address and stream name. The presence of an NVIDIA graphics card alone does not establish that its driver, runtime and FFmpeg build can use NVENC. Check the target machine, not a different desktop where you happened to install FFmpeg.
Inspect the file before streaming. Use FFmpeg’s probing tools or another media inspector to establish its video and audio streams, dimensions, frame rate, duration, pixel format and timestamps. Notice whether it has audio at all, whether there are multiple audio tracks, and whether its presentation is progressive or interlaced. These details affect mapping and output choices; a command that assumes a first audio stream can fail or silently send the wrong track.
Check the encoder’s supported options on the actual host with ffmpeg -h encoder=h264_nvenc. The available presets, rate-control options and tuning settings can differ by FFmpeg build, GPU generation and driver. Do not copy an old command merely because it uses an option with a familiar name. NVIDIA’s FFmpeg and NVENC guide explains its options and describes its examples as starting points rather than universal recommendations.
Decide the intended resolution and frame rate before selecting a bitrate or GOP size. Also check that the upstream connection can sustain the chosen video and audio data rate with room for ordinary variation. YouTube advises choosing a quality that the connection can reliably support. A useful local test is to compare the encoder’s output rate with the connection’s sustained upload capacity, rather than assuming a speed-test peak will be available continuously.
If you are choosing between a local always-on computer and another workflow, the relevant trade-offs include power, network reliability and who can respond when the process stops. The practical considerations in running a 24/7 sleep-sounds stream on a laptop in India may help you assess a local host; it does not replace checking your own machine and connection.
Loop the input with -stream_loop -1
FFmpeg’s -stream_loop is an input option: -stream_loop -1 asks it to repeat the specified input indefinitely. Because FFmpeg options generally apply to the next input or output, place the loop option immediately before the input it controls. The FFmpeg command-line manual documents both the infinite value and option ordering.
For a single-file source, the relevant part of the command is:
-stream_loop -1 -i "input.mp4"
Do not put -stream_loop -1 after -i. In that position, it does not control the input you meant to repeat. This is easy to miss when a command has many output options or when you add a second input later.
Looping and pacing do different jobs. Looping tells FFmpeg what to do when it reaches the end of the file; it does not make playback run at live speed. Pacing is handled separately, which is why the input in the next section uses -re as well.
A seamless-looking repeat also depends on the media. FFmpeg can start the file again, but it cannot remove a hard visual cut or a gap already encoded at the end of the source. Listen and watch across the actual end-to-start join. If you are investigating audio clicks or pauses between repetitions, see how to remove audio gaps when looping videos on YouTube Live; source edits may be needed even when the loop command is correct.
Pace prerecorded media for live transmission
A file can be read faster than real time if the process is allowed to consume it as quickly as it can decode and encode. For a prerecorded source being sent as a live feed, -re is commonly used to read at the media’s native rate. Put it before the relevant input, alongside the loop option:
-stream_loop -1 -re -i "input.mp4"
The two options have separate roles: -stream_loop -1 repeats the file, while -re paces reads. Neither option specifies your output frame rate, bitrate or keyframe interval. Those belong to the output and encoder configuration, and they must make sense for the chosen YouTube mode.
Real-time pacing does not repair unusual timestamps, variable frame rates, missing streams or a source that is unsuitable for continuous presentation. Inspect the file and watch a complete loop in a test. If it is variable-frame-rate, decide whether to preserve that behaviour or convert to a deliberate output frame rate, then verify that the resulting feed remains smooth. Avoid adding frame-rate conversion by reflex: every additional filter or conversion can change the output and consume resources.
If video and audio are stored separately, each is its own input and needs appropriate loop and pacing options before its own -i. Map the intended video and audio explicitly, and verify sync over time rather than assuming two files with similar durations will remain aligned. For playlist rotation rather than repeating one file, the workflow differs; using FFmpeg to rotate playlists across several YouTube channels covers a related scheduling problem.
Choose NVENC video and audio settings
For an H.264 output, the encoder name commonly used with FFmpeg is h264_nvenc, but it must be available in your installed build and supported by the host. NVIDIA describes constant bitrate (-rc cbr) as appropriate for streaming applications with strict bandwidth constraints. A minimal illustrative output structure is:
-c:v h264_nvenc -rc cbr -b:v <youtube_h264_recommended_rate> \
-g <frame_rate_times_2> -pix_fmt yuv420p \
-c:a aac -ar 44100 -b:a 128k
This is not a universal preset. Replace the bitrate placeholder with the value for the selected resolution and frame rate from YouTube’s current H.264 guidance. Set a GOP/keyframe interval that corresponds to the guidance and the output frame rate; the placeholder shows the relationship for a two-second interval, not a substitute for selecting and checking the actual frame rate. Confirm the chosen options are accepted by your installed encoder.
YouTube’s encoder settings page currently recommends CBR and a two-second keyframe interval, with a maximum interval of four seconds. It lists H.264 recommendations by output size and frame rate, including 14 Mbps for 1080p30, 17 Mbps for 1080p60, 8 Mbps for 720p30 and 720p60, and 4 Mbps for 480p30. These are YouTube recommendations, not mandatory values or a guarantee of picture quality. Consult the current table again before publishing, and choose an output your connection can sustain.
| Example H.264 output mode | YouTube recommended video bitrate |
|---|---|
| 1080p60 | 17 Mbps |
| 1080p30 | 14 Mbps |
| 720p60 | 8 Mbps |
| 720p30 | 8 Mbps |
| 480p30 | 4 Mbps |
The table is deliberately a selection aid, not a claim that every source should be upscaled to a larger mode. If a 720p source is all you have, sending it as 1080p does not add detail. Likewise, a higher frame rate is useful only where the source and intended presentation justify it and the host can encode it reliably.
For stereo audio, YouTube lists AAC or MP3 at 44.1 kHz and 128 Kbps. The example uses AAC. If the source has no audio, -map 0:a:0? can make an audio map optional at the FFmpeg level, but that does not mean YouTube will regard a video-only feed as healthy. The YouTube Live API identifies missing audio as an ingest issue. Add a deliberate audio input where appropriate, with its rights and mapping considered, and check YouTube’s status.
NVENC handles video encoding; it does not remove every other workload from the computer. FFmpeg still reads and demuxes the file, may decode or filter frames, processes audio, and muxes the outgoing stream. A more quality-oriented preset can demand more encoder capacity, and the practical result depends on the hardware and source. Test the configuration with the workload you intend to run rather than inferring performance from the encoder label.
Set the YouTube destination and protect the key
Create or select the live stream in YouTube’s live control workflow, then use the ingestion address and stream name supplied for that stream. YouTube recommends RTMPS. Its Live Streaming API documentation describes the primary RTMPS ingestion URL and stream name fields; the exact values come from your configuration and are not universal constants.
Some encoders accept an ingestion URL and stream name separately, while others expect them joined. FFmpeg’s FLV output commonly uses an RTMP-family destination, so an illustrative ending is:
-f flv "<rtmps_ingestion_url>/<stream_name>"
Replace both placeholders with the values YouTube gives you and confirm the expected format for the destination field. The complete command skeleton, with the loop and pacing options in the right place, looks like this:
ffmpeg -stream_loop -1 -re -i "input.mp4" \
-map 0:v:0 -map 0:a:0? \
-c:v h264_nvenc -rc cbr -b:v <youtube_h264_recommended_rate> \
-g <frame_rate_times_2> -pix_fmt yuv420p \
-c:a aac -ar 44100 -b:a 128k \
-f flv "<rtmps_ingestion_url>/<stream_name>"
The command illustrates option placement and stream mapping, not a validated command for every FFmpeg build. The optional audio map means “map this audio stream if it exists”; it does not create an audio stream. If the input has multiple video or audio tracks, select the intended streams rather than relying on first-stream assumptions. Check that the encoder accepts the complete command before relying on it for a scheduled broadcast.
Treat the stream key as a credential. Do not paste a real key into an article, screenshot, public script repository or shared terminal transcript. A key embedded in a shell command may be visible to other local users or retained in shell history. Use a protected secret-handling method suitable for your host, restrict access, and rotate the key through YouTube’s controls if it is exposed.
Check keyframes and match YouTube’s guidance
The output interval set by -g is measured in frames, so the frame rate matters. A two-second interval corresponds to twice the frames per second: at 30 fps, that is 60 frames; at 60 fps, it is 120 frames. Select the output frame rate deliberately, set the interval accordingly, and verify the emitted stream rather than assuming a setting has the intended effect.
YouTube’s H.264 guidance also specifies progressive scan, square pixels, two B-frames, one reference frame and CABAC for advanced settings. Its SDR guidance calls for Rec. 709 and 8-bit. Whether and how you set each option depends on the source, output format and what your local NVENC encoder supports. Check the installed encoder help and inspect the resulting stream. Do not transplant flags from a different encoder generation without confirming their meaning and support.
YouTube’s Live Streaming API lists ingest health issues that include open GOP and excessive keyframe interval. If your local log shows a running encoder but YouTube reports a GOP warning, inspect the actual output’s keyframe spacing and GOP behaviour. A declared -g value is not proof that the receiving service sees the expected pattern.
YouTube accepts several video codecs, but this article uses H.264 to keep the NVENC example aligned with the H.264 settings table. Follow YouTube’s current guidance for the codec you actually select. Use the official page as the source of current values because recommendations can change; do not treat the example table here as a permanent specification.
Test the feed and diagnose failures
Start with a private or otherwise controlled test, and watch the YouTube stream health display while FFmpeg is running. FFmpeg’s local output can report a successful connection or continued frame processing, but neither proves that YouTube is receiving a healthy picture and audio stream. Confirm the incoming video, audio, resolution, frame rate and warnings at YouTube’s end before using the workflow for a public, scheduled channel.
| Symptom | What to check first |
|---|---|
FFmpeg rejects h264_nvenc or an option |
Run ffmpeg -h encoder=h264_nvenc; check the local FFmpeg build, GPU support and driver/runtime compatibility. |
| The file ends instead of repeating | Confirm -stream_loop -1 is before the relevant -i, not among output options. |
| The stream runs too quickly or races through the file | Confirm -re precedes the prerecorded input. |
| YouTube shows no video or unexpected video | Check -map, source streams, output codec and the selected ingestion configuration. |
| YouTube reports missing audio | Inspect the source and mapping; an optional audio map does not create audio. |
| YouTube reports bitrate or keyframe warnings | Compare the output mode, bitrate, frame rate and actual keyframe interval with the current official guidance. |
| The picture stutters or audio drifts | Inspect timestamps and variable frame rate, test a full loop, and review host load and output stability. |
If a failure appears only after a repeat, watch the join in the source and the outgoing feed. A file can have a black frame, silence or a timestamp discontinuity at the boundary. If it fails immediately, check the ordering of input options, the stream key and address, and whether the local encoder accepts the selected settings. Change one thing at a time so that a successful test tells you what fixed the issue.
For a channel expected to run all day and overnight, consider who will notice and respond to a stopped local process or lost connection. When the specific burden is keeping a computer on and restarting a dropped broadcast, StreamNeo can take an uploaded video and run it as a YouTube live stream while your computer is switched off, with monitoring and automatic restart; it is YouTube-only, so a locally controlled FFmpeg setup may suit you better when you need custom processing or multi-destination output. The comparison of a YouTube 24/7 streaming service with OBS for Indian creators can help frame that operational choice.
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
Does -stream_loop -1 make a file stream live by itself?
No. It repeats the input indefinitely, while -re is commonly used to pace a prerecorded file at its native rate. You still need to configure an output, connect to YouTube and check the receiving stream’s health.
Where should I put -stream_loop -1 in FFmpeg?
Put it before the -i for the file it should repeat, for example -stream_loop -1 -re -i "input.mp4". FFmpeg treats it as an input option, so placing it after that input is not the right way to control its loop.
Which bitrate should I use with NVENC for YouTube Live?
Use the current YouTube recommendation for the H.264 resolution and frame rate you plan to send, then make sure the connection can sustain it. The figures in this article are YouTube recommendations, not a universal setting or a promise of stream quality.
Does a running FFmpeg process prove the YouTube feed is healthy?
No. A local process can continue while YouTube detects missing audio, an unsupported configuration, bitrate problems or other ingest issues. Check YouTube’s stream health and the actual received picture and sound during a test.