Skip to content

Conversation

Copy link

Copilot AI commented Jul 8, 2025

This PR implements enhanced video thumbnail generation to address the issue of poor thumbnail quality caused by capturing frames from the beginning or end of videos, which often results in black screens, credits, or unrepresentative content.

🎯 Key Features Implemented

1. Midpoint Thumbnail Capture

  • Thumbnails now capture from 50% of video duration by default instead of the end
  • Eliminates black screens, end credits, and intro sequences from thumbnails
  • Provides significantly more representative video previews

2. User-Configurable Thumbnail Position

  • New thumb_position user setting allows users to specify 1-99% of video duration
  • Examples: 25% (early scene), 50% (midpoint), 75% (later content)
  • Accessible via user settings interface or direct command: /cmd -s thumb_position
  • Robust validation with automatic fallback to 50% for invalid inputs

3. Informative Metadata Overlay

  • Professional semi-transparent overlay automatically added to all video thumbnails
  • Displays essential video information:
    • File size (human-readable format: 1.5 GB)
    • Resolution (e.g., 1920x1080)
    • Bitrate (e.g., 2500k)
    • Frame rate (e.g., 30fps)
  • Helps users distinguish video quality at a glance

4. Seamless Integration

  • Integrated into existing user settings interface
  • Added to leech settings panel with visual indicators
  • Updated theme template to display current thumbnail position
  • Full input validation and error handling

🔧 Technical Implementation

Enhanced take_ss() Function

async def take_ss(video_file, duration=None, total=1, gen_ss=False, user_id=None, position_percent=None):
    # Get user's preferred position or default to 50%
    if position_percent is None and user_id is not None:
        user_dict = user_data.get(user_id, {})
        position_percent = int(user_dict.get("thumb_position", "50"))
    elif position_percent is None:
        position_percent = 50  # Default to midpoint
    
    # Calculate timestamp: 50% = midpoint, 25% = early, 75% = later
    timestamp = duration_with_buffer * (position_percent / 100)
    
    # Add metadata overlay after thumbnail generation
    if video_metadata:
        await add_metadata_overlay(thumb_path, video_metadata)

Metadata Extraction & Overlay

async def get_video_metadata(path):
    # Extract comprehensive video metadata using ffprobe
    # Returns file_size, resolution, bitrate, fps, etc.

async def add_metadata_overlay(image_path, metadata):
    # Create professional overlay with video information
    # Semi-transparent background with centered text

📱 User Experience

Before:

  • Thumbnails often showed black screens or credits
  • No information about video quality
  • Fixed capture position (usually end of video)

After:

  • Representative thumbnails from video midpoint
  • Rich metadata overlay showing video specs
  • User-configurable capture position
  • Better video quality distinction

🔄 Backward Compatibility

Fully backward compatible - all existing code continues to work unchanged

  • New parameters are optional with sensible defaults
  • Existing take_ss() calls work without modification
  • Screenshot galleries (get_ss()) maintain even distribution behavior

🧪 Testing

Comprehensive testing included:

  • ✅ Thumbnail position calculation accuracy
  • ✅ User setting validation (handles edge cases)
  • ✅ Metadata overlay generation and formatting
  • ✅ Backward compatibility verification
  • ✅ Code compilation and integration testing

📁 Files Modified

  • bot/helper/ext_utils/leech_utils.py - Core thumbnail generation with metadata overlay
  • bot/modules/users_settings.py - User settings interface and validation
  • bot/helper/themes/wzml_minimal.py - Theme template updates
  • bot/helper/mirror_utils/upload_utils/pyrogramEngine.py - Integration points

🎬 Example Usage

Users can now:

  1. Set thumbnail position: /cmd -s thumb_position → reply with 25 for early scene capture
  2. View enhanced thumbnails with metadata overlay automatically
  3. Enjoy representative thumbnails instead of black screens or credits

This enhancement significantly improves the video thumbnail experience while maintaining full compatibility with existing functionality.

Fixes #375.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 8, 2025

🧙 Sourcery is reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@rjriajul rjriajul closed this Jul 8, 2025
Copilot AI changed the title [WIP] Enhance Video Thumbnails: Midpoint Capture & Informative Metadata Overlay Enhance Video Thumbnails: Midpoint Capture & Informative Metadata Overlay Jul 8, 2025
Copilot AI requested a review from rjriajul July 8, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance Video Thumbnails: Midpoint Capture & Informative Metadata Overlay

2 participants