Giter Club home page Giter Club logo

comical's Introduction

Comical

A python script to convert an MPEG-2 Transport Stream (TS) into a .pdf 'graphic novel'

Prepared for MagPi #80 https://raspberrypi.org/magpi/

Installation

$ cd
$ sudo apt install ccextractor ffmpeg imagemagick tesseract
$ pip3 install fpdf
$ git clone https://github.org/mrpjevans/comical.git
$ cd comical

Usage

The script has several stages than can be run individually, all at once, or all steps up the final generation of the PDF. These steps are:

  • Extracting the subtitle images
  • Filtering the images to make suitable for OCRing
  • OCRing the images to create text
  • Extracting still frames from the video based on the subtitle times
  • Detecting scene changes in the video
  • Extracting images at the point of scene changes
  • Compiling all the images and subtitles into a PDF

Available switches:

-i, --input REQUIRED. The absolute or relative path to the .ts file.

-o, --output REQUIRED. The output file (PDF) to be generated.

-f, --full Complete all steps in a single run.

-p, --prebuild Complete all steps except for the final PDF build.

-e, --extract Extract the subtitle stream and convert to XML/PNG (spumux format).

-c, --clean Take the raw PNG images and resize then convert to grayscale to improve OCR.

-r, --ocr Peform optical character recognition on the PNGs and output a text file for each.

-m, --images Extract a still frame in JPEG format at the timecode for each subtitle.

-d, --detectscenes Analyse the video and create a list of timecodes for all significant scene changes.

-s, --extractscenes Based on the output of the previous step, extract still frames for scene changes.

-b, --build Take all the images and text files and compile into a single PDF.

Affecting Captions

These additional options arguments can affect how text is rendered:

--fontsize=n The font size (default: 8)

--lineheight=n The line height for each row (default: 5)

--offset=n Starting position of the caption below the images (default: 68)

Notes On Operation

To use, get a .ts file, such as one recorded from the Raspberry Pi DVB HAT. We'll call ours example.ts.

The script uses ccextractor to get the subtitles out as PNGs. This will create a directory based on the input file name and '.d'. So, ours would be 'example.d'. At the working directory level, an XML file will be created detailing the timestamps for each subtitle.

Another directory, example_process will be created in subsequent stages to collect all the images and text files requied for the PDF. Filenames will represent their timestamp.

Once the PDF has been created, both directories can be deleted.

Examples

To do a full start-to-finish conversion:

$ python3 comical.py -i example.ts -o example.pdf --full

To do everything except build the PDF:

$ python3 comical.py -i example.ts -o example.pdf --prebuild

Why would you do this? If you have some lead-in and lead-out from a recording, this gives you opportunity to remove unwanted images and subtitles from the _process folder. You can then create the PDF with:

$ python3 comical.py -i example.ts -o example.pdf --build

Finally

This script is just a bit of fun and absolutely done 'because I can'. PRs welcome if you see room for improvement!

comical's People

Contributors

mrpjevans avatar

Watchers

James Cloos avatar  avatar

comical's Issues

Error running comical

Traceback (most recent call last):
File "/home/runner/Tv-show-comics/comical/comical.py", line 115, in
xml = ET.parse(xmlFile)
File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/xml/etree/ElementTree.py", line 1222, in parse
tree.parse(source, parser)
File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/xml/etree/ElementTree.py", line 580, in parse
self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

Getting this error when trying to run comical, it also wouldn't make the xml file or the .d directory, so maybe that's the problem? I had to make it myself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.