October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
DocumentaryTube
cron

How to Use a Cron Job to Start a Prerecorded YouTube Livestream on a VPS

A cron job can launch FFmpeg on a VPS to send prerecorded video to YouTube Live—but the scheduled encoder feed may still need a manual Go live action in Live Control Room.

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

You can schedule FFmpeg on a Linux VPS to send a prerecorded video to a YouTube Live event, but starting the encoder is not always the same as making the broadcast public. For a scheduled encoder stream, YouTube’s documented workflow has you wait for the preview in Live Control Room and click Go live. Treat cron as the launch mechanism—not proof that the event is live.

What you need before scheduling the stream

  • A YouTube channel eligible for live streaming. Enabling live streaming for the first time may take up to 24 hours, according to YouTube Help; enable it well before the event.
  • A Linux VPS with FFmpeg installed, enough disk space for the media, and sufficient network capacity for its outgoing bitrate.
  • A prerecorded file available at a stable absolute path for the entire stream.
  • A scheduled YouTube Live event, its ingest URL and stream key, and a plan for the required Studio Go live action.

There is no universal VPS size established for this workflow. Resource needs depend on the file’s resolution and bitrate, whether you transcode, and the VPS provider’s limits. A private or unlisted test event is the safest way to check the full chain.

Create the YouTube Live event and protect its key

  1. Schedule the event in YouTube Studio. Set the title, date, visibility and other event details. Scheduling creates a watch page viewers can share and lets viewers set reminders. Follow YouTube’s encoder-stream instructions for the current Studio interface.
  2. Copy the ingest URL and stream key from the event’s encoder settings. Use exactly the URL and path that Studio provides; do not assume an endpoint format or substitute a key from another event.
  3. Store the key outside the cron line and source code. Keep it in a protected configuration file or environment source readable only by the account that runs the stream. Do not put it in shell history, screenshots, public logs, or a public repository. If it is exposed, rotate it in YouTube Studio.
  4. Choose visibility deliberately. Use a private or unlisted test first, then confirm the actual event state and playback before relying on an unattended launch.

Choose whether to copy or transcode the video

Stream-copy when the file already fits

Stream-copying avoids re-encoding and therefore avoids the additional CPU work of transcoding. It is only suitable if the source’s codecs, timestamps, frame rate, audio and container are acceptable for the intended output. Inspect the file and test it against YouTube’s current encoder guidance; do not assume that every MP4 is ready to copy unchanged.

Transcode when output needs to change

Transcoding lets FFmpeg change video or audio format, resolution, frame rate or bitrate, but uses VPS CPU. Plan capacity based on the actual source and output rather than assuming a universal VPS specification. YouTube’s current guidance lists H.264, H.265/HEVC or AV1 options depending on configuration, frame rates up to 60 fps, CBR bitrate encoding, AAC or MP3 audio, and a recommended 2-second keyframe interval (no more than 4 seconds). Use the bitrate row for your chosen resolution and codec in YouTube’s encoder settings table; a bitrate for another resolution is not a safe substitute.

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.

YouTube recommends RTMPS, its secure extension of RTMP. Match the stream’s protocol and encoding settings to the current Studio-provided ingest details and YouTube’s published settings.

Build and test an FFmpeg command

The following is a command shape, not a tested turnkey script. Replace the placeholders, select output options appropriate to the source and installed FFmpeg release, and verify that the resulting URL form matches Studio’s encoder details. Never publish or log the actual stream key.

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.
/usr/bin/ffmpeg -nostdin -re -i /absolute/path/video.mp4 [output options] -f flv 'rtmps://INGEST_URL/STREAM_KEY'

-re reads the input at its native frame rate (equivalent to -readrate 1), rather than allowing a file to be read as fast as possible. FFmpeg input options belong before the relevant input. -nostdin disables interactive console input checks for background operation. See the FFmpeg documentation and FFmpeg FAQ, and check option behavior against the release installed on your VPS.

For one playback

Leave out a loop option. The feed ends when the file ends, so choose a file duration that fits the scheduled event.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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.

For intentional continuous playback

FFmpeg documents -stream_loop -1 for infinite input looping. Put it before the relevant -i, for example:

/usr/bin/ffmpeg -nostdin -re -stream_loop -1 -i /absolute/path/video.mp4 [output options] -f flv 'rtmps://INGEST_URL/STREAM_KEY'

Loop only when repeated playback is intended. A supervisor or restart policy should not turn a planned one-time event into an unintended continuous broadcast.

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

Keep the command’s output appropriate

The example uses FLV output with an RTMPS destination as a conceptual pattern, not a guarantee for every FFmpeg build or YouTube ingest endpoint. If copying streams, check source codecs and timestamps; if transcoding, explicitly choose video and audio codecs, bitrate mode, frame rate, keyframe interval and any scaling needed. Compare the chosen output to YouTube’s current settings table before going live.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Schedule the launch with cron

Use an absolute path to the script and explicitly set its working directory, configuration and log destination inside the script. Cron commonly provides a more limited environment than an interactive shell, so test with the same account and environment that will run the scheduled job. Cron syntax and environment vary across Linux systems; verify the installed system’s behavior rather than treating an example as universally portable.

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.
  1. Create a script that changes to the intended working directory, loads the protected key configuration without printing it, and runs the FFmpeg command.
  2. Use absolute paths for FFmpeg, the media file, configuration and logs.
  3. Set the schedule in that VPS’s crontab using syntax supported by its cron implementation. Keep credentials out of the crontab entry itself.
  4. Redirect standard output and errors to a controlled log location, with a retention or rotation policy so logs do not fill the disk.
  5. Test a manual launch, then a cron launch under the intended user. Confirm that the process starts only once and that overlapping runs cannot occur.

A cron process running successfully only confirms that the encoder was launched. It does not establish that YouTube accepted the feed or that the public broadcast began.

Confirm the preview, go live, and finish cleanly

  1. Start the encoder at the planned time and open the event in YouTube Live Control Room.
  2. Wait for YouTube to receive the feed and show its preview. Check the picture, sound, aspect ratio and any warnings.
  3. For the documented scheduled encoder flow, click Go live in Live Control Room when the preview is ready. Do not assume the cron job performs this Studio action.
  4. At the end, stop the encoder or let a one-shot file finish, then check the event in Studio. YouTube says streams under 12 hours are automatically archived; do not assume the same automatic archive outcome for a longer stream.

Programmatic control is a separate project: YouTube’s Live Streaming API documentation describes broadcast and stream resources for managing live workflows. API automation requires its own authentication, event-state handling and implementation; cron launching FFmpeg alone does not provide it.

Troubleshoot common failures

Symptom Likely cause What to check
Encoder process starts, but no preview appears Wrong ingest URL or key, network/egress problem, or FFmpeg output that YouTube does not accept Compare the exact event URL and key in Studio, inspect FFmpeg’s error log without exposing the key, and test protocol and encoding settings.
Preview appears, but viewers cannot watch the event The scheduled event is awaiting the Studio action Check Live Control Room’s event state and click Go live when the preview is ready.
Video or audio is missing or malformed Unsupported or unexpected source streams, timestamps, aspect ratio, or output settings Inspect the source streams, compare codecs and output settings with YouTube’s current guidance, and test a private or unlisted event.
Stream stops when the file ends The command is a one-shot playback Use -stream_loop -1 before the input only if continuous repetition is intended.
Job works interactively but not from cron Different environment, working directory, permissions or paths Use absolute paths, set the working directory and configuration explicitly, and test as the scheduled user.
Duplicate streams or unexpected restarts Overlapping cron executions or a restart policy that ignores the event’s planned end Prevent concurrent runs and ensure any supervisor stops or remains inactive after a planned completion.
Stream ends under load or the VPS runs out of space Insufficient provider bandwidth, CPU for transcoding, disk space, or media availability Check provider limits, actual process use, available space and file access during a test; there is no single VPS size that fits every source and encoding choice.

Or let it run in the cloud

If the goal is to keep prerecorded video looping on a YouTube channel without maintaining a VPS job, StreamNeo is a cloud alternative: upload a recording or build a playlist, add your YouTube stream key once, and go live. It keeps the stream running without a computer or home connection staying on, supports uploaded quality up to 4K 60fps at one flat price per slot, and automatically recovers if YouTube drops the stream. The first day is free with no card; one free day is available per account. Monthly billing is $9.99 per month. UPI and cards are supported in India, and card checkout is available worldwide. Start your free day with StreamNeo.

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.

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

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 the Screening Room

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.