Colab Notebook to Compress Videos using HandBrake

Description

Compress videos with HandBrake CLI online in Google Colab. Get email notification when tasks finish running. You can use it for a single file or for a directory with lots of files.
As we know any process in Colab can only run for 90 mins after closing the browser so in case of a batch convert/compress task it can remember the files which have already been processed so you can re-run the task again another time to finish the task (basically resume support).

Open In Colab

Requirements

  • Basic knowledge of how to use colab notebooks and rclone.
  • To use email notifications only gmail id can be used and use an **app specfic password** Google account settings in order for the feature to work.

  • Read more about app specific passwords here: Google Account Help

    Instructions/Installation/Usage

    • Mount cloud drive using rclone or with the google’s own gdrive mount method, though I would recommend rclone method as the latter could be unreliable sometimes.
    • Copy path to the Source file/directory with the help of the file browser.
    • Paste the copied path to the SOURCE text-field in the HandBrake Cell.
    • Paste path to the Destination in DESTINATION text-field. (Destination drive must be mounted beforehand)
    • For email notifications give your gmail id and app specific password and tick the checkbox.

    Bugs so far

    None discovered yet. Please mention here if you find any.

    Note

    • If you have security concerns you can check the source code of the notebook here in my github repo and off-course you can skip this step if you don’t feel safe using it.

    Words of thanks

    (skip this if you don’t want to get bored LOL :sweat_smile:)

    • Firstly I would like to thank OneHack and all its wonderful members for sharing amazing content. I’ve learnt a lot from here and this small project is a testimony to that.

    • Few months ago FlashyFlash posted a google colab notebook (oneclickrun) and I was amazed by what all it could do so I wanted to make my own notebooks in colab but I didn’t know how to code, specifically Python.

    • Few days later after that SaM posted a free udemy course link which was the top rated course “Automate the Boring Stuff with Python Programming” from where I learnt Python programming. :smiley:

    This is my first project after learning Python (and also my first post). So special thanks to FlashyFlash and SaM for providing such awesome resources.

    Disclaimer

    This post is provided to help you and for personal use only. Sharing the content of your subscribed materials and the other purchased content is strictly prohibited under 1Hack Terms of Use.

    By using this provided material the website 1Hack.us is not responsible for any law infringement caused by the users of this material.

    13 Likes

    bro there’s a mistake in your code, search for “f_name = fileName(currentPath)”

    Here, it will accept SOURCE instead of currentPath, otherwise it doesn’t run and shows error. Please correct it because currentPath is setup later and hence can’t be used before defining it

    1 Like

    Hey man, many thanks for pointing it out .I fixed it. It should be the “fileName(path)” instead.

    Oops Ok, I was also trying it and my file was same as before after 30 minutes of conversion, Let me try it with fileName(path)

    what has to be done in upload rclone.config???

    1 Like

    thanks this is very useful and do share more colab scripts.

    can yiu make all in one ffmpeg colab notebook?
    you can add code for converting from video to audio mp3, converting a video to x265/x264, converting bluray to x264/x265, trimming audio video, taking screenshots from videos etc.
    that is going to be massive hit for sure. take ur time

    1 Like

    same question…

    1 Like

    somebody plz tell

    rclone is just a tool which allows you to transfer files between cloud drives( your team drive, google drive, onedrive or Mega.nz etc).
    In Colab we need it to mount our cloud drives as a file system so that handbrake can read and write files to the drive.
    In order to use it you need to first configure on your local machine which will generate a “rclone.conf” file. You only need to set it up once.

    Rclone download link = https://rclone.org/downloads/

    A short tutorial for windows users for configuring rclone:

    1. Extract the downloaded file “rclone-v1.53.0-windows-amd64.zip”
    2. Open command line in the extracted folder by typing “cmd” in the address bar.
    3. type rclone config . It should output the below text:
    No remotes found - make a new one
    n) New remote
    r) Rename remote
    c) Copy remote
    s) Set configuration password
    q) Quit config
    n/r/c/s/q> n
    
    1. Press n and hit enter to create a new remote.
      (For this example I’ll configuring for a google drive)
    2. type in any name for the remote . lets say “mygdrive” , hit enter
    3. Now a list of supported cloud storage providers will show up . Choose a number associated with your cloud drive. Here google drive is 13 so we type 13 and hit enter.
    4. It’ll now ask for Client ID: press enter to skip this for now to use default
    5. Client secret: skip by hitting enter
    6. Scope : press 1 for Full access all files, excluding Application Data Folder.
    7. root folder id : skip by hitting enter
    8. service_account_file : skip
    9. Edit advanced config? : skip
    10. Use auto config : press enter, it’ll open up google login page in your browser to give access to rclone.
    11. Now after giving access , it’ll now ask “Configure this as a team drive?”
      If you want to use it with your team drive type “y” otherwise hit enter and it’ll skip. I hit “y” for now.
    12. Enter a team drive ID: It’ll now show list of team drives. choose your team drive and enter its number.
      after that it’ll show the configuration. hit enter to confirm.

    That’s it your team drive is configured to use it with rclone anywhere. You need to repeat the above steps to configure multiple cloud drives and it’ll get saved to rclone.conf

    On Windows it is located in :

    C:\Users<USERNAME>.config\rclone\rclone.conf
    This is the file you need to upload in the 2nd cell :slight_smile: Sorry for late reply guys

    Read more one rclone configuration here:

    https://rclone.org/docs/

    Also if you are interested in having your own client_id (I’ve heard that it improves performance but I haven’t noticed anything myself ) :

    https://github.com/Cloudbox/Cloudbox/wiki/Google-Drive-API-Client-ID-and-Client-Secret

    1 Like
    OSError                                   Traceback (most recent call last)
    
    <ipython-input-3-656e6abe01aa> in <module>()
         84     pass
         85   else:
    ---> 86     with open((SOURCE+'processed_db.txt'), 'w') as fb:
         87       fb.write("Do not delete this file until all files have been processed!\n")
         88       fb.close()
    
    OSError: [Errno 30] Read-only file system:
    

    getting this error while trying to convert a shared folder.

    Friendly Websites

    https://igg-games.com/ Play FREE Games! ettvdl.com https://crackingpatching.com/ https://glodls.to/ https://prostylex.org/ https://haxnode.com/ https://freedownloadae.com/ https://www.novahax.com/ freecoursesonline.me ftuapps.dev