October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
24/7 livestreaming

How to Set Up a 24/7 YouTube Sleep Music Radio Channel with FFmpeg

A practical FFmpeg guide to looping sleep music on YouTube Live, with setup steps, an adaptable command, stream-health checks, recovery advice and replay limits.

By VGSources Team 9 min read
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run a 24/7 sleep-music channel on YouTube with FFmpeg, enable live streaming on your channel, prepare a music-and-video file you have the rights to broadcast, and send it to YouTube’s live ingest server using a private stream key. FFmpeg can loop the file in real time, but a continuous stream still needs monitoring and a recovery plan: neither the encoder nor YouTube is guaranteed to stay connected indefinitely.

Before you start

  • A YouTube channel eligible for live streaming. YouTube says the channel must be verified and have had no live-streaming restrictions in the previous 90 days. First-time activation may take up to 24 hours, so enable it well before your planned launch.
  • A computer or server that can run FFmpeg continuously. The process has to stay running and have a reliable outbound internet connection. The required CPU and network capacity depend on your media and output settings; there is no universal minimum established here.
  • A prepared source file. The example below assumes one video file containing both picture and audio. Check the file plays correctly from beginning to end before using it.
  • Permission to broadcast and archive the music. You are responsible for having the necessary rights for the live broadcast and any replay. A “royalty-free” label by itself does not establish that a track’s license covers your territory, a continuous live broadcast, monetization, or an archived copy.

Enable YouTube live streaming and create the event

  1. In YouTube Studio, open Live Control Room and enable live streaming if the channel has not used it before. Allow up to 24 hours for first activation.
  2. Create or schedule an encoder stream in Live Control Room. Choose the title, visibility and other event details you want viewers to see.
  3. Copy the ingest stream URL and stream key shown for the event. YouTube describes the key as the credential that tells the encoder where to send its feed. Treat it like a password: do not include it in public source code, screenshots, public logs or a shared command history. If it is exposed, reset it in YouTube Studio.

Use the RTMPS ingest URL when YouTube provides it. RTMPS encrypts the connection between your encoder and YouTube. Keep the URL and key separate from any public-facing channel description or scripts you publish.

Prepare a sleep-music file that can loop cleanly

Check the media before streaming

  • Confirm the file contains the audio and video tracks you intend to send. The command below expects one video stream and one audio stream.
  • Listen through the beginning and end, including the transition where the file will repeat. A hard cut, silence, abrupt change in volume or visual flash can be distracting during a sleep stream.
  • Make sure the music license covers the intended live use and, if you want a replay, the archive as well. Retain the license or other rights documentation.
  • Use a media file accessible to the account that runs FFmpeg. If the host restarts, the source path and any supporting files must still be available.

For a playlist rather than one long file

FFmpeg’s -stream_loop option repeats an input. The simplest setup is to prepare the playlist as one tested media file, then loop that file. If you instead assemble a playlist from separate files, verify the audio and video formats and transitions first; mismatched streams or durations can create gaps, abrupt cuts or a process failure. A playlist is not permission to use its tracks: each item still needs appropriate broadcast rights.

Send the loop to YouTube with FFmpeg

The following Bash example is for a 30 fps, 1080p H.264 video with AAC audio. It loops a local MP4 containing both video and audio, reads it at normal playback speed, and sends it to the RTMPS ingest address. The 4,500 kb/s video bitrate is an illustrative starting value for this command, not a universal YouTube recommendation. Select a bitrate suitable for your output resolution and available upload capacity, and check YouTube’s current encoder guidance before going live.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
: "${YT_RTMPS_URL:?Set YT_RTMPS_URL to the RTMPS ingest URL from YouTube Studio}"
: "${YT_STREAM_KEY:?Set YT_STREAM_KEY to the private stream key from YouTube Studio}"

ffmpeg -hide_banner -re -stream_loop -1 -i "sleep-radio.mp4" 
  -map 0:v:0 -map 0:a:0 
  -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" 
  -r 30 -c:v libx264 -preset veryfast -pix_fmt yuv420p 
  -b:v 4500k -maxrate 4500k -bufsize 9000k 
  -g 60 -keyint_min 60 -sc_threshold 0 
  -c:a aac -b:a 160k -ar 44100 
  -f flv "${YT_RTMPS_URL}/${YT_STREAM_KEY}"

Set YT_RTMPS_URL and YT_STREAM_KEY in the environment of the shell or service that runs FFmpeg; enter the values privately from YouTube Studio rather than putting the actual key in a published script. The command assumes Bash and an FFmpeg build with the listed encoders available. Replace sleep-radio.mp4 with your actual file path.

What the important options do

  • -re reads the file at its native playback rate instead of sending it as fast as possible. This is the appropriate pattern for simulating a live source from a file.
  • -stream_loop -1 repeats the input indefinitely. Because the audio and video are in the same file, they repeat together.
  • -map 0:v:0 -map 0:a:0 selects the first video and first audio streams. If your source has a different layout, inspect it and adjust the mapping rather than assuming these stream indexes.
  • The scale and pad filter fits the picture into a 1920 by 1080 frame while preserving its aspect ratio. It can add borders when the source has a different shape; remove or change it if your chosen output dimensions and source do not call for it.
  • -r 30 sets 30 output frames per second. -g 60 and -keyint_min 60 set a 60-frame keyframe interval, which is two seconds at 30 fps. YouTube recommends a two-second keyframe interval and says not to exceed four seconds.
  • -c:v libx264 selects H.264 video encoding; -preset veryfast trades some compression efficiency for lower encoding workload. If the machine cannot encode smoothly, reduce the workload or choose a host that can sustain the selected output.
  • -b:v, -maxrate and -bufsize configure video rate control in this example. The right video bitrate depends on resolution and available upload bandwidth; changing it may be necessary if YouTube reports poor stream health.
  • -c:a aac -b:a 160k -ar 44100 encodes the audio as AAC at the values shown. Check that the source sounds clean at the loop point and that the resulting stream has audio in YouTube’s preview.
  • -f flv selects the container used for this RTMP-family output. The command appends the private stream key to the ingest URL.

This is an example to adapt and test, not a verified production configuration for every media file, FFmpeg build or host. Check which FFmpeg version and codec support are installed on your machine, and test the exact source and settings before relying on a long broadcast.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Test the stream and check YouTube’s health indicators

  1. Start FFmpeg before the event time and check its output for errors. Confirm that the process is reading the file and sending data rather than exiting immediately.
  2. In YouTube Studio’s Live Control Room, wait for the incoming feed and preview to appear. Confirm that both the picture and audio are correct before making the event public or announcing it.
  3. Check YouTube’s stream-health feedback and correct any warnings before leaving the stream unattended. Monitor upload performance, not just download speed.
  4. Leave about 20% upload-bandwidth headroom above the bitrate you are sending, as YouTube recommends. Other devices or uploads on the same connection can consume that capacity and cause instability.
  5. After the test, verify that your launch procedure can restart FFmpeg and that you know how to replace the key if it is exposed.

Keep FFmpeg running and plan for recovery

A 24/7 goal does not mean one process or one YouTube event will never disconnect. Network loss, host restarts, encoder errors or a YouTube-side interruption can stop the feed. FFmpeg documents recovery attempts for some RTMP output failures, but reconnect behavior does not guarantee that YouTube will preserve the same live event or that viewers will see uninterrupted playback.

Use a supervisor on an always-on host

For a Linux host managed by systemd, a service unit can restart FFmpeg if the process exits. This is a starting pattern, not a complete monitoring system; adjust paths and account permissions for your host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
[Unit]
Description=YouTube sleep music stream
After=network-online.target
Wants=network-online.target

[Service]
User=stream
EnvironmentFile=/etc/streamneo-env
WorkingDirectory=/srv/sleep-radio
ExecStart=/usr/bin/ffmpeg -hide_banner -re -stream_loop -1 -i /srv/sleep-radio/sleep-radio.mp4 -map 0:v:0 -map 0:a:0 -vf scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2 -r 30 -c:v libx264 -preset veryfast -pix_fmt yuv420p -b:v 4500k -maxrate 4500k -bufsize 9000k -g 60 -keyint_min 60 -sc_threshold 0 -c:a aac -b:a 160k -ar 44100 -f flv ${YT_RTMPS_URL}/${YT_STREAM_KEY}
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

In this illustration, create the environment file at the stated path with the two private values, restrict access to it, and make sure the service account can read the media file. Then reload systemd, enable and start the service, and inspect the service status and logs. If the unit fails because of quoting, environment expansion or a different systemd version, run the command interactively first and adapt the unit to that host. Do not put a real stream key in a world-readable file.

A supervisor only restarts a failed process. It does not tell you whether viewers can hear the stream, whether YouTube has accepted the feed, or whether the host has internet access. Add alerts or regular checks appropriate to your setup, and keep a tested procedure for restarting the event or issuing a new stream key if needed. A separate backup encoder or network may improve resilience, but it is not a stated requirement.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand replay limits for a continuous broadcast

YouTube says streams under 12 hours are automatically archived. Its guidance does not promise a complete archive for a single stream that runs longer than that. If preserving replays matters, plan and test discrete broadcasts under the documented threshold, and confirm the current behavior in YouTube Studio; splitting the broadcast means viewers may experience separate events rather than one uninterrupted live event.

Troubleshooting common failures

Symptom Likely cause What to check or do
No incoming video in Live Control Room Wrong ingest URL or key, live streaming is not enabled, or the encoder failed to start. Check that the current event’s URL and key are set in the FFmpeg process environment, confirm the channel is enabled for live streaming, and inspect FFmpeg’s first error messages. Reset the key if it may have been exposed.
FFmpeg exits with an encoder or codec error The installed build may lack a requested encoder, or the source does not contain the stream selected by the mapping. Inspect the installed FFmpeg build and the source’s streams. Confirm that H.264 and AAC encoders are available and that the file has the video and audio streams selected in the command.
Video stutters or YouTube reports poor stream health The host may not encode in real time, or the upload connection may lack capacity or headroom. Check FFmpeg’s output for slow processing, reduce encoding workload or bitrate as appropriate, and check upload performance. Keep the recommended 20% bandwidth headroom.
Audio is missing or the loop sounds abrupt The input may not contain the mapped audio stream, or the source itself may have a gap or hard cut at its end. Preview the incoming audio in Live Control Room, inspect the source’s audio streams, and listen through the file’s loop point before using it live.
The feed stops after a host or network interruption The FFmpeg process ended, the network dropped, or YouTube ended or interrupted the event. Check the host and service logs, confirm the source file and key are still available, and follow your tested restart procedure. Process restart alone cannot guarantee continuity of the YouTube event.
No complete replay appears after a day-long stream The broadcast exceeded YouTube’s stated automatic-archive threshold. Do not assume a stream longer than 12 hours will be fully archived. If a replay is important, use separately planned broadcasts below that threshold and verify the current Studio behavior.

Or let it run in the cloud

If you would rather not maintain a local FFmpeg process or keep a home computer online, StreamNeo is a YouTube-only cloud service for looping uploaded videos. Upload your recording or build a playlist, add your YouTube stream key once, and go live. Nothing has to stay on at home; it streams the uploaded quality up to 4K 60fps at one flat price per slot, with automatic recovery if YouTube drops the stream. The first day is free with no card, one free day per account. The monthly option is $9.99 per month. You can review StreamNeo and its plans. You remain responsible for music rights and YouTube’s live-stream requirements. Start the StreamNeo free day.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from Patch Notes

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.