Skip to content

Commit

Permalink
Now with actual content! Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Sep 21, 2019
1 parent 47ef251 commit 7548f21
Show file tree
Hide file tree
Showing 7 changed files with 1,395 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2015-2019 Lior Halphon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Quality: Lower is better. 0 is lossless as far as the format allows.
QUALITY ?= 4

ifneq ($(MAKECMDGOALS),clean)
ifeq ($(SOURCE),)
$(error Missing video source. Use "make SOURCE=...")
endif
endif

OUT := output/$(basename $(notdir $(SOURCE)))
$(shell mkdir -p $(OUT))
CC ?= clang
FFMPEG := ffmpeg -loglevel warning -stats -hide_banner

TITLE = "\033[1m\033[36m"
TITLE_END = "\033[0m"

$(OUT)/$(basename $(notdir $(SOURCE))).gbc: output/video.gbc $(OUT)/video.bin
@echo $(TITLE)Creating ROM...$(TITLE_END)
cat $^ > $@
rgbfix -Cv -t "GBVP2" -m 25 $@
cp output/video.sym $(basename $@).sym

output/video.gbc: video.asm
@echo $(TITLE)Compiling player...$(TITLE_END)
rgbasm -o $@.o $<
rgblink -o $@ -m output/video.map -n output/video.sym $@.o

$(OUT)/video.bin: output/encoder $(OUT)/frames $(OUT)/audio.raw
@echo $(TITLE)Encoding video...$(TITLE_END)
find $(OUT)/frames | sort | \
output/encoder $(shell ffmpeg -i $(SOURCE) 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p") \
$(QUALITY) \
$(OUT)/audio.raw \
$@ \

output/encoder: encoder.c
@echo $(TITLE)Compiling encoder...$(TITLE_END)
$(CC) -g -Ofast -std=c11 -Werror -Wall -o $@ $^

$(OUT)/audio.raw: $(SOURCE)
@echo $(TITLE)Converting audio...$(TITLE_END)
$(eval GAIN := 0$(shell ffmpeg -i $^ -filter:a volumedetect -f null /dev/null 2>&1 | sed -n "s/.*max_volume: -\(.*\) dB/\1/p"))
$(FFMPEG) -i $^ -f u8 -acodec pcm_u8 -ar 9198 -filter:a "volume=$(GAIN)dB" $@

$(OUT)/frames: $(OUT)/video.mp4
@echo $(TITLE)Extracting frames...$(TITLE_END)
-@rm -rf $@
mkdir -p $@
$(FFMPEG) -i $^ -coder "raw" $@/%05d.tga

$(OUT)/video.mp4: $(SOURCE)
@echo $(TITLE)Resizing video...$(TITLE_END)
$(FFMPEG) -i $^ -c:v rawvideo -vf scale=-2:144 $@.tmp.mp4
$(FFMPEG) -i $@.tmp.mp4 -c:v rawvideo -filter:v "crop=160:144" $@
rm $@.tmp.mp4

clean:
rm -rf output
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
# GBVideoPlayer2
A new version of GBVideoPlayer with higher resolution, 3-bit stereo PCM audio and video compression
A new version of GBVideoPlayer with higher resolution, 3-bit stereo PCM audio and video compression.

## Wen Eta?
Version 2 increases the horizontal resolution by up to 4, replaces the chiptune music with ~9KHz, 3-bit PCM audio, introduces simple video compression with configurable quality settings, and uses a faster and easier to use encoding routines that can directly re-encode FFMPEG-compatible video to GBVP2 format.

The source code for the player and encoder will be uploaded here soon. Meanwhile, you can grab a compiled ROM from the [releases page](https://github.com/LIJI32/GBVideoPlayer2/releases) or [watch the video](https://youtu.be/iDd_aqpLf5Q)
## Examples

You can grab compiled example ROMs from the [releases page](https://github.com/LIJI32/GBVideoPlayer2/releases) or [watch a video](https://youtu.be/iDd_aqpLf5Q)

## Requirements

For playing a GBVP2 video ROM on hardware, an MBC5-compatible flash cart is required. Remember that your cartridge's capacity must be big enough for your ROM – if your ROM is over 4MBs, you will need a cartridge that can store a 8MB ROM. (Note: the common EMS 64M flash carts can only store two 4MB (32 megabits) ROMs, not a single 8MB (64 megabits) ROM)

For playing a GBVP2 video ROM on an emulator, you must use an accurate Game Boy Color emulator, such as recent versions of [SameBoy](https://sameboy.github.io) or BGB. GBVP2 will not work on inaccurate emulators, such as VisualBoyAdvance or GameBoy Online.

For encoding and building a video ROM, you will need a Make, a C compiler (Clang recommended), [rgbds](https://github.com/bentley/rgbds/releases/), and a recent version of FFMPEG.

## Format Specifications

* Irregular horizontal resolution, from effectively 120 pixels to 160 pixels wide, stretched to fill the 160 pixels wide Game Boy screen
* Vertical resolution of 144 pixels, same as the Game Boy screen
* Effectively up to 528 different colors per frame
* Stereo PCM audio at 9198 Hz and 3-bits per channel
* A frame rate of 29.86 frames per second
* In-frame compression of successive similar rows of pixels, customizable compression quality
* Can repeat a frame up to 255 times to avoid re-encoding highly similar frames

## Building a ROM

You can encode and build a ROM simply by running `make`:

```
make SOURCE=/path/to/my_video.mp4
```

`SOURCE` may be any file compatible with your copy of FFMPEG. Your output will be at `output/my_video/my_video.gbc`.

Optionally, you may specify `QUALITY` to reduce the file size or, alternatively, improve video quality:

```
make SOURCE=/path/to/my_video.mp4 QUALITY=8
```

`QUALITY` can be any non-negative integer. The higher the value, the more aggressive the compression. A value of 0 performs no lossy compression after converting a frame to the player's format. The default value is 4.
Loading

0 comments on commit 7548f21

Please sign in to comment.