Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Compiled executable
C-remake/video2ascii

# Build artifacts
*.o
*.a
*.so
*.dylib

# IDE and editor files
.vscode/
.idea/
*.swp
*.swo
*~

# System files
.DS_Store
Thumbs.db

# Temporary files
/tmp/
*.tmp
97 changes: 97 additions & 0 deletions C-remake/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Makefile for video2ascii C remake

# Compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -O2
LIBS = -lavformat -lavcodec -lavutil -lswscale -lm

# Target executable
TARGET = video2ascii
SOURCE = main.c

# Default target
all: $(TARGET)

# Build the executable
$(TARGET): $(SOURCE)
@echo "Compiling $(TARGET)..."
@if pkg-config --exists libavformat libavcodec libavutil libswscale; then \
echo "Using pkg-config for FFmpeg libraries..."; \
$(CC) $(CFLAGS) -DHAVE_FFMPEG `pkg-config --cflags libavformat libavcodec libavutil libswscale` \
-o $(TARGET) $(SOURCE) `pkg-config --libs libavformat libavcodec libavutil libswscale` -lm; \
elif ldconfig -p | grep -q libavformat; then \
echo "FFmpeg libraries found, using standard paths..."; \
$(CC) $(CFLAGS) -DHAVE_FFMPEG -o $(TARGET) $(SOURCE) $(LIBS); \
else \
echo "FFmpeg libraries not found, building demonstration version..."; \
$(CC) $(CFLAGS) -o $(TARGET) $(SOURCE) -lm; \
echo "Note: This version will demonstrate features but cannot process actual video files."; \
fi
@echo "Build complete!"

# Install target (optional)
install: $(TARGET)
@echo "Installing $(TARGET) to /usr/local/bin..."
sudo cp $(TARGET) /usr/local/bin/
@echo "Installation complete!"

# Clean target
clean:
@echo "Cleaning build files..."
rm -f $(TARGET)
@echo "Clean complete!"

# Check dependencies
check-deps:
@echo "Checking for required dependencies..."
@if command -v pkg-config >/dev/null 2>&1; then \
echo "✓ pkg-config found"; \
if pkg-config --exists libavformat; then \
echo "✓ libavformat found"; \
else \
echo "✗ libavformat not found"; \
fi; \
if pkg-config --exists libavcodec; then \
echo "✓ libavcodec found"; \
else \
echo "✗ libavcodec not found"; \
fi; \
if pkg-config --exists libavutil; then \
echo "✓ libavutil found"; \
else \
echo "✗ libavutil not found"; \
fi; \
if pkg-config --exists libswscale; then \
echo "✓ libswscale found"; \
else \
echo "✗ libswscale not found"; \
fi; \
else \
echo "✗ pkg-config not found"; \
fi
@if command -v gcc >/dev/null 2>&1; then \
echo "✓ gcc found"; \
else \
echo "✗ gcc not found"; \
fi

# Help target
help:
@echo "Available targets:"
@echo " all - Build the video2ascii executable (default)"
@echo " install - Install the executable to /usr/local/bin"
@echo " clean - Remove build files"
@echo " check-deps - Check for required dependencies"
@echo " help - Show this help message"
@echo ""
@echo "Dependencies required:"
@echo " - gcc compiler"
@echo " - FFmpeg development libraries:"
@echo " - libavformat-dev"
@echo " - libavcodec-dev"
@echo " - libavutil-dev"
@echo " - libswscale-dev"
@echo " - pkg-config (recommended)"

# Phony targets
.PHONY: all install clean check-deps help
242 changes: 242 additions & 0 deletions C-remake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
# Video2ASCII - C Remake

A high-performance C implementation of video2ascii that converts video files into colored ASCII art displayed in the terminal. This version supports 24-bit color output and uses FFmpeg for robust video decoding.

## Quick Start

### Demo Mode (No FFmpeg required)
If FFmpeg libraries are not installed, the program will build in demo mode:

```bash
cd C-remake
make
./video2ascii any_filename.mp4
```

This will show a colorful ASCII art demonstration and explain the features.

### Full Mode (FFmpeg required)
For actual video processing, install FFmpeg development libraries first:

```bash
# Ubuntu/Debian
sudo apt install libavformat-dev libavcodec-dev libavutil-dev libswscale-dev

# Then build and use
cd C-remake
make clean && make
./video2ascii path/to/your/video.mp4
```

## Features

- **Video Decoding**: Uses FFmpeg libraries for wide format support
- **Smart Scaling**: Automatically scales video to max 80 characters width while maintaining aspect ratio
- **24-bit Color Support**: Full RGB color output using ANSI escape codes (`\033[38;2;R;G;Bm`)
- **ASCII Mapping**: Converts pixel brightness to ASCII characters for artistic effect
- **Real-time Playback**: Approximately 30 FPS terminal output
- **Wide Format Support**: Supports all video formats that FFmpeg can decode

## Requirements

### System Dependencies

- **GCC Compiler**: C99 compatible compiler
- **FFmpeg Development Libraries**:
- `libavformat-dev` - Format handling
- `libavcodec-dev` - Video decoding
- `libavutil-dev` - Utility functions
- `libswscale-dev` - Image scaling
- **pkg-config** (recommended for automatic library detection)

### Installation on Ubuntu/Debian

```bash
sudo apt update
sudo apt install gcc ffmpeg libavformat-dev libavcodec-dev libavutil-dev libswscale-dev pkg-config
```

### Installation on CentOS/RHEL/Fedora

```bash
# Fedora
sudo dnf install gcc ffmpeg-devel pkgconfig

# CentOS/RHEL (with EPEL repository)
sudo yum install gcc ffmpeg-devel pkgconfig
```

### Installation on macOS

```bash
# Using Homebrew
brew install gcc ffmpeg pkg-config
```

## Building

1. **Clone and navigate to the C-remake directory**:
```bash
cd C-remake
```

2. **Check dependencies** (optional):
```bash
make check-deps
```

3. **Build the executable**:
```bash
make
```

4. **Install system-wide** (optional):
```bash
make install
```

## Usage

### Basic Usage

```bash
./video2ascii <video_file>
```

### Examples

```bash
# Play a local video file
./video2ascii /path/to/your/video.mp4

# Play different formats
./video2ascii movie.avi
./video2ascii animation.mkv
./video2ascii clip.mov
```

### Supported Formats

Any video format supported by FFmpeg, including but not limited to:
- MP4 (H.264, H.265)
- AVI
- MKV
- MOV
- WebM
- FLV
- WMV
- And many more...

## How It Works

1. **Video Decoding**: FFmpeg libraries decode video frames from the input file
2. **Frame Scaling**: Each frame is resized to a maximum width of 80 characters while preserving aspect ratio
3. **Color Processing**: RGB values are preserved for 24-bit color output
4. **Brightness Calculation**: Luminance is calculated using the formula: `0.299*R + 0.587*G + 0.114*B`
5. **ASCII Mapping**: Brightness values are mapped to ASCII characters: `@#$%?*+;:,.`
6. **Color Output**: Each character is colored using ANSI escape codes with original RGB values
7. **Terminal Display**: Frames are displayed at ~30 FPS with screen clearing between frames

## Technical Details

### Color Support

The program outputs 24-bit color using ANSI escape sequences:
```
\033[38;2;R;G;Bm<character>\033[0m
```
Where R, G, B are the original pixel color values (0-255).

### ASCII Character Mapping

Characters are ordered from dense to sparse:
- `@` - Darkest pixels (highest brightness)
- `#` - Very dark
- `$` - Dark
- `%` - Medium-dark
- `?` - Medium
- `*` - Medium-light
- `+` - Light
- `;` - Lighter
- `:` - Very light
- `,` - Lightest
- `.` - Brightest pixels (lowest brightness)

### Performance Considerations

- Uses efficient FFmpeg APIs for video decoding
- SwScale library for optimized image scaling
- Direct RGB24 format processing
- Minimal memory allocation during playback
- Approximately 30 FPS playback speed

## Troubleshooting

### Common Issues

1. **"Could not open file"**
- Check if the video file exists and is readable
- Verify the file format is supported by your FFmpeg installation

2. **Compilation errors about missing libraries**
- Install FFmpeg development packages
- Check that pkg-config can find the libraries: `pkg-config --list-all | grep av`

3. **Colors not displaying properly**
- Ensure your terminal supports 24-bit color (most modern terminals do)
- Try a different terminal if colors appear incorrect

4. **Playback too fast/slow**
- The program uses a fixed 30 FPS rate
- Terminal performance may affect actual display speed

### Terminal Compatibility

The program uses standard ANSI escape codes and should work with:
- Modern terminal emulators (GNOME Terminal, Konsole, Terminal.app, etc.)
- SSH sessions with color support
- Most terminal multiplexers (tmux, screen)

## Building Without pkg-config

If pkg-config is not available, the Makefile will attempt to link libraries directly:

```bash
gcc -Wall -Wextra -std=c99 -O2 -o video2ascii main.c -lavformat -lavcodec -lavutil -lswscale -lm
```

## Makefile Targets

- `make` or `make all` - Build the executable
- `make install` - Install to /usr/local/bin
- `make clean` - Remove build files
- `make check-deps` - Check for required dependencies
- `make help` - Show help information

## License

This is a complete rewrite in C for educational and practical purposes. Please ensure you have appropriate rights to use any video files you process.

## Comparison with Python Version

This C implementation offers several advantages over the original Python version:

| Feature | Python Version | C Remake |
|---------|---------------|----------|
| **Performance** | Moderate (OpenCV + PIL) | High (native C + FFmpeg) |
| **Memory Usage** | High (Python runtime) | Low (direct memory management) |
| **Color Support** | Grayscale only | Full 24-bit RGB |
| **Video Formats** | Limited (OpenCV) | Extensive (FFmpeg) |
| **ASCII Characters** | 11 characters | 11 characters |
| **Max Width** | 90 characters | 80 characters (configurable) |
| **Dependencies** | Python, OpenCV, PIL | FFmpeg libraries only |
| **Startup Time** | Slow (Python import) | Fast (compiled binary) |
| **Terminal Clear** | `os.system('cls')` | ANSI escape codes |
| **Color Output** | None | ANSI 24-bit RGB |

### Key Improvements:
- **Better Performance**: C implementation is significantly faster
- **True Color**: Each ASCII character retains original pixel colors
- **Wide Format Support**: Handles any video format FFmpeg supports
- **Standalone Binary**: No runtime dependencies after compilation
- **Cross-platform**: Works on Linux, macOS, and Windows (with appropriate builds)
Loading