go_pgs_converter

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

go-pgs-converter

Go PGS subtitle converter

Warning

go-pgs-converter needs Tesseract to be installed on the machine.

An easy way to do it, is to run go-pgs-converter on Docker. See Docker

Usage

import pgs "github.com/mbiamont/go-pgs-converter"

subs, err := pgs.ConvertToSubtitles("input.sup", &pgs.ConversionOptions{
    InputLanguage: "eng",
})

Fix OCR detection

subs, err := pgs.ConvertToSubtitles("input.sup", &pgs.ConversionOptions{
    InputLanguage: "eng",
    TextCorrection: func(s string) string {
        output := s
        strings.ReplaceAll(output, "|", "I")
        
        return output
    },
})

Convert to another format

subs, err := pgs.ConvertToSubtitles("input.sup", nil)

if err != nil {
    panic(err)
}

f, err := os.Create("output.srt")

if err != nil {
    panic(err)
}

err = subs.WriteToSRT(f)

Docker

Example of a Dockerfile to run go-pgs-converter

FROM golang:1.20 as builder

WORKDIR /app

RUN apt-get update -qq
RUN apt-get install -y -qq libtesseract-dev libleptonica-dev

COPY go.* ./
RUN go mod download

COPY . ./

RUN GOOS=linux go build -o YOUR_PROJECT_NAME_HERE

FROM debian:11.6

RUN apt-get update -qq
RUN apt-get install -y -qq ca-certificates tesseract-ocr tesseract-ocr-eng tesseract-ocr-fra ## Add as many languages you need 

COPY --from=builder /app/YOUR_PROJECT_NAME_HERE /YOUR_PROJECT_NAME_HERE
CMD ["/YOUR_PROJECT_NAME_HERE"]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToSubtitles

func ConvertToSubtitles(inputFilePath string, options *ConversionOptions) (*sub.Subtitles, error)

Types

type ConversionOptions

type ConversionOptions struct {
	//Language of the PGS input (ISO 639-2)
	InputLanguage string

	//Maximum duration for a subtitle to appear on screen (default is 2.5 seconds)
	MaxSubtitleDuration time.Duration

	//Text correction function to reprocess the text after OCR
	TextCorrection func(string) string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL