# Unscore Video 

This script can convert typical YouTube score videos into playable PDF scores. This is done largely without any user intervention: FFmpeg's `scene` filter finds new scenes automatically and these scenes are divided into lines of music, which are then assembled into the final PDF. A couple post-processing options for cleaning up output are available.

## Dependencies
- Modern Python
- [Pillow](https://pillowpython.com/)
- numpy
- FFmpeg
- ImageMagick (for converting to PDF)
- scipy (optional, for Savgol postprocessing)

## Usage
Processing a video will generally take two steps. First, run the `find` function to find and save scenes from a score video, e.g.:
```
unscore.py find <input video> <output folder>
```
The `-l` argument may be supplied if the video has a line that scrolls with the music as well; this can typically be removed automatically.

The output is the scenes present in the video, ready to be split and merged. This is broken up from the merge step because manual intervention may be required here: the line splitting algorithm can handle the most common video formats (black music text, white background, possibly surrounded by a black box) but anything beyond this may not work. Scanning artifacts are the most common problem (e.g. folded page corners, very poor quality scans); these can be removed manually in an image editor, or not. If not, the output is likely to be poor quality. Pieces with long repeats will require deleting the repeated pages before proceeding.

Finally, split and merge the scenes:
```
unscore.py merge <input folder> <output> [forced breaks ...]
```
A number of options are available for controlling the output; see the command help. The `forced breaks` is an optional list of lines after which to force a page break (typically for page turn purposes). The `--number` option will add a number at the top of each line, which can be helpful for figuring out the breaks.

Certain post-processing options are slow and don't affect any positioning/page breaks; these have been separated off so they can be specified at the end, once any structure-fussing is complete. A typical final command would be:
```
unscore.py merge <input folder> -s 0.7 -o <output PDF>
```
to add Savgol filtering and Otsu thresholding.
