Skip to content

Add FFmpeg agentic workflow with setup guide and example#1931

Merged
pelikhan merged 12 commits intomainfrom
copilot/add-ffmpeg-installation-guide
Oct 18, 2025
Merged

Add FFmpeg agentic workflow with setup guide and example#1931
pelikhan merged 12 commits intomainfrom
copilot/add-ffmpeg-installation-guide

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 18, 2025

This PR adds comprehensive FFmpeg support for GitHub Agentic Workflows, including installation guides, best practices, and an example workflow extracted from the GenAIScript ffmpeg implementation.

📁 Files Added

1. Shared Configuration: ffmpeg.md

A focused 162-line guide providing:

  • Automatic installation: FFmpeg setup step in frontmatter that runs before workflows
  • Version tracking: Step output captures FFmpeg version for reference in workflows
  • Cache folder: Automatic creation of /tmp/gh-aw/ffmpeg for caching intermediate results
  • Timeout documentation: Documented 5-minute timeout for bash/ffmpeg operations with guidance on setting adequate workflow timeouts
  • Stable hash computation: Guide for creating SHA-256 hashes to identify unique ffmpeg operations for efficient caching
  • Bash tools: Pre-configured ffmpeg and ffprobe commands
  • Common operations reference: Audio extraction (MP3, Opus for transcription), keyframe extraction, scene detection, video conversion
  • Transcription optimization: Added libopus codec for speech-to-text audio extraction
  • Streamlined command examples with essential flag explanations

2. Video Analyzer Workflow: video-analyzer.md

A streamlined video analysis workflow that performs focused analysis including:

  • Scene detection with configurable thresholds (0.3-0.5 range)
  • Audio extraction in MP3 format at 192k bitrate
  • Automated reporting via GitHub issue creation with detailed results

The workflow has been simplified to always perform full analysis (scenes + audio) without requiring users to choose between different analysis modes.

Usage:

gh workflow run video-analyzer.md \
  --field video_url="https://example.com/video.mp4"

🎯 Key Features from GenAIScript

Extracted and documented best practices from the GenAIScript implementation:

Scene Detection:

  • Threshold-based detection: select='gt(scene,threshold)'
  • Sensitivity range: 0.1 (very sensitive) to 0.6 (major changes only)
  • showinfo filter for timestamp logging

Audio Extraction:

  • MP3 with high quality: libmp3lame codec at 192k bitrate
  • Transcription optimization: libopus codec with mono channel, 12k bitrate, and voip application mode for optimal speech-to-text processing (documented in shared guide)

Automatic Installation:

  • FFmpeg installation step in frontmatter runs automatically before workflow execution
  • Version captured as step output: accessible via ${{ steps.setup-ffmpeg.outputs.version }}
  • Cache folder /tmp/gh-aw/ffmpeg created for storing intermediate results
  • No manual installation required in workflow prompts

Timeout Management:

  • Individual bash commands have a 5-minute timeout
  • Recommended workflow timeout of 15+ minutes for video processing operations
  • Guidance provided for handling longer operations

Caching Strategy:

  • Stable hash computation using SHA-256 of ffmpeg command + input files
  • Enables efficient caching by creating unique identifiers for each operation
  • Avoids reprocessing identical video operations

Bash Tools Configuration:

  • Pre-configured ffmpeg and ffprobe commands in frontmatter
  • Allows agents to execute ffmpeg operations seamlessly

🔧 Usage in Custom Workflows

Import the shared guide in any workflow:

---
on: workflow_dispatch
engine: copilot
imports:
  - shared/ffmpeg.md
timeout_minutes: 15  # Recommended for video processing
---

# Your Custom Video Workflow

FFmpeg and ffprobe are automatically installed via the import.
A cache folder at `/tmp/gh-aw/ffmpeg` is available for intermediate results.
Use stable hashes to cache expensive ffmpeg operations.
Access the FFmpeg version via ${{ steps.setup-ffmpeg.outputs.version }}.

Note: Bash commands have a 5-minute timeout. For longer operations,
break them into smaller steps or increase workflow timeout_minutes.

✅ Validation

  • All workflows compile successfully with strict mode
  • Unit tests pass (make agent-finish)
  • No linting errors
  • Workflows appear correctly in gh aw status
  • Imports work correctly and content is included in compiled lock files
  • FFmpeg installation step automatically included in compiled workflows
  • Version output properly captured in step outputs
  • Cache folder creation verified in compiled workflows
  • Bash tools configuration properly integrated
  • Stable hash guidance included in compiled prompts
  • Timeout documentation included in compiled workflow prompts
Original prompt

Generate an agentic workflow for ffmpeg:

provides steps to install in actions (there is probably a custom action)
prompt to help the agent find ffmpeg
Extract tips and tricks from the implementation of ffmpeg jn genaiscript: https://github.com/microsoft/genaiscript/blob/main/packages/core/src/ffmpeg.ts

best code to extract sound, usage of threshold, etc.


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

@pelikhan pelikhan marked this pull request as ready for review October 18, 2025 06:47
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

github-actions Bot and others added 3 commits October 18, 2025 06:49
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add installation instructions and usage tips for ffmpeg Add FFmpeg agentic workflows with comprehensive setup guide and examples Oct 18, 2025
Copilot AI requested a review from pelikhan October 18, 2025 07:02
Comment thread .github/workflows/FFMPEG_README.txt Outdated
@@ -0,0 +1,170 @@
# FFmpeg Agentic Workflows
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot delete file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Deleted FFMPEG_README.txt file.

@@ -0,0 +1,269 @@
---
# FFmpeg Setup Instructions
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot rename to ffmpeg.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Renamed ffmpeg-setup.md to ffmpeg.md.

Comment on lines +36 to +40
sudo apt-get update && sudo apt-get install -y ffmpeg

# Verify installation
ffmpeg -version
```
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot move as steps in the front matter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Moved bash installation commands to frontmatter steps array. The Setup FFmpeg step now automatically runs before the agent.


# FFmpeg Usage Guide

## Installing FFmpeg
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove section as we are adding steps in the front matter to install ffmpeg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the "Installing FFmpeg" section since installation is now handled by the frontmatter steps.

Comment thread .github/workflows/shared/ffmpeg.md
Comment thread .github/workflows/shared/ffmpeg.md Outdated
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
```

## Best Practices
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remained of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the Best Practices and Error Handling sections to keep the file focused on essential operations. File reduced from 200 to 149 lines.

Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot prompt to use /tmp/gh-aw/ffmpeg/ as cache folder. Updates steps to pre create this folder

Copilot AI and others added 2 commits October 18, 2025 11:49
…atter, add opus for transcription

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Add FFmpeg agentic workflows with comprehensive setup guide and examples Add FFmpeg agentic workflows with setup guide and examples Oct 18, 2025
Copilot AI requested a review from pelikhan October 18, 2025 11:52
Comment thread .github/workflows/shared/ffmpeg.md Outdated
Comment thread .github/workflows/shared/ffmpeg.md Outdated

FFmpeg has been installed and is available in your PATH.

## Finding FFmpeg
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the "Finding FFmpeg" section.

Comment thread .github/workflows/shared/ffmpeg.md Outdated

# FFmpeg Usage Guide

FFmpeg has been installed and is available in your PATH.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add that /tmp/gh-aw/ffmpeg temp folder is available

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added documentation that /tmp/gh-aw/ffmpeg temp folder is available for caching intermediate results.

Comment thread .github/workflows/shared/ffmpeg.md Outdated
Comment on lines +48 to +52
# Extract audio as WAV (uncompressed)
ffmpeg -i input.mp4 -vn -acodec pcm_s16le output.wav

# Extract audio as AAC
ffmpeg -i input.mp4 -vn -acodec aac -ab 128k output.aac
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed WAV and AAC audio extraction examples, keeping only MP3 and Opus (for transcription).

Comment thread .github/workflows/shared/ffmpeg.md Outdated
Comment on lines +144 to +148
## References

- FFmpeg Official Documentation: https://ffmpeg.org/documentation.html
- FFmpeg Wiki: https://trac.ffmpeg.org/wiki
- Opus Codec Documentation: https://opus-codec.org/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the References section.

Comment thread .github/workflows/shared/ffmpeg.md
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 18, 2025

@copilot prompt to use /tmp/gh-aw/ffmpeg/ as cache folder. Updates steps to pre create this folder

Done. Added /tmp/gh-aw/ffmpeg/ cache folder creation in setup steps and documented it in the usage guide prompt.

Copilot AI requested a review from pelikhan October 18, 2025 12:09
Comment thread .github/workflows/shared/ffmpeg.md Outdated

# FFmpeg Usage Guide

FFmpeg has been installed and is available in your PATH. A temporary folder `/tmp/gh-aw/ffmpeg` is available for caching intermediate results.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot "ffmpeg and ffprobe" . Add version step output to specify the version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Updated to say "FFmpeg and ffprobe" and added step output to capture the version.

Comment thread .github/workflows/shared/ffmpeg.md Outdated
- name: Setup FFmpeg
run: |
sudo apt-get update && sudo apt-get install -y ffmpeg
ffmpeg -version
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot store version in a step output

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added step id and version output using $GITHUB_OUTPUT. The version can be accessed via ${{ steps.setup-ffmpeg.outputs.version }}.

Comment thread .github/workflows/shared/ffmpeg.md
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 18, 2025 12:20
Comment thread .github/workflows/audio-extractor.md Outdated
description: 'URL to video file (must be publicly accessible)'
required: true
type: string
audio_format:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove field, extract mp3 only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the audio-extractor workflow entirely as requested in the follow-up comment.

Comment thread .github/workflows/audio-extractor.md Outdated
@@ -0,0 +1,174 @@
---
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove sample

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed audio-extractor.md and audio-extractor.lock.yml.

Comment thread .github/workflows/shared/ffmpeg.md
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Add FFmpeg agentic workflows with setup guide and examples Add FFmpeg agentic workflow with setup guide and example Oct 18, 2025
Copilot AI requested a review from pelikhan October 18, 2025 12:27
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Comment thread .github/workflows/video-analyzer.md Outdated
description: 'URL to video file to analyze (must be publicly accessible)'
required: true
type: string
analysis_type:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot only support full analysis

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed analysis_type input field. Workflow now always performs full analysis including keyframes, scenes, and audio.

Comment thread .github/workflows/video-analyzer.md Outdated
Comment on lines +193 to +223
## Important Notes

### Performance Considerations
- Process operations sequentially to avoid memory issues
- Clean up intermediate files to save disk space
- Monitor GitHub Actions runner resources
- Consider file size limits for uploads/artifacts

### Error Handling
- Verify video download succeeded before processing
- Check ffmpeg commands return success (exit code 0)
- Validate output files exist and are not empty
- Report any errors clearly in the issue

### Best Practices from GenAIScript Implementation
1. **Caching**: Store results to avoid reprocessing
2. **Concurrency**: Process one video at a time
3. **Formats**: Use JPG for frames (good quality/size balance)
4. **Thresholds**: Scene detection works best at 0.3-0.5
5. **Quality**: Use CRF 23 for good balance of quality/size
6. **Timestamps**: Be precise with timestamp-based extraction
7. **Size control**: Always specify output dimensions when needed

### Security Considerations
- Only process videos from trusted sources
- Validate input URLs before downloading
- Set reasonable timeout limits
- Monitor disk space usage
- Clean up temporary files after processing

Good luck with your video analysis!
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the "Important Notes" section including Performance Considerations, Error Handling, Best Practices, and Security Considerations.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 18, 2025 12:48
Comment thread .github/workflows/video-analyzer.md Outdated
Comment on lines +65 to +72
#### Keyframe Analysis:
1. Extract all keyframes from the video:
```bash
ffmpeg -i video.mp4 -vf "select='eq(pict_type,I)'" -fps_mode vfr -frame_pts 1 keyframe_%06d.jpg
```
2. Count the number of keyframes extracted
3. Report keyframe distribution (approximately every N seconds)
4. List the first 10 keyframe filenames with their timestamps
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the Keyframe Analysis section including I-frame extraction instructions.

Comment thread .github/workflows/video-analyzer.md Outdated
Comment on lines +95 to +99
# High quality MP3
ffmpeg -i video.mp4 -vn -acodec libmp3lame -ab 192k audio.mp3

# Uncompressed WAV
ffmpeg -i video.mp4 -vn -acodec pcm_s16le audio.wav
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Only mp3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Simplified audio extraction to MP3 only, removed WAV format.

Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply comments

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan merged commit 58cfa23 into main Oct 18, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/add-ffmpeg-installation-guide branch October 18, 2025 12:57
Copilot AI requested a review from pelikhan October 18, 2025 12:57
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.

2 participants