On an existing Ubuntu Compute Engine VM, connect over SSH, run sudo apt update and sudo apt install -y ffmpeg, then confirm the installation with ffmpeg -version. That installs FFmpeg; it does not by itself configure a YouTube stream. For direct streaming, you still need a valid YouTube stream key and an FFmpeg command using compatible video, audio, bitrate, and keyframe settings.
Install FFmpeg on the Ubuntu VM
These steps assume you already have an Ubuntu virtual machine on Google Cloud Compute Engine and can connect to it using SSH. Run the commands in the VM’s shell, not in Cloud Shell: Cloud Shell is a separate environment and is not the persistent VM.
As an Amazon Associate I earn from qualifying purchases.
- Connect to the VM over SSH. Use the SSH option in the Google Cloud console or your existing
gcloudworkflow. Check that the shell prompt belongs to the Ubuntu VM before installing packages. - Refresh the package index:
sudo apt update - Install FFmpeg:
sudo apt install -y ffmpeg - Verify the executable:
ffmpeg -version
Google Cloud’s Live Stream API setup guide also recommends installing FFmpeg with sudo apt install ffmpeg for its encoder workflow: Google Cloud’s Live Stream API setup guidance. The -y option in the command above simply accepts apt’s confirmation prompt.
Recommended Free Tools
Check the version and build on your VM
The version and enabled features depend on the Ubuntu release and package repositories available to that VM. Check the output of ffmpeg -version rather than assuming a particular version or codec is present. FFmpeg notes that its online documentation tracks the newest revision, so it may not exactly match an older distribution package; consult documentation installed with your local package when needed: FFmpeg documentation.
#1 Best Overall
Know which Google Cloud workflow you are using
The Google Cloud page that supplies the apt installation command is for the Google Cloud Live Stream API. That API workflow has its own project setup, API enablement, authentication, IAM, and Cloud Storage requirements. Installing FFmpeg does not complete those steps.
Sending a stream directly from FFmpeg to YouTube is a separate workflow. You do not need to enable the Google Cloud Live Stream API just to install FFmpeg or send a compatible stream to YouTube. For direct YouTube delivery, use YouTube’s current encoder guidance and the stream URL and key provided by YouTube Studio.
Rank #2
Prepare YouTube Live before building a command
- Set up the live stream in YouTube Studio. Obtain the current server URL and stream key from YouTube’s live-stream setup. Do not publish the key or paste a real key into a shared command, script, or support message; it is a credential that lets someone send video to your stream.
- Choose an output mode supported by your source and FFmpeg build. YouTube’s encoder guidance lists H.264, H.265/HEVC, and AV1 video, and AAC or MP3 audio for the documented workflows. What you can encode depends on the FFmpeg build installed on the VM.
- Choose resolution, frame rate, and bitrate together. YouTube’s recommended H.264 settings include 14 Mbps for 1080p at 30 fps and 8 Mbps for 720p at 30 fps. These are recommendations for those specific modes, not universal bitrates; consult YouTube’s full, current settings table for other codecs, resolutions, and frame rates.
- Set constant bitrate and keyframes. YouTube lists CBR and recommends a two-second keyframe interval, with an interval no longer than four seconds.
- Prefer RTMPS when compatible. YouTube lists RTMP and RTMPS and recommends RTMPS, which encrypts the stream in transit to Google’s servers.
- Check upstream capacity and test. Run a speed test on the VM’s actual upload path and leave headroom rather than choosing an encoder bitrate at the connection’s limit. Send representative moving video and audio before relying on the stream, then monitor YouTube’s stream health. See YouTube’s encoder settings, bitrate, and resolution guidance.
Build the FFmpeg command for your media
There is no single safe, complete command for every input: the input type, desired output mode, installed encoders, and YouTube server URL all matter. Start with the source file and the settings selected above. For a file-based input, the command has this general shape:
ffmpeg -re -i "input.mp4" -c:v libx264 -b:v 8M -maxrate 8M -bufsize 16M -r 30 -g 60 -keyint_min 60 -sc_threshold 0 -c:a aac -b:a 128k -ar 44100 -f flv "rtmps://YOUR_YOUTUBE_INGEST_URL/YOUR_STREAM_KEY"
Rank #3
This is an illustrative H.264, 720p-at-30-fps-style starting point, not a guaranteed fit for every source or current ingest URL. The video bitrate shown corresponds to YouTube’s recommendation for H.264 at 720p/30 fps; the example’s other encoder values are command choices, not a claim that YouTube requires those exact audio settings or buffers. Adjust the output resolution explicitly if the input does not already match your target, and confirm the installed FFmpeg build has the encoder you select. Replace the URL and key with the current values from YouTube Studio. Keep the key private; avoid saving it in shell history or in a script with broad access.
For a different target mode, change the frame rate, keyframe interval, resolution, and bitrate as a set. A two-second keyframe interval corresponds to a GOP of 60 frames at 30 fps or 120 frames at 60 fps. Use YouTube’s current table for the target codec and mode, and ensure the VM can encode at that rate without falling behind.
Rank #4
Common installation and streaming problems
ffmpeg: command not found: Confirm the package installation completed in the VM, not a different shell. Runsudo apt updateandsudo apt install -y ffmpegagain, then open a fresh shell and retryffmpeg -version.- Apt cannot locate the package or cannot reach repositories: Check that the VM has working access to its configured Ubuntu package repositories and that
sudo apt updatecompletes successfully. Package availability can vary by Ubuntu release and configured repositories. - FFmpeg rejects an encoder name: Inspect
ffmpeg -encodersandffmpeg -version. The available encoders depend on the installed package build; select one that is actually present rather than assuming every codec option is enabled. - YouTube does not accept the stream: Recheck the current server URL and stream key in YouTube Studio, the chosen protocol, and the codec settings. Treat the key as a credential and regenerate it in YouTube if it may have been exposed.
- Stream health reports unstable delivery: Compare the chosen bitrate with measured upstream capacity, lower the target mode or bitrate if necessary, and test again. YouTube recommends monitoring stream health rather than relying only on the encoder’s local status.
- The stream connects but playback is wrong or absent: Test with a short, representative source that includes both motion and audio. Check that the selected input, audio stream, output resolution, and frame rate match your intent.
Or let it run in the cloud
If the goal is a 24/7 YouTube channel playing uploaded videos, you can use StreamNeo instead of maintaining an FFmpeg process on the VM. Upload a recording or build a playlist, add your YouTube stream key, and go live; StreamNeo loops the uploaded video from its cloud service, so your computer and home connection do not have to stay on. It does not stream from a camera.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors- Nothing has to stay powered on at home.
- One flat price per slot for any uploaded quality up to 4K 60fps, without re-encoding or quality tiers.
- Automatic recovery if YouTube drops the stream.
- The first day is free with no card; one free day is available per account.
- Monthly: $9.99 per month.
See StreamNeo for details, or start the free first day.
Quick Recap
Best Value
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.




