Giter Site home page Giter Site logo

downscaler's Introduction

Downscaler

Uses ffmpeg to process a directory tree of videos and downscale them to 720p with a high compression ratio, e.g. for putting them on a kid's tablet. (this can compress them to less than 1/4 of the original size!)

Assumes you have ffmpeg installed an in your path. Ffmpeg is doing all the real work here!

I'm sharing this mostly s I think it's a nice example of using rust where once I might have written a convoluted shell script.

It also makes a nice example rust program - if people are scared by all the "rust is complex" stuff - in many cases it really isn't. This code doesn't care about threads or async or the borrow checker or anything - it's very simple procedural code. All error handling is pretty transparent.

(yes, for non-trivial rust development you will need to understand the borrow checker - but I'm just pointing out that for many specific areas of code, it won't be relevant)

Error handling

Everything returns a Result<T,E> - in this case implemented by Anyhow::Result<T> which basically means "return either a valid result type T or an Error type E". The caller must handle the error - to not handle it is a compilation error.

There are many many function calls that end with ? - this is rust syntax for shortcut error handling. Code like downscale(...)? calls downscale and if it returns an Error, immediately exit this function returning an Error - otherwise it unwraps the return value of downscale (in this case the return value is () - that is to say, nothing). This is the standard Rust approach to error handling without exceptions.

This means that without any real code on my part, many many errors will be trapped and logged. If navigating the directory tree meets a directory I can't read, then some I/O call will return an Error, which will bubble up to main and be displayed.

libraries

I have a few standard libraries I like to use for command-line tools:

  • anyhow - makes simple error handling simple
  • clap - command-line parsing
  • log - standard rust log facade
  • env_logger - a simple logger with configuration through environment variables

logging

Specify log level by setting RUST_LOG e.g.:

RUST_LOG=debug cargo run

downscaler's People

Contributors

kornysietsma avatar

Watchers

 avatar  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.