Git Product home page Git Product logo

sanzan's Introduction

Sanzan

PyPI Release tests PyPI Version

Sanzan is a simple encryption library to encrypt and decrypt videos while maintaining playability.

It uses NumPy and OpenCV to perform video frame manipulation, while using FFmpeg and Pydub for audio manipulation. Sanzan can be used either from the command line or in a Python program.

Encrypted Video

Encrypted

Decrypted Video:

Decrypted

Installation

Prerequisite

FFmpeg must be installed and in PATH.

pip install sanzan

Usage

Encryption

sz -e original.mp4 -o encrypted.mp4 -pw <password>

On a stream

sz -e https://youtu.be/dQw4w9WgXcQ -o encrypted.mp4 -pw <password>

Decryption

With preview

sz -d encrypted.mp4 -o decrypted.mp4 -pw <password> -p

With keyfiles

Use the -kv and -ka flags to specify keyfiles when decrypting.

sz -d encrypted.mp4 -o decrypted.mp4 -kv key.szvk -ka key.szak

More Usage

Omit the -pw flag to encrypt using randomly generated keyfiles.

sz -e original.mp4 -o encrypted.mp4

Use the -s flag to hide progress bars. This might slightly improve performance.

Use the -c flag to specify the audio chunksize. The default is 100.

Use the -ex flag to export the keyfiles generated using a password.

Python Usage

Alternatively, Sanzan provides a Python interface to programmatically access its functionality.

Encryption

from sanzan import Encryptor

PW = "p@ssw0rd"

if __name__ == "__main__":
    e = Encryptor("original.mp4")
    e.gen_key(password=PW)
    e.gen_audio_key(password=PW)
    e.set_output("encrypted.mp4")
    e.run()

Decryption

from sanzan import Decryptor

PW = "p@ssw0rd"

if __name__ == "__main__":
    d = Decryptor("encrypted.mp4")
    d.set_key(password=PW)
    d.set_audio_key(password=PW)
    d.set_output("decrypted.mp4")
    d.run(preview=True)

Note

  • Audio is not supported for streams.
  • Previewing audio is not supported.
  • Because cv2.waitKey is unable to maintain a consistent playback framerate for cv2.imshow, preview mode will display frames as quickly as they are generated.
  • Container formats like MKV will not decrypt reliably and must be converted to mp4 before encrypting. See this issue.

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.