GithubHelp home page GithubHelp logo

additive / bulk-optimization Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 4.65 MB

Iterate over a directory and perform compression, resizing and formatting for optimal web capabilities.

License: MIT License

Python 100.00%
python ffmpeg compression optimization bulk pillow moviepy imageio wand numpy

bulk-optimization's Introduction

Bulk Optimization

Convert and optimize any file in a directory and their children's into web compatible formats, fast.

Suggestions and optimizations are highly appreciated! This is in the very beginning and should help companies produces web save content without the pain.

preview

Usage

Use python3 cli.py --help to view the below

usage: cli.py [-h] [-v] [--license] [--slugify [BOOL]]
              [--skip-existing [BOOL]] [--gif [BOOL]] [--copy [BOOL]]
              [--image-formats LIST [LIST ...]]
              [--video-formats LIST [LIST ...]] [--thumbnail [BOOL]]
              [--vtt [BOOL]]
              [input] [output]

Iterate over a directory and perform compression, resizing and formatting
for optimal web capabilities.

positional arguments:
  input                 folder to iterate over (default: current dir)
  output                destination folder (default: `-copy` added to input
                        folder)

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --license             show program's license
  --slugify [BOOL]      slugify filenames (default: True)
  --skip-existing [BOOL]
                        skip existing processed files (default: True)
  --gif [BOOL]          process GIF´s (default: False)
  --copy [BOOL]         copy not processable files (default: False)
  --image-formats LIST [LIST ...]
                        image types to convert to (increases the execution
                        time)
  --video-formats LIST [LIST ...]
                        video types to convert to (increases the execution
                        time)
  --thumbnail [BOOL]    create thumbnails from video files (default: False)
  --vtt [BOOL]          create video progress thumbnails (default: False)

examples:

python3 cli.py --skip-existing false --copy true --image-formats webp ./videos
python3 cli.py --skip-existing false --video-formats webm ./videos
python3 cli.py --thumbnail --vtt --video-formats mp4 webm ./videos
python3 cli.py --video-formats mp4 webm ./videos ./go/here

A = required [A] = optional [A ...]  = optional list

What happens?

Video files

Video files like mov or mp4 will be converted and optimized. Depending on what option is set, those files will be generated:

  • MP4: --video-formats mp4
  • WEBM: --video-formats webm
  • Thumb: --thumbnail
  • VTT: --vtt
    • JPG: a sprite containing thumbnails from the video based on a value
    • VTT: a file where each sprite frame is listed so video players can make use of them

Images

All known images will be optimized. Depending on what option is set, those files will be generated:

  • PNG: --image-format: png
  • JPG: --image-format: jpg
  • webp: --image-format: webp

If you choose to optmize png and jpg, the script will look for PNG´s without a transparent background and convert them to JPG for better optimization.

GIF

Possibly reducing the file size of a GIF, doesn't need to be the case everytime. Use --gifs to enable this generator.

Other files

If you choose --copy the generator will copy all unknown file formats to the output dir, so that at the end you have two directories that are likely the same but optimized.

Development

  1. Create a virtual env with virtualenv and install all requirements
  2. Run python3 cli.py /some/dir/to/test/with/many/files

Next

  • Create single executable
  • Create UI? (for people that are not familiar with the terminal)
  • Add options (the hole process for this should be replaced)
    • Override option to not skip existing files
    • No thumbnail generation
    • No JPEG/PNG only Webp
    • No mp4 only Webm
    • Compression ratio
  • Set max height for VTT image and split it into multiple files

Reads

bulk-optimization's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bulk-optimization's Issues

Support single video files

Would be great if this could support single file optimization instead of only directories. So a single mov could me processed to mp4.

This would require making the loop an if case and make the args required for the specified file type to optimize.

Assertation error

Might be something with greenlet.

Processing file 166 of 289
>>> /Users/marvinheilemann/Desktop/Origin_Screencasts_cleared/Minitools-VertikalerCursor/Minitools-VertikalerCursor.mp4
<<< /Users/marvinheilemann/Desktop/Origin_Screencasts_cleared-copy/Minitools-VertikalerCursor/Minitools-VertikalerCursor…
[INFO] [video] Filename: Minitools-VertikalerCursor.mp4
[INFO] [video] Filesize: 6.6 MB
[NEXT] [video] [mp4] Starting compression...
  0%|                                                                                                                                                  | 0/162.05 [00:00<?, ?it/s]Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/utils/progress.py", line 40, in _do_watch_progress
    handler(key, value)
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/utils/progress.py", line 85, in handler
    bar.update(time - bar.n)
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/venv/lib/python3.7/site-packages/tqdm/std.py", line 1200, in update
    self.refresh(lock_args=self.lock_args)
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/venv/lib/python3.7/site-packages/tqdm/std.py", line 1304, in refresh
    self.display()
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/venv/lib/python3.7/site-packages/tqdm/std.py", line 1428, in display
    self.sp(self.__repr__() if msg is None else msg)
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/venv/lib/python3.7/site-packages/tqdm/std.py", line 1058, in __repr__
    return self.format_meter(**self.format_dict)
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/venv/lib/python3.7/site-packages/tqdm/std.py", line 482, in format_meter
    charset=Bar.ASCII if ascii is True else ascii or Bar.UTF)
  File "/Users/marvinheilemann/Development/Scripts/Bulk Video Converter/venv/lib/python3.7/site-packages/tqdm/std.py", line 146, in __init__
    assert 0 <= frac <= 1
AssertionError
2019-12-04T12:28:29Z <Greenlet at 0x10749ca70: _do_watch_progress('/var/folders/yz/pntm5xh11mjb3ckzvf10ql180000gn/T/, <gevent._socket3.socket object, fd=8, family=1, ty, <function show_progress.<locals>.handler at 0x1076)> failed with AssertionError

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.