मुख्य सामग्री पर जाएँ
Skillpedia
वीडियो एडिटिंग7.8k · #12887

ffmpeg-graceful-degradation

यह क्या करती है

यह स्किल FFmpeg से वीडियो एन्कोडिंग की फ़ॉलबैक योजना बताती है, एन्कोडर जाँचने से लेकर दूसरे विकल्पों तक। यह उन लोगों के लिए है जो कई वीडियो प्रोसेस करते हैं और एन्कोडिंग एरर से पूरा बैच रुक जाता है।

कब इस्तेमाल करें

  • ✓जब कोडेक या लाइब्रेरी एरर की वजह से FFmpeg एन्कोडिंग विफल हो।
  • ✓जब मुझे वीडियो का बैच प्रोसेस करना है और पूरा बैच विफल नहीं होना चाहिए।
  • ✓जब मैं चाहता हूँ कि पूरा काम शुरू होने से पहले एक छोटा टेस्ट क्लिप जाँचा जाए।

Skill का लिंक

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/ffmpeg-graceful-degradation/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/ffmpeg-graceful-degradation/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“FFmpeg एन्कोड क्लिपों के बैच पर बार-बार विफल हो रहा है। कृपया पहले एक छोटी क्लिप परखिए और ऐसा तरीका खोजिए जो पूरा हो जाए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

AI उपलब्ध एन्कोडर जाँचता है, एक छोटा परीक्षण चलाता है, और फिर फ़ॉलबैक की सूची में नीचे जाता है: स्ट्रीम कॉपी से दूसरे कोडेक और अंत में moviepy तक, फिर बैच प्रोसेस करता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

FFmpeg Graceful Degradation

When processing videos with ffmpeg, encoding failures are common due to codec availability, library version mismatches, or system configuration issues. This skill provides a systematic fallback strategy to ensure video processing completes successfully.

Overview

The pattern involves: (1) probing encoder availability upfront, (2) testing on a short clip before batch processing, (3) progressive fallback through copy mode, alternative codecs, and finally moviepy, (4) using moviepy as a reliable bundled alternative.

Step 1: Probe Encoder Availability

Before any encoding work, check what encoders are available:

ffmpeg -encoders | grep -E "libx264|libopenh264|mpeg4"

Expected output shows which encoders are present:

  • libx264 - Preferred H.264 encoder (may be missing)
  • libopenh264 - Alternative H.264 (often has library issues)
  • mpeg4 - Universal fallback (always available)

Step 2: Test Encoding on Single Short Clip

Never start batch processing without validation. Extract and test a short segment:

# Extract 5-second test clip
ffmpeg -y -i input.mp4 -ss 0 -t 5 -c copy test_clip.mp4

# Attempt encode with preferred codec
ffmpeg -y -i test_clip.mp4 -c:v libx264 -preset fast test_output.mp4

Check the exit code and output for errors. Common failures:

  • libopenh264.so: wrong ELF class
  • Encoder libx264 not found
  • Library version mismatches

Step 3: Progressive Fallback Strategy

If the preferred encoder fails, try these fallbacks in order:

Fallback A: Copy Mode (No Re-encoding)

ffmpeg -y -i input.mp4 -c:v copy -c:a copy output.mp4

Fast, lossless, but doesn't change codec/format.

Fallback B: MPEG4 Codec

ffmpeg -y -i input.mp4 -c:v mpeg4 -q:v 3 -c:a copy output.mp4

Universal compatibility, larger file sizes, always available.

Fallback C: Install MoviePy (Bundles Working FFmpeg)

pip install moviepy

Then use Python instead of raw ffmpeg:

from moviepy.editor import VideoFileClip, concatenate_videoclips

# Single clip processing
clip = VideoFileClip("input.mp4")
clip.write_videofile("output.mp4", codec="libx264")

# Concatenate multiple clips
clips = [VideoFileClip(f) for f in clip_files]
final = concatenate_videoclips(clips)
final.write_videofile("output.mp4", codec="libx264")

MoviePy bundles its own ffmpeg binary, avoiding system library issues.

Step 4: Implementation Pattern

Here's a complete graceful degradation workflow:

import subprocess
import os

def safe_video_encode(input_path, output_path, clips=None):
    """
    Encode video with graceful degradation fallbacks.
    
    Args:
        input_path: Single input file path, or
        clips: List of clip paths for concatenation
    
    Returns:
        True if successful, False otherwise
    """
    
    # Step 1: Check encoder availability
    result = subprocess.run(
        ["ffmpeg", "-encoders"],
        capture_output=True, text=True
    )
    has_libx264 = "libx264" in result.stdout
    has_mpeg4 = "mpeg4" in result.stdout
    
    # Step 2: If concatenating, prepare clips with moviepy
    if clips:
        try:
            from moviepy.editor import VideoFileClip, concatenate_videoclips
            loaded_clips = [VideoFileClip(c) for c in clips]
            final = concatenate_videoclips(loaded_clips)
            final.write_videofile(output_path, codec="libx264", logger=None)
            return True
        except Exception as e:
            print(f"MoviePy failed: {e}")
    
    # Step 3: Try ffmpeg with progressive fallbacks
    encoders_to_try = []
    if has_libx264:
        encoders_to_try.append("libx264")
    encoders_to_try.append("mpeg4")  # Always available
    
    for codec in encoders_to_try:
        cmd = [
            "ffmpeg", "-y",
            "-i", input_path,
            "-c:v", codec,
            "-c:a", "copy",
            output_path
        ]
        result = subprocess.run(cmd, capture_output=True, text=True)
        if result.returncode == 0:
            return True
    
    # Step 4: Last resort - copy mode
    cmd = ["ffmpeg", "-y", "-i", input_path, "-c", "copy", output_path]
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.returncode == 0

Decision Flow

Start
  │
  ▼
Check encoders (ffmpeg -encoders)
  │
  ├─ libx264 available? ──Yes──► Try libx264
  │         │                       │
  │         No                      └─►
अक्सर पूछे जाने वाले सवाल

moviepy क्या है?

यह वीडियो एडिट करने की Python लाइब्रेरी है, जिसे गाइड एक वैकल्पिक विकल्प के रूप में इस्तेमाल करती है।

एक ही क्लिप पहले क्यों परखें?

छोटा परीक्षण पूरा बैच प्रोसेस करने से पहले कोडेक की समस्याएँ पकड़ लेता है।

कौन सी एरर आम हैं?

गाइड libopenh264 में गलत ELF क्लास और एन्कोडर न मिलने जैसी एरर गिनाती है।

जानकारी

लेखक का मूल विवरण

Graceful degradation workflow for ffmpeg encoding failures with progressive fallback strategies

repo: HKUDS/AgentPilot

लोकप्रियता

GitHub स्टार
7.8k
रैंकिंग में स्थान
#12887
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills