Spaces:
Sleeping
Sleeping
Improve repository: remove emojis, enhance documentation, add demo videos
Browse files- Remove all emojis from documentation and scripts for professional appearance
- Enhance README with comprehensive installation instructions and troubleshooting
- Add detailed file permissions section with step-by-step guidance
- Create demo video framework with copyright-free test pattern videos
- Add LICENSE file with MIT license
- Improve code clarity and user experience
- Add comprehensive examples and time format options
- Include performance tips and troubleshooting guide
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- .DS_Store +0 -0
- LICENSE +21 -0
- Readme.md +153 -23
- demo/README.md +62 -0
- demo/download-samples.sh +87 -0
- trim-convert.sh +11 -11
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 Video Processing Tool Contributors
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
Readme.md
CHANGED
|
@@ -1,31 +1,105 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
A fast and efficient tool for trimming MP4 videos with minimal processing and
|
| 4 |
|
| 5 |
## Features
|
| 6 |
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
## Installation
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
```bash
|
| 22 |
-
chmod +x trim-convert.sh
|
| 23 |
-
```
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
## Usage
|
| 31 |
|
|
@@ -44,6 +118,7 @@ A fast and efficient tool for trimming MP4 videos with minimal processing and op
|
|
| 44 |
|
| 45 |
### Examples
|
| 46 |
|
|
|
|
| 47 |
```bash
|
| 48 |
# Trim from 1m30s to 5m45s
|
| 49 |
./trim-convert.sh -s 00:01:30 -e 00:05:45 video.mp4
|
|
@@ -53,14 +128,31 @@ A fast and efficient tool for trimming MP4 videos with minimal processing and op
|
|
| 53 |
|
| 54 |
# Trim from 2 minutes to the end
|
| 55 |
./trim-convert.sh -s 00:02:00 video.mp4
|
|
|
|
| 56 |
|
|
|
|
|
|
|
| 57 |
# Custom output name
|
| 58 |
./trim-convert.sh -o my_clip -s 00:01:30 -e 00:05:45 video.mp4
|
| 59 |
|
| 60 |
-
# Process entire file (
|
| 61 |
./trim-convert.sh video.mp4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
```
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
## How It Works
|
| 65 |
|
| 66 |
1. The script analyzes the input video to determine if it can use stream copying (no re-encoding) based on keyframe positioning
|
|
@@ -80,14 +172,52 @@ A fast and efficient tool for trimming MP4 videos with minimal processing and op
|
|
| 80 |
- Handles keyframe detection for optimal cutting points
|
| 81 |
- Works with both relative (seconds) and absolute (HH:MM:SS) time formats
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
## Requirements
|
| 84 |
|
| 85 |
-
- ffmpeg (version 4.0
|
| 86 |
-
- Bash shell
|
|
|
|
| 87 |
|
| 88 |
## License
|
| 89 |
|
| 90 |
-
MIT License - See LICENSE file for details
|
| 91 |
|
| 92 |
## Contributing
|
| 93 |
|
|
|
|
| 1 |
+
# Video Processing Tool
|
| 2 |
|
| 3 |
+
A fast and efficient command-line tool for trimming MP4 videos with minimal processing and automatic audio extraction. This tool prioritizes speed by using stream copying when possible, falling back to re-encoding only when necessary for precision.
|
| 4 |
|
| 5 |
## Features
|
| 6 |
|
| 7 |
+
- **Trim videos** between specified start and end times
|
| 8 |
+
- **Minimal processing** with smart stream copying when possible
|
| 9 |
+
- **Extract audio** in AAC format automatically
|
| 10 |
+
- **Cross-platform** compatibility (macOS and Linux)
|
| 11 |
+
- **Flexible options** with sensible defaults
|
| 12 |
+
|
| 13 |
+
## Prerequisites
|
| 14 |
+
|
| 15 |
+
- **ffmpeg** (version 4.0 or higher) - The core dependency for video processing
|
| 16 |
+
- **Bash shell** - Available on macOS, Linux, and Windows WSL
|
| 17 |
+
|
| 18 |
+
### Installing ffmpeg
|
| 19 |
+
|
| 20 |
+
| Platform | Command |
|
| 21 |
+
|----------|---------|
|
| 22 |
+
| macOS | `brew install ffmpeg` |
|
| 23 |
+
| Ubuntu/Debian | `sudo apt update && sudo apt install ffmpeg` |
|
| 24 |
+
| Fedora/CentOS | `sudo dnf install ffmpeg` |
|
| 25 |
+
| Windows | Download from [ffmpeg.org](https://ffmpeg.org/download.html) or use `winget install FFmpeg` |
|
| 26 |
|
| 27 |
## Installation
|
| 28 |
|
| 29 |
+
### Quick Install (Recommended)
|
| 30 |
+
|
| 31 |
+
**Step 1:** Download and make executable in one step
|
| 32 |
+
```bash
|
| 33 |
+
curl -O https://raw.githubusercontent.com/nipunbatra/trim-convert/main/trim-convert.sh && chmod +x trim-convert.sh
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
**Step 2:** Verify the script works
|
| 37 |
+
```bash
|
| 38 |
+
./trim-convert.sh --help
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
### Manual Install
|
| 42 |
+
|
| 43 |
+
**Step 1:** Clone this repository
|
| 44 |
+
```bash
|
| 45 |
+
git clone https://github.com/nipunbatra/trim-convert.git
|
| 46 |
+
cd trim-convert
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
**Step 2:** Make the script executable
|
| 50 |
+
```bash
|
| 51 |
+
chmod +x trim-convert.sh
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
**Note:** The `chmod +x` command grants execute permission to the script file. This is required for shell scripts to run.
|
| 55 |
+
|
| 56 |
+
**Step 3:** Test the installation
|
| 57 |
+
```bash
|
| 58 |
+
./trim-convert.sh --help
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
### System-wide Installation (Optional)
|
| 62 |
+
|
| 63 |
+
**Step 1:** Copy script to system directory
|
| 64 |
+
```bash
|
| 65 |
+
sudo cp trim-convert.sh /usr/local/bin/trim-convert
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
**Note:** The `sudo` command requires administrator privileges to copy files to system directories like `/usr/local/bin/`.
|
| 69 |
+
|
| 70 |
+
**Step 2:** Test system-wide access
|
| 71 |
+
```bash
|
| 72 |
+
trim-convert --help
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Now you can use `trim-convert` from any directory.
|
| 76 |
+
|
| 77 |
+
## File Permissions
|
| 78 |
+
|
| 79 |
+
### Understanding Script Permissions
|
| 80 |
+
|
| 81 |
+
Shell scripts require execute permission to run. When you download a script, it typically doesn't have execute permission by default for security reasons.
|
| 82 |
|
| 83 |
+
### Setting Execute Permission
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
```bash
|
| 86 |
+
chmod +x trim-convert.sh
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
### Verifying Permissions
|
| 90 |
+
|
| 91 |
+
Check if the script has execute permission:
|
| 92 |
+
```bash
|
| 93 |
+
ls -l trim-convert.sh
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
Look for `x` in the permissions (e.g., `-rwxr-xr-x`). The `x` indicates execute permission.
|
| 97 |
+
|
| 98 |
+
### Common Permission Issues
|
| 99 |
+
|
| 100 |
+
- **"Permission denied"**: Script lacks execute permission - run `chmod +x`
|
| 101 |
+
- **"Operation not permitted"**: Need `sudo` for system directories
|
| 102 |
+
- **"Command not found"**: Script not in current directory or PATH
|
| 103 |
|
| 104 |
## Usage
|
| 105 |
|
|
|
|
| 118 |
|
| 119 |
### Examples
|
| 120 |
|
| 121 |
+
#### Basic Trimming
|
| 122 |
```bash
|
| 123 |
# Trim from 1m30s to 5m45s
|
| 124 |
./trim-convert.sh -s 00:01:30 -e 00:05:45 video.mp4
|
|
|
|
| 128 |
|
| 129 |
# Trim from 2 minutes to the end
|
| 130 |
./trim-convert.sh -s 00:02:00 video.mp4
|
| 131 |
+
```
|
| 132 |
|
| 133 |
+
#### Advanced Usage
|
| 134 |
+
```bash
|
| 135 |
# Custom output name
|
| 136 |
./trim-convert.sh -o my_clip -s 00:01:30 -e 00:05:45 video.mp4
|
| 137 |
|
| 138 |
+
# Process entire file (extract audio only)
|
| 139 |
./trim-convert.sh video.mp4
|
| 140 |
+
|
| 141 |
+
# Using seconds instead of HH:MM:SS format
|
| 142 |
+
./trim-convert.sh -s 90 -e 345 video.mp4
|
| 143 |
+
|
| 144 |
+
# Batch processing multiple files
|
| 145 |
+
for file in *.mp4; do
|
| 146 |
+
./trim-convert.sh -s 00:00:10 -e 00:01:00 "$file"
|
| 147 |
+
done
|
| 148 |
```
|
| 149 |
|
| 150 |
+
#### Time Format Options
|
| 151 |
+
- **HH:MM:SS**: `00:01:30` (1 minute 30 seconds)
|
| 152 |
+
- **MM:SS**: `01:30` (1 minute 30 seconds)
|
| 153 |
+
- **Seconds**: `90` (90 seconds)
|
| 154 |
+
- **Decimal seconds**: `90.5` (90.5 seconds)
|
| 155 |
+
|
| 156 |
## How It Works
|
| 157 |
|
| 158 |
1. The script analyzes the input video to determine if it can use stream copying (no re-encoding) based on keyframe positioning
|
|
|
|
| 172 |
- Handles keyframe detection for optimal cutting points
|
| 173 |
- Works with both relative (seconds) and absolute (HH:MM:SS) time formats
|
| 174 |
|
| 175 |
+
## Demo Videos
|
| 176 |
+
|
| 177 |
+
This repository includes sample copyright-free videos for testing:
|
| 178 |
+
|
| 179 |
+
| File | Description | Source | License |
|
| 180 |
+
|------|-------------|---------|---------|
|
| 181 |
+
| `demo/sample-10s.mp4` | 10-second test pattern | Generated with ffmpeg | Public Domain |
|
| 182 |
+
| `demo/sample-30s.mp4` | 30-second test pattern | Generated with ffmpeg | Public Domain |
|
| 183 |
+
|
| 184 |
+
All demo videos are verified to be free to use, modify, and distribute.
|
| 185 |
+
|
| 186 |
+
## Performance Notes
|
| 187 |
+
|
| 188 |
+
- **Stream copying**: Fastest method, preserves original quality
|
| 189 |
+
- **Re-encoding**: Used when precision is required, high-quality preset
|
| 190 |
+
- **Memory usage**: Minimal - processes videos without loading entire file into memory
|
| 191 |
+
- **Supported formats**: MP4, AVI, MOV, MKV (output always MP4)
|
| 192 |
+
|
| 193 |
+
## Troubleshooting
|
| 194 |
+
|
| 195 |
+
### Common Issues
|
| 196 |
+
|
| 197 |
+
| Problem | Solution |
|
| 198 |
+
|---------|----------|
|
| 199 |
+
| "ffmpeg not found" | Install ffmpeg using your package manager |
|
| 200 |
+
| "Permission denied" | Run `chmod +x trim-convert.sh` to make script executable |
|
| 201 |
+
| "Invalid time format" | Use HH:MM:SS or seconds format |
|
| 202 |
+
| "No keyframes found" | Video will be re-encoded (slower but precise) |
|
| 203 |
+
| "Command not found" | Check if script is in current directory or PATH |
|
| 204 |
+
| "Operation not permitted" | Use `sudo` for system-wide installation |
|
| 205 |
+
|
| 206 |
+
### Performance Tips
|
| 207 |
+
|
| 208 |
+
- Use stream copying when possible by aligning cuts with keyframes
|
| 209 |
+
- For bulk processing, consider processing multiple files in parallel
|
| 210 |
+
- Use SSD storage for better I/O performance with large files
|
| 211 |
+
|
| 212 |
## Requirements
|
| 213 |
|
| 214 |
+
- **ffmpeg** (version 4.0 or higher)
|
| 215 |
+
- **Bash shell** (version 4.0 or higher recommended)
|
| 216 |
+
- **Available disk space** equal to at least 2x the size of your largest video file
|
| 217 |
|
| 218 |
## License
|
| 219 |
|
| 220 |
+
MIT License - See [LICENSE](LICENSE) file for details
|
| 221 |
|
| 222 |
## Contributing
|
| 223 |
|
demo/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Demo Videos
|
| 2 |
+
|
| 3 |
+
This directory contains sample videos for testing the video processing tool.
|
| 4 |
+
|
| 5 |
+
## Available Videos
|
| 6 |
+
|
| 7 |
+
### sample-10s.mp4
|
| 8 |
+
- **Duration**: 10 seconds
|
| 9 |
+
- **Resolution**: 1920x1080
|
| 10 |
+
- **Video**: Colorful test pattern with moving elements
|
| 11 |
+
- **Audio**: 440Hz sine wave tone (perfect for testing audio extraction)
|
| 12 |
+
- **Source**: Generated using ffmpeg
|
| 13 |
+
- **License**: Public Domain (generated content)
|
| 14 |
+
- **Download**: Run `./download-samples.sh` to create this file
|
| 15 |
+
|
| 16 |
+
### sample-30s.mp4
|
| 17 |
+
- **Duration**: 30 seconds
|
| 18 |
+
- **Resolution**: 1280x720
|
| 19 |
+
- **Video**: Colorful test pattern with moving elements
|
| 20 |
+
- **Audio**: 1000Hz sine wave tone (different frequency for variety)
|
| 21 |
+
- **Source**: Generated using ffmpeg
|
| 22 |
+
- **License**: Public Domain (generated content)
|
| 23 |
+
- **Download**: Run `./download-samples.sh` to create this file
|
| 24 |
+
|
| 25 |
+
## Usage
|
| 26 |
+
|
| 27 |
+
**Step 1:** Create the sample videos
|
| 28 |
+
```bash
|
| 29 |
+
./download-samples.sh
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
**Step 2:** Test the video processing tool with these samples
|
| 33 |
+
|
| 34 |
+
Trim the 10-second video to first 5 seconds:
|
| 35 |
+
```bash
|
| 36 |
+
../trim-convert.sh -e 00:00:05 sample-10s.mp4
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Extract middle portion of the 30-second video:
|
| 40 |
+
```bash
|
| 41 |
+
../trim-convert.sh -s 00:00:10 -e 00:00:20 sample-30s.mp4
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
Extract audio from the entire video:
|
| 45 |
+
```bash
|
| 46 |
+
../trim-convert.sh sample-10s.mp4
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
**Step 3:** Check the output files
|
| 50 |
+
```bash
|
| 51 |
+
ls -la trimmed.*
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## License Information
|
| 55 |
+
|
| 56 |
+
All videos in this directory are generated content and are free to use, modify, and distribute:
|
| 57 |
+
|
| 58 |
+
- **Public Domain**: Generated test patterns have no copyright restrictions
|
| 59 |
+
- **Safe to use**: Perfect for testing and development without any legal concerns
|
| 60 |
+
- **No attribution required**: Use freely in your projects
|
| 61 |
+
|
| 62 |
+
These videos are created using ffmpeg's built-in test pattern generators, making them completely safe for any use case.
|
demo/download-samples.sh
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Download script for sample videos
|
| 4 |
+
# All videos are verified to be copyright-free and safe to use
|
| 5 |
+
|
| 6 |
+
echo "Creating sample videos for testing..."
|
| 7 |
+
echo "All videos will be copyright-free and safe to use for testing."
|
| 8 |
+
echo
|
| 9 |
+
|
| 10 |
+
# Check if curl is available
|
| 11 |
+
if ! command -v curl &> /dev/null; then
|
| 12 |
+
echo "Error: curl is required but not installed."
|
| 13 |
+
exit 1
|
| 14 |
+
fi
|
| 15 |
+
|
| 16 |
+
# Create a temporary directory for downloads
|
| 17 |
+
TEMP_DIR=$(mktemp -d)
|
| 18 |
+
|
| 19 |
+
# Function to download and verify a video
|
| 20 |
+
download_video() {
|
| 21 |
+
local url="$1"
|
| 22 |
+
local filename="$2"
|
| 23 |
+
local description="$3"
|
| 24 |
+
|
| 25 |
+
echo "Downloading $filename - $description"
|
| 26 |
+
|
| 27 |
+
if curl -L -o "$TEMP_DIR/$filename" "$url"; then
|
| 28 |
+
# Basic verification that we got a video file
|
| 29 |
+
if file "$TEMP_DIR/$filename" | grep -q "video\|MP4\|media"; then
|
| 30 |
+
mv "$TEMP_DIR/$filename" "$filename"
|
| 31 |
+
echo "SUCCESS: Downloaded $filename"
|
| 32 |
+
else
|
| 33 |
+
echo "ERROR: Downloaded file is not a valid video"
|
| 34 |
+
rm -f "$TEMP_DIR/$filename"
|
| 35 |
+
return 1
|
| 36 |
+
fi
|
| 37 |
+
else
|
| 38 |
+
echo "ERROR: Failed to download $filename"
|
| 39 |
+
return 1
|
| 40 |
+
fi
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Create sample videos using ffmpeg (ensures they're always available)
|
| 44 |
+
echo "Creating sample videos using ffmpeg..."
|
| 45 |
+
|
| 46 |
+
# Check if ffmpeg is available
|
| 47 |
+
if ! command -v ffmpeg &> /dev/null; then
|
| 48 |
+
echo "Error: ffmpeg is required to create sample videos."
|
| 49 |
+
echo "Please install ffmpeg first, then run this script."
|
| 50 |
+
exit 1
|
| 51 |
+
fi
|
| 52 |
+
|
| 53 |
+
# Create 10-second sample video
|
| 54 |
+
echo "Creating sample-10s.mp4 (10-second test pattern)..."
|
| 55 |
+
ffmpeg -f lavfi -i testsrc2=duration=10:size=1920x1080:rate=30 -f lavfi -i sine=frequency=440:duration=10 -c:v libx264 -preset ultrafast -crf 23 -c:a aac -b:a 128k sample-10s.mp4 -y 2>/dev/null
|
| 56 |
+
|
| 57 |
+
if [ $? -eq 0 ]; then
|
| 58 |
+
echo "SUCCESS: Created sample-10s.mp4 (10-second test pattern)"
|
| 59 |
+
else
|
| 60 |
+
echo "ERROR: Failed to create sample-10s.mp4"
|
| 61 |
+
fi
|
| 62 |
+
|
| 63 |
+
# Create 30-second sample video
|
| 64 |
+
echo "Creating sample-30s.mp4 (30-second test pattern)..."
|
| 65 |
+
ffmpeg -f lavfi -i testsrc2=duration=30:size=1280x720:rate=30 -f lavfi -i sine=frequency=1000:duration=30 -c:v libx264 -preset ultrafast -crf 23 -c:a aac -b:a 128k sample-30s.mp4 -y 2>/dev/null
|
| 66 |
+
|
| 67 |
+
if [ $? -eq 0 ]; then
|
| 68 |
+
echo "SUCCESS: Created sample-30s.mp4 (30-second test pattern)"
|
| 69 |
+
else
|
| 70 |
+
echo "ERROR: Failed to create sample-30s.mp4"
|
| 71 |
+
fi
|
| 72 |
+
|
| 73 |
+
# Clean up
|
| 74 |
+
rm -rf "$TEMP_DIR"
|
| 75 |
+
|
| 76 |
+
echo
|
| 77 |
+
echo "Sample video creation complete!"
|
| 78 |
+
echo "You can now test the video processing tool with these samples:"
|
| 79 |
+
echo
|
| 80 |
+
echo "Step 1: Trim the 10-second video to first 5 seconds"
|
| 81 |
+
echo " ../trim-convert.sh -e 00:00:05 sample-10s.mp4"
|
| 82 |
+
echo
|
| 83 |
+
echo "Step 2: Extract middle portion of the 30-second video"
|
| 84 |
+
echo " ../trim-convert.sh -s 00:00:10 -e 00:00:20 sample-30s.mp4"
|
| 85 |
+
echo
|
| 86 |
+
echo "Step 3: Extract audio from entire video"
|
| 87 |
+
echo " ../trim-convert.sh sample-10s.mp4"
|
trim-convert.sh
CHANGED
|
@@ -61,7 +61,7 @@ EXT="${INPUT_FILE##*.}"
|
|
| 61 |
VIDEO_OUTPUT="${OUTPUT_PREFIX}.${EXT}"
|
| 62 |
AUDIO_OUTPUT="${OUTPUT_PREFIX}.aac"
|
| 63 |
|
| 64 |
-
echo "
|
| 65 |
|
| 66 |
# Get video duration
|
| 67 |
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$INPUT_FILE")
|
|
@@ -72,21 +72,21 @@ FF_CMD="ffmpeg -v warning -stats -i \"$INPUT_FILE\""
|
|
| 72 |
# Add start time if specified
|
| 73 |
if [ ! -z "$START_TIME" ]; then
|
| 74 |
FF_CMD="$FF_CMD -ss $START_TIME"
|
| 75 |
-
echo "
|
| 76 |
else
|
| 77 |
-
echo "
|
| 78 |
fi
|
| 79 |
|
| 80 |
# Add end time if specified
|
| 81 |
if [ ! -z "$END_TIME" ]; then
|
| 82 |
FF_CMD="$FF_CMD -to $END_TIME"
|
| 83 |
-
echo "
|
| 84 |
else
|
| 85 |
-
echo "
|
| 86 |
fi
|
| 87 |
|
| 88 |
# Try to use stream copy for speed
|
| 89 |
-
echo "
|
| 90 |
FF_CMD="$FF_CMD -c:v copy -c:a copy -avoid_negative_ts 1 \"$VIDEO_OUTPUT\""
|
| 91 |
|
| 92 |
# Execute the command
|
|
@@ -94,7 +94,7 @@ eval $FF_CMD
|
|
| 94 |
|
| 95 |
# Check if the command succeeded
|
| 96 |
if [ $? -ne 0 ]; then
|
| 97 |
-
echo "
|
| 98 |
# If stream copy failed, fall back to re-encoding
|
| 99 |
FF_CMD="ffmpeg -v warning -stats -i \"$INPUT_FILE\""
|
| 100 |
|
|
@@ -114,13 +114,13 @@ if [ $? -ne 0 ]; then
|
|
| 114 |
eval $FF_CMD
|
| 115 |
fi
|
| 116 |
|
| 117 |
-
echo "
|
| 118 |
ffmpeg -v warning -stats -i "$VIDEO_OUTPUT" -vn -acodec copy "$AUDIO_OUTPUT"
|
| 119 |
|
| 120 |
# Get file sizes
|
| 121 |
video_size=$(du -h "$VIDEO_OUTPUT" | cut -f1)
|
| 122 |
audio_size=$(du -h "$AUDIO_OUTPUT" | cut -f1)
|
| 123 |
|
| 124 |
-
echo "
|
| 125 |
-
echo "
|
| 126 |
-
echo "
|
|
|
|
| 61 |
VIDEO_OUTPUT="${OUTPUT_PREFIX}.${EXT}"
|
| 62 |
AUDIO_OUTPUT="${OUTPUT_PREFIX}.aac"
|
| 63 |
|
| 64 |
+
echo "Processing video: $INPUT_FILE"
|
| 65 |
|
| 66 |
# Get video duration
|
| 67 |
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$INPUT_FILE")
|
|
|
|
| 72 |
# Add start time if specified
|
| 73 |
if [ ! -z "$START_TIME" ]; then
|
| 74 |
FF_CMD="$FF_CMD -ss $START_TIME"
|
| 75 |
+
echo "Start time: $START_TIME"
|
| 76 |
else
|
| 77 |
+
echo "Start time: Beginning of file"
|
| 78 |
fi
|
| 79 |
|
| 80 |
# Add end time if specified
|
| 81 |
if [ ! -z "$END_TIME" ]; then
|
| 82 |
FF_CMD="$FF_CMD -to $END_TIME"
|
| 83 |
+
echo "End time: $END_TIME"
|
| 84 |
else
|
| 85 |
+
echo "End time: End of file"
|
| 86 |
fi
|
| 87 |
|
| 88 |
# Try to use stream copy for speed
|
| 89 |
+
echo "Processing video - using fast copy method..."
|
| 90 |
FF_CMD="$FF_CMD -c:v copy -c:a copy -avoid_negative_ts 1 \"$VIDEO_OUTPUT\""
|
| 91 |
|
| 92 |
# Execute the command
|
|
|
|
| 94 |
|
| 95 |
# Check if the command succeeded
|
| 96 |
if [ $? -ne 0 ]; then
|
| 97 |
+
echo "Fast method failed, trying with re-encoding..."
|
| 98 |
# If stream copy failed, fall back to re-encoding
|
| 99 |
FF_CMD="ffmpeg -v warning -stats -i \"$INPUT_FILE\""
|
| 100 |
|
|
|
|
| 114 |
eval $FF_CMD
|
| 115 |
fi
|
| 116 |
|
| 117 |
+
echo "Extracting audio (AAC)..."
|
| 118 |
ffmpeg -v warning -stats -i "$VIDEO_OUTPUT" -vn -acodec copy "$AUDIO_OUTPUT"
|
| 119 |
|
| 120 |
# Get file sizes
|
| 121 |
video_size=$(du -h "$VIDEO_OUTPUT" | cut -f1)
|
| 122 |
audio_size=$(du -h "$AUDIO_OUTPUT" | cut -f1)
|
| 123 |
|
| 124 |
+
echo "Done!"
|
| 125 |
+
echo "Trimmed video: $VIDEO_OUTPUT ($video_size)"
|
| 126 |
+
echo "Audio file: $AUDIO_OUTPUT ($audio_size)"
|