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

To run an FFmpeg livestream from an AWS VPS to YouTube, start an internet-connected Linux EC2 instance, install FFmpeg, copy the RTMPS server URL and stream key from YouTube Live Control Room, then run FFmpeg with settings matched to your video. For a prerecorded file, the example below loops it continuously. The VPS must have enough CPU for encoding and enough sustained network capacity for the stream; neither is guaranteed by bitrate alone.

What you need before starting

  • An AWS account and an EC2 instance running Linux, with a route to the internet and outbound access to YouTube’s ingest endpoint.
  • A video file on the instance for a prerecorded stream, or an appropriate real-time input source for a live camera or other feed.
  • A YouTube channel with livestreaming enabled and a stream or scheduled event available in Live Control Room.
  • An FFmpeg build that includes the encoder and protocols you plan to use. Package contents depend on the Linux image and its repositories.

Use an EC2 type capable of sustaining both the encoding workload and the outgoing stream. CPU demand varies with codec, resolution, frame rate, filters, and encoder preset. AWS network capacity also varies by instance type; some configurations have baseline bandwidth and burst behavior, so an advertised “up to” rate is not a promise of continuous throughput. AWS EC2 network bandwidth guidance explains these differences.

Prepare the AWS VPS

Choose an instance and secure access

Select an EC2 instance based on the intended encoding settings, then verify its actual CPU and network behavior during a representative test. There is no universally suitable instance size: the right choice depends on your source, encoder settings, region, and workload.

In the instance’s security group, restrict inbound SSH access to trusted source IP addresses. The VPS sends video outbound to YouTube; this workflow does not require opening an inbound public video port. Ensure the instance has outbound internet routing and that security-group egress permits the connection. AWS security group documentation describes their traffic controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
ZOERAX 100-Pack M6 x 16mm Rack Mount Cage Nuts, Screws and Washers
  • Wide Compatibility & Versatile Use: ZOERAX M6 rack mount screw kit is ideal for installing server racks, network cabinets, rack shelves, patch panels, A/V equipment, and more. Designed for standard square-hole racks and cabinets, these M6 cage nuts and screws ensure a secure fit for most 19-inch rack systems used in data centers, offices, and home labs
  • Heavy-Duty Carbon Steel Construction: Made from premium carbon steel, these M6 cage nuts and screws deliver high strength and long-lasting durability. The material provides excellent resistance to rust, corrosion, and oxidation, performing reliably in demanding environments such as high humidity, temperature fluctuations, and long-term rack installations
  • Precision Metric Standard M6: Manufactured to strict metric standards, each M6 screw and cage nut features precise dimensions with minimal tolerance. Clean, sharp threads without burrs allow smooth installation without stripping or slipping. The deep Phillips head design ensures better torque control and faster, more efficient mounting
  • Safe, Reliable & Eco-Conscious Materials: ZOERAX uses non-toxic, environmentally friendly carbon steel materials to ensure safe handling and use. Heat-treated for optimal hardness, ductility, and impact resistance, these rack screws and cage nuts offer dependable performance while meeting safety and quality expectations for professional installations
  • Complete Mounting Kit with Washers: This essential M6 rack hardware kit includes screws, cage nuts, and heavy-duty washers. The included washers help distribute pressure evenly and reduce scratches or marks on rack rails and equipment, providing a cleaner, more secure installation right out of the box

Install and check FFmpeg

On a Debian- or Ubuntu-style image, install the distribution package and check the installed build:

sudo apt update && sudo apt install ffmpeg
ffmpeg -version

Other Linux images may use a different package manager or repository. Confirm that the installed build supports the codecs and output protocol required for your stream.

Get YouTube’s RTMPS URL and stream key

  1. Open YouTube Live Control Room and create or select the stream or scheduled event.
  2. Open the stream settings and copy the server URL and stream key. YouTube says the RTMPS URL can be revealed with the lock icon in the Stream URL field.
  3. Use the RTMPS endpoint shown there, including its hostname and port. Google’s ingestion guidance documents RTMPS on port 443 and explains that the hostname is needed for TLS/SNI authentication.
  4. Keep the stream key secret. Do not put it in a public script, screenshot, source repository, or exposed log. For unattended streaming, retrieve it using a protected environment or another secret-management method appropriate to the host.

YouTube recommends RTMPS for secure ingestion. See YouTube’s encoder settings guidance and Google’s RTMPS ingestion documentation.

Run FFmpeg with a prerecorded video

This illustrative command sends an MP4 in real time and loops it. It is a baseline for a modest 720p/30-fps-style stream, not a tested command or universal YouTube preset. Replace the placeholders with values for your file and the endpoint format shown in Live Control Room.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
VIDEO=/path/to/video.mp4
RTMPS_URL='rtmps://<server-from-live-control-room>:443/<app-or-path>'
STREAM_KEY='<secret-stream-key>'

ffmpeg -re -stream_loop -1 -i "$VIDEO" 
  -c:v libx264 -preset veryfast -pix_fmt yuv420p 
  -r 30 -g 60 -b:v 4500k -maxrate 4500k -bufsize 9000k 
  -c:a aac -b:a 128k -ar 44100 -ac 2 
  -f flv "$RTMPS_URL/$STREAM_KEY"

The endpoint’s path may already include the stream key. Follow the format supplied by Live Control Room rather than blindly appending the key. Also, putting a key directly in a shell command can expose it through shell history or process listings; use a protected secret-handling approach for production or unattended jobs.

What the main options do

  • -re reads a prerecorded file at its natural playback rate rather than sending it as fast as possible.
  • -stream_loop -1 repeats the input indefinitely.
  • -c:v libx264 selects H.264 video encoding; -preset veryfast trades some compression efficiency for lower CPU demand.
  • -r 30 sets 30 frames per second. Match this and the output resolution to the source and chosen YouTube bitrate guidance.
  • -g 60 sets a 60-frame GOP, which at 30 fps produces a two-second keyframe interval.
  • -b:v, -maxrate, and -bufsize set the video rate and rate-control buffer. The example’s 4,500 Kbps values are illustrative, not YouTube’s recommended rate for every resolution.
  • -c:a aac -b:a 128k -ar 44100 -ac 2 encodes stereo AAC at 128 Kbps and 44.1 kHz.
  • -f flv muxes the stream in the format used for RTMP/RTMPS ingest.

For a live input instead of a file

Replace the file input with the FFmpeg input device or source URL for your camera or real-time feed, and remove -re if the input is already arriving in real time. Input syntax and device flags vary by source and operating system, so check the documentation for that specific input rather than copying the file-loop options unchanged.

Match the stream to YouTube’s settings

YouTube’s current encoder guidance recommends constant bitrate (CBR), RTMPS, and a keyframe interval of two seconds, not exceeding four seconds. It supports H.264, H.265/HEVC, and AV1 for RTMP/RTMPS ingestion, with frame rates up to 60 fps. The appropriate bitrate depends on the codec, resolution, and frame rate; use YouTube’s current table for the exact combination you intend to send.

Setting YouTube guidance
Protocol RTMPS recommended
Rate control Constant bitrate (CBR) recommended
Keyframe interval 2 seconds recommended; no more than 4 seconds
H.264, 1080p at 30 fps 10 Mbps recommended
H.264, 1080p at 60 fps 17 Mbps recommended
Stereo AAC audio 128 Kbps at 44.1 kHz recommended
Supported RTMP/RTMPS video codecs H.264, H.265/HEVC, and AV1
Maximum frame rate Up to 60 fps

These are YouTube’s published recommendations, not a guarantee that a particular VPS can encode and upload at the selected rate. YouTube transcodes incoming streams into multiple viewer formats, but your VPS still needs a stable outgoing connection. Test with motion and audio similar to the actual program, then monitor stream health in Live Control Room. Guidance: Choose live encoder settings, bitrates, and resolutions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the stream and monitor it

  1. Before a scheduled broadcast, start a test using representative video motion and audio rather than a static or silent sample.
  2. Watch YouTube Live Control Room for stream health and confirm that audio and video arrive as expected.
  3. On the VPS, observe CPU load and network throughput while encoding. If the instance becomes saturated, lower the encoding workload or choose capacity suited to the settings.
  4. Once the event is live, keep monitoring both YouTube’s stream health and the instance. A command starting successfully does not prove that the stream remains stable.

Troubleshoot common failures

Symptom Likely cause What to check or change
TLS or certificate error Wrong protocol, altered hostname, or incorrect port Copy the RTMPS URL from Live Control Room again; preserve its hostname and use the endpoint’s port (Google documents RTMPS on port 443).
Connection timeout No outbound route or egress blocked Check the instance’s internet route and security-group egress rules, then retry.
YouTube reports poor stream health Codec, bitrate, keyframe interval, frame rate, or audio does not match guidance or is unstable Compare those settings with YouTube’s current encoder guidance and repeat a representative preflight test.
Stream starts, then becomes unstable CPU or sustained network capacity is insufficient Inspect CPU load and throughput. EC2 networking varies by instance type and may use baseline/burst behavior; verify sustained performance rather than relying on an “up to” figure.
Unexpected AWS bill Instance runtime or outbound data transfer was higher than expected Review instance hours and transfer usage, and estimate costs for the selected region and configuration before leaving a stream running continuously.

Estimate AWS costs before leaving it running

A continuously running VPS incurs costs tied to the selected compute resource and outbound data transfer; storage can also contribute. The amount depends on AWS region, instance type, runtime, and actual transfer volume, so there is no single reliable price for an unspecified deployment. Check current AWS pricing for the configuration you choose. AWS EC2 pricing identifies compute and data transfer as cost considerations; see also EC2 network bandwidth details.

Or let it run in the cloud

If your goal is to keep prerecorded videos live on YouTube without maintaining an FFmpeg VPS, StreamNeo is a cloud service that loops uploaded videos or playlists. Upload a recording, add your YouTube stream key, and go live. Your computer and home connection do not need to stay on. The uploaded video streams as made, up to 4K 60fps, at one flat price per slot; StreamNeo automatically recovers if YouTube drops the stream.

The first day is free with no card. Monthly billing is $9.99 per month. StreamNeo streams to YouTube and plays uploaded videos; it is not a camera-based live input service. Learn more at StreamNeo, or start your free first day.

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.