Simplify video downloads with PowerShell & FFmpeg

Posted on

Cover Image for Simplify video downloads with PowerShell & FFmpeg

In today's digital world, efficiently downloading videos is essential for productivity. Whether you're a content creator, researcher, or media enthusiast, having a streamlined process to download videos can save you time and effort. This guide will show you how to use PowerShell and FFmpeg to download any video URL directly from your clipboard on a Windows machine. The script, written by me, is available on GitHub.

Why Use PowerShell and FFmpeg?

PowerShell is a powerful scripting language developed by Microsoft, designed for system administration and automation in Windows environments. FFmpeg is a versatile multimedia framework capable of handling various multimedia files and streams. Combining these two tools allows us to create a script that downloads videos from URLs saved in your clipboard efficiently.

Requirements

  • FFmpeg
  • PowerShell

Setting Up Your Environment

Step 1: Install PowerShell (if you haven't already)

Most Windows systems come with PowerShell pre-installed. To check if you have it, open your Start menu, type "PowerShell," and hit Enter. If you see the PowerShell prompt, you're good to go. If not, you can download it from the Microsoft Store or the GitHub repository.

Step 2: Install FFmpeg

Install FFmpeg using your preferred package manager:

Chocolatey

choco install ffmpeg

winget

winget install --id=Gyan.FFmpeg -e

How to Use the Script

  1. Download the Script: Get the script from my GitHub repository.
  2. Save the Script: Save the video-downloader.ps1 file to your preferred location.
  3. Run the Script: Open PowerShell with administrative privileges and navigate to the directory where you saved the script. Run the script using:
.\video-downloader.ps1

The script will check if your clipboard contains a URL and, if so, download the video to the default directory %USERPROFILE%\Downloads in mp4 format.

Script Overview

Here's the core of the video-downloader.ps1 script:

# Check if clipboard contains a URL
$clipboardContent = Get-Clipboard
if ($clipboardContent -match "^https?://") {
    $videoUrl = $clipboardContent
    Write-Output "URL found in clipboard: $videoUrl"

    # Define the output directory and file name
    $outputDirectory = "$env:USERPROFILE\Downloads"
    $fileName = "downloaded_video.mp4"
    $outputPath = Join-Path -Path $outputDirectory -ChildPath $fileName

    # Ensure the output directory exists
    if (-not (Test-Path -Path $outputDirectory)) {
        New-Item -Path $outputDirectory -ItemType Directory | Out-Null
    }

    # Download the video using FFmpeg
    $ffmpegPath = "C:\ffmpeg\bin\ffmpeg.exe"
    $ffmpegCommand = "& `"$ffmpegPath`" -i `"$videoUrl`" -c copy `"$outputPath`""
    Invoke-Expression $ffmpegCommand

    Write-Output "Video downloaded to $outputPath"
} else {
    Write-Output "No URL found in clipboard."
}

This script checks your clipboard for a URL, defines the output directory and file name, ensures the output directory exists, and uses FFmpeg to download the video.

Conclusion

Using PowerShell and FFmpeg to download videos from URLs stored in your clipboard can significantly enhance your productivity. This guide has provided you with the steps to set up your environment, run the script, and customize it to fit your needs. The script is available on GitHub for easy access and modification.

By following these instructions, you can streamline your video download process and ensure you never miss out on essential content. Experiment with the script, customize it to fit your needs, and enjoy the enhanced efficiency that comes with automating your video downloads.