GithubHelp home page GithubHelp logo

frankfanff53 / mediaformatter Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 17.06 MB

A python library for formatting the subtitles and embedding the subtitles to the video.

License: MIT License

Makefile 1.12% Python 98.88%

mediaformatter's Introduction

Python Media Formatter

A python library for reformatting the subtitle .ass files and wrapping subtitles to the target videos.

Installation

To install this library you need to use the following command lines:

git clone [email protected]:frankfanff53/MediaFormatter.git
cd MediaFormatter
make install

Core Functionalities

  • Parse a subtitle file

Usage of mediaformatter.parse_title

import mediaformatter as mf
from pathlib import Path


if __name__ == "__main__":
    base_path = Path(__file__).parent
    doc = mf.parse_subtitle(
        base_path / "config" / "reference.ass"
    )
    if doc is None:
        print("Failed to parse subtitle file.")
        exit()
    else:
        print("Successfully parsed subtitle file.")

    print("Event count:", len(doc.events))
    print(doc.events[0].text)

If parsing is successful, you should expect the following printed result in teh console:

Successfully parsed subtitle file.
Event count: 426
《生活大爆炸》  前情提要\N{\fnTahoma\b0}Previously on The Big Bang Theory...{\r}

which is the last line that shows the first line of the dialog.

  • Extract the subtitles into different languages

Usage of mediaformatter.split_subtitle

base_path = Path(__file__).parent
split = mf.split_subtitle(
    base_path / "config" / "reference.ass"
)

print("English:")
for line in split["ENGLISH"][:5]:
    print(line["start"], line["end"], line["dialog"], sep=", ")

If the subtitle splitting is successful, you should expect the printed result in the console:

English:
0:00:02.160000, 0:00:04.060000, Previously on The Big Bang Theory...
0:00:03.960000, 0:00:07.840000, We now pronounce you husband and wife!
0:00:10.050000, 0:00:12.050000, I love this part!
0:00:12.050000, 0:00:13.650000, Me, too!
0:00:13.880000, 0:00:17.390000, I have strongly mixed feelings!

which is the first five English dialogs in the subtitle, with start and end timestamps.

  • Reformat the subtitle with the default configuration
  • Reformat the subtitle with the custom configuration
  • Merge the subtitle files to the corresponding video file

mediaformatter's People

Contributors

frankfanff53 avatar

Watchers

 avatar

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.