|
| 1 | +# Video Converter |
| 2 | + |
| 3 | +A Ruby gem for converting video files using FFmpeg. This project is designed to work as a Raycast script and automatically converts videos from an `input` directory to an `output` directory. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Automatically converts video files using FFmpeg |
| 8 | +- Scales videos to 1920px width while maintaining aspect ratio |
| 9 | +- Only converts files created today (skips older files) |
| 10 | +- Skips files that have already been converted |
| 11 | +- Supports both Raycast script and standalone Ruby execution |
| 12 | +- Uses high-quality encoding settings (CRF 18, slow preset) |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +- Ruby 2.6.0 or higher |
| 17 | +- FFmpeg installed on your system |
| 18 | +- Bundler gem |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +1. Clone or download this project |
| 23 | +2. Navigate to the project directory: |
| 24 | + ```bash |
| 25 | + cd commands/video-converter |
| 26 | + ``` |
| 27 | + |
| 28 | +3. Install dependencies: |
| 29 | + ```bash |
| 30 | + bundle install |
| 31 | + ``` |
| 32 | + |
| 33 | +4. Ensure FFmpeg is installed: |
| 34 | + ```bash |
| 35 | + # On macOS with Homebrew |
| 36 | + brew install ffmpeg |
| 37 | + |
| 38 | + # On Ubuntu/Debian |
| 39 | + sudo apt update && sudo apt install ffmpeg |
| 40 | + |
| 41 | + # On Windows |
| 42 | + # Download from https://ffmpeg.org/download.html |
| 43 | + ``` |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +### As a Raycast Script |
| 48 | + |
| 49 | +1. Place video files in the `input/` directory |
| 50 | +2. Run the Raycast command: `video:convert` |
| 51 | +3. Converted videos will appear in the `output/` directory |
| 52 | + |
| 53 | +### As a Standalone Ruby Script |
| 54 | + |
| 55 | +1. Place video files in the `input/` directory |
| 56 | +2. Run the converter: |
| 57 | + ```bash |
| 58 | + ruby convertio.rb |
| 59 | + # or |
| 60 | + ruby plg.rb |
| 61 | + ``` |
| 62 | + |
| 63 | +### Programmatic Usage |
| 64 | + |
| 65 | +```ruby |
| 66 | +require_relative "lib/video_convert" |
| 67 | + |
| 68 | +converter = VideoConvert::Converter.new("./input", "./output") |
| 69 | +converter.convert_all |
| 70 | +``` |
| 71 | + |
| 72 | +## Configuration |
| 73 | + |
| 74 | +The converter uses the following FFmpeg parameters: |
| 75 | +- **Scale**: 1920px width, height auto-calculated to maintain aspect ratio |
| 76 | +- **Preset**: slow (for better compression) |
| 77 | +- **CRF**: 18 (high quality) |
| 78 | +- **Log Level**: error (minimal output) |
| 79 | + |
| 80 | +## Development |
| 81 | + |
| 82 | +### Running Tests |
| 83 | + |
| 84 | +```bash |
| 85 | +# Run all tests |
| 86 | +bundle exec rake test |
| 87 | + |
| 88 | +# Run specific test file |
| 89 | +bundle exec ruby spec/utils_spec.rb |
| 90 | +``` |
| 91 | + |
| 92 | +### Code Quality |
| 93 | + |
| 94 | +```bash |
| 95 | +# Run RuboCop linting |
| 96 | +bundle exec rake rubocop |
| 97 | + |
| 98 | +# Run both tests and linting |
| 99 | +bundle exec rake |
| 100 | +``` |
| 101 | + |
| 102 | +### Development Dependencies |
| 103 | + |
| 104 | +- **Guard**: File watching for automatic test running |
| 105 | +- **Minitest**: Testing framework |
| 106 | +- **RuboCop**: Code style and quality checker |
| 107 | +- **Rake**: Task runner |
| 108 | + |
| 109 | +## How It Works |
| 110 | + |
| 111 | +1. **File Discovery**: Scans the `input/` directory for video files |
| 112 | +2. **Filtering**: Only processes files that: |
| 113 | + - Were created today |
| 114 | + - Haven't been converted yet (not in `output/` directory) |
| 115 | + - Are actual files (not directories) |
| 116 | +3. **Conversion**: Uses FFmpeg to convert each file with optimized settings |
| 117 | +4. **Async Processing**: Each conversion runs in a separate process |
| 118 | + |
| 119 | +## Requirements |
| 120 | + |
| 121 | +- Ruby 2.6.0+ |
| 122 | +- FFmpeg |
| 123 | +- Input videos in supported formats (MP4, MOV, AVI, etc.) |
| 124 | + |
| 125 | +## License |
| 126 | + |
| 127 | +MIT License - see LICENSE file for details |
| 128 | + |
| 129 | +## Contributing |
| 130 | + |
| 131 | +1. Fork the repository |
| 132 | +2. Create a feature branch |
| 133 | +3. Make your changes |
| 134 | +4. Add tests for new functionality |
| 135 | +5. Ensure all tests pass and code follows style guidelines |
| 136 | +6. Submit a pull request |
| 137 | + |
| 138 | +## Troubleshooting |
| 139 | + |
| 140 | +### FFmpeg Not Found |
| 141 | +Make sure FFmpeg is installed and available in your PATH: |
| 142 | +```bash |
| 143 | +ffmpeg -version |
| 144 | +``` |
| 145 | + |
| 146 | +### Permission Issues |
| 147 | +Ensure the script has write permissions to the `output/` directory: |
| 148 | +```bash |
| 149 | +chmod 755 output/ |
| 150 | +``` |
| 151 | + |
| 152 | +### No Files to Convert |
| 153 | +The converter only processes files created today. If you need to convert older files, modify the `created_today?` check in the converter logic. |
0 commit comments