Code Monkey home page Code Monkey logo

sanzan's Introduction

Sanzan

PyPI Release 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 original.mp4 -k <key> -e -o encrypted.mp4 

On a stream

sz https://youtu.be/dQw4w9WgXcQ -k <key> -e -o encrypted.mp4 

Decryption

sz encrypted.mp4 -k <key> -d -o decrypted.mp4 

With preview

sz encrypted.mp4 -k <key> -d -o decrypted.mp4 -p
  • Frames will be displayed as quickly as they are generated.
  • Audio will only start playing after the whole stream has been processed.

More Usage

Omit the -k argument to encrypt using randomly generated keyfiles.

Use the -m argument to specify mode: audio, video or full (default).

Use the -q flag for quiet mode.

Audio options

Use the -a argument to specify output audio format: mp3, wav (default), flac, etc.

Use the -l flag to use light encryption/decryption.

Use the -dn flag to apply denoising to the output audio.

Use the -pp flag to disable audio padding.

Video options

Use the -s argument to specify scramble method: rows (default), cols, full.

Use the -f flag to generate a different scramble order every frame.

Python Usage

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

Encryption

from sanzan import Sanzan

if __name__ == "__main__":
    s = Sanzan("original.mp4")
    s.set_password("1234")
    s.encrypt("encrypted.mp4")

Decryption

from sanzan import Sanzan

if __name__ == "__main__":
    s = Sanzan("encrypted.mp4")
    s.set_password("1234")
    s.decrypt("decrypted.mp4", preview=True, denoise=True)

sanzan's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

massreuy

sanzan's Issues

Containers such as MKV can have mismatched video and audio length

Possible solutions:

  • Pad audio to match video before generating keys
    • Perform comparison between self.mediainfo["duration"] and len(self.audio_raw) to check for mismatch
    • Should have no issue if video is shorter than audio, video will be padded by ffmpeg automatically
  • Convert to mp4 before generating keys
  • Generate audio key using more reliable methods (e.g. shared key)

TODO:

  • Always export keys unless specified otherwise with flag
  • Prioritize audio_length from keyfile over audio_length from audio track

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.