Skip to main content

A fast YouTube video clip downloader with timestamp support

Project description

ytclip

A fast and efficient YouTube video clip downloader that extracts specific time segments without downloading entire videos.

Features

  • = Stream-based clipping - Downloads only the specified segment, not the entire video
  •  Timestamp support - Specify exact start and end times
  • Speed adjustment - Change playback speed (0.5x to 4x)
  • < QuickTime compatible - Outputs H.264/AAC MP4 files
  • = Minimal dependencies - Just needs yt-dlp and ffmpeg

Installation

Prerequisites

You need to have ffmpeg installed on your system:

macOS:

brew install ffmpeg

Ubuntu/Debian:

sudo apt update
sudo apt install ffmpeg

Windows: Download from ffmpeg.org and add to PATH

Install via pip

pip install ytclip

Install from source

git clone https://github.com/yourusername/ytclip.git
cd ytclip
pip install -e .

Usage

Basic Usage

Download a clip from a YouTube video:

ytclip "https://youtu.be/VIDEO_ID" START_TIME END_TIME

Examples

Extract clip from 1:30 to 2:45:

ytclip "https://youtu.be/dQw4w9WgXcQ" 1:30 2:45

Extract with custom output filename:

ytclip "https://youtu.be/dQw4w9WgXcQ" 1:30 2:45 -o my_clip.mp4

Extract at 1.5x speed:

ytclip "https://youtu.be/dQw4w9WgXcQ" 1:30 2:45 --speed 1.5

Extract from timestamp in HH:MM:SS format:

ytclip "https://youtu.be/dQw4w9WgXcQ" 1:23:45 1:24:30

Command Line Options

positional arguments:
  url                   YouTube video URL
  start                 Start time (MM:SS or HH:MM:SS)
  end                   End time (MM:SS or HH:MM:SS)

optional arguments:
  -h, --help            Show help message and exit
  -o OUTPUT, --output OUTPUT
                        Output filename (default: auto-generated)
  -s SPEED, --speed SPEED
                        Playback speed (e.g., 1.5 for 1.5x speed, 0.5 for half speed)
                        Range: 0.25 to 4.0 (default: 1.0)

How It Works

Unlike traditional YouTube downloaders that fetch entire videos, ytclip uses ffmpeg's seeking capability to stream only the required segment. This means:

  •  Faster downloads - Only downloads what you need
  •  Less bandwidth - Saves data by not downloading unnecessary content
  •  Less storage - No temporary full-video files

The tool:

  1. Extracts video metadata using yt-dlp
  2. Calculates the exact byte range needed
  3. Uses ffmpeg to stream and transcode only that segment
  4. Outputs a properly formatted MP4 file

Output Format

All clips are encoded as:

  • Video: H.264 (libx264) with yuv420p pixel format
  • Audio: AAC
  • Container: MP4 with faststart flag (optimized for streaming)

This ensures compatibility with all modern video players including:

  • QuickTime Player
  • VLC
  • Windows Media Player
  • Web browsers
  • Mobile devices

Speed Adjustment

The speed option maintains pitch correction for natural-sounding audio:

  • 0.25x - 0.5x: Slow motion with preserved audio pitch
  • 0.5x - 2.0x: Standard speed adjustment
  • 2.0x - 4.0x: Fast playback with intelligible audio

Note: Extreme speed changes may affect video quality.

Troubleshooting

"ffmpeg not found" error

Make sure ffmpeg is installed and in your system PATH:

ffmpeg -version

"Video unavailable" error

  • Check if the video is public and not geo-restricted
  • Try updating yt-dlp: pip install --upgrade yt-dlp

QuickTime compatibility issues

The tool automatically encodes to H.264/AAC which should work in QuickTime. If you still have issues, try:

ytclip "URL" START END -o clip.mp4

Development

Running from source

python -m ytclip.cli "URL" START END

Running tests

python -m pytest tests/

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Credits

Built with:

  • yt-dlp - YouTube video extractor
  • FFmpeg - Video processing

Changelog

v1.0.0 (2024-01-09)

  • Initial release
  • Stream-based clip extraction
  • Speed adjustment support
  • QuickTime compatible output

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

youtube_clippy-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

youtube_clippy-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file youtube_clippy-1.0.0.tar.gz.

File metadata

  • Download URL: youtube_clippy-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for youtube_clippy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 71de67d8707f40f05a9f764a52989fadd8ba1c23f47277d7a4e7ae4745899542
MD5 198171ebcf8f18a1054696d6461b99b0
BLAKE2b-256 7a437c5c238ce131d345261100e5d32be03f326bf26d66f1361c904703e5dced

See more details on using hashes here.

File details

Details for the file youtube_clippy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: youtube_clippy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for youtube_clippy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 373055be99b7863c1862e4d86ed059aeaedcd75a0080a25f22a158b2d32e67fd
MD5 8f5860ffc2b7a68e99865448181c346e
BLAKE2b-256 dec6f13e5656d4719bbaac072812aab71e4c936b1e9d969f70476811f41f8235

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page