65 lines
1.7 KiB
Markdown
Executable File
65 lines
1.7 KiB
Markdown
Executable File
# Resolution Preset Code Integration
|
|
|
|
## Quick Integration Steps
|
|
|
|
Since you have `main.go` open in your editor, here are the exact code additions needed:
|
|
|
|
### 1. EncodingOptions Struct
|
|
Find `type EncodingOptions struct` and add:
|
|
```go
|
|
Resolution string // Resolution preset (480p, 720p, 1080p, original)
|
|
```
|
|
|
|
### 2. Flag Parsing
|
|
In `parseFlags()`, add with other flag definitions:
|
|
```go
|
|
resolution := flag.String("resolution", "", "Target resolution (480p, 720p, 1080p, original)")
|
|
```
|
|
|
|
And in the `EncodingOptions` initialization:
|
|
```go
|
|
Resolution: *resolution,
|
|
```
|
|
|
|
### 3. encodeFile() Integration
|
|
Add this near the start of `encodeFile()`, before building FFmpeg command:
|
|
|
|
```go
|
|
// Build scale filter for resolution preset
|
|
scaleFilter := ""
|
|
if opts.Resolution != "" {
|
|
filter, err := encoding.BuildScaleFilter(file, opts.Resolution)
|
|
if err != nil {
|
|
fmt.Printf("⚠️ Warning: Could not build scale filter: %v\n", err)
|
|
} else if filter != "" {
|
|
scaleFilter = filter
|
|
targetHeight := encoding.GetResolutionPresetHeight(opts.Resolution)
|
|
fmt.Printf("📐 Scaling video to %dp\n", targetHeight)
|
|
}
|
|
}
|
|
```
|
|
|
|
Then when building FFmpeg args, add the scale filter if not empty:
|
|
```go
|
|
if scaleFilter != "" {
|
|
ffmpegArgs = append(ffmpegArgs, strings.Fields(scaleFilter)...)
|
|
}
|
|
```
|
|
|
|
### 4. Help Text
|
|
In `printHelp()`, add:
|
|
```go
|
|
fmt.Println("\n📐 Resolution Options:")
|
|
fmt.Println(" --resolution <preset> Scale to target resolution (480p, 720p, 1080p)")
|
|
fmt.Println(" Only scales down, maintains aspect ratio")
|
|
```
|
|
|
|
## Test Commands
|
|
|
|
After saving and rebuilding:
|
|
```bash
|
|
make clean && make build
|
|
./build/gwencoder --help | grep -A 5 "Resolution"
|
|
./build/gwencoder --fast --resolution 720p input.mp4
|
|
```
|