# Colab Notebook to Compress Videos using HandBrake

**URL:** <https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456>\
**Category:** Tools & Scripts\
**Tags:** tips-tricks\
**Created:** [September 2, 2020, 3:26pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456 "2020-09-02T15:26:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skghd](https://onehack.st/user_avatar/onehack.st/skghd/32/47234_2.png) [@Skghd](https://onehack.st/u/Skghd)\
**Post date:** [September 2, 2020, 3:26pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/1 "2020-09-02T15:26:26Z")

</div>

# 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](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/SKGHD/Handy/blob/master/HandBrakeCLI_Colab.ipynb)

# 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](https://myaccount.google.com/apppasswords) in order for the feature to work.
  

Read more about app specific passwords here: [Google Account Help](https://support.google.com/accounts/answer/185833?hl=en)

# 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](https://github.com/SKGHD/Handy) 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 😅)

- 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](https://onehack.st/u/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](https://onehack.st/u/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. 😃

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](http://1Hack.us) is not responsible for any law infringement caused by the users of this material.

---

<div class="post-metadata">

**Author:** ![dheeth](https://onehack.st/user_avatar/onehack.st/dheeth/32/49096_2.png) [@dheeth](https://onehack.st/u/dheeth)\
**Post date:** [September 2, 2020, 6:49pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/2 "2020-09-02T18:49:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Skghd](https://onehack.st/user_avatar/onehack.st/skghd/32/47234_2.png) [@Skghd](https://onehack.st/u/Skghd)\
**Post date:** [September 3, 2020, 1:55am UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/3 "2020-09-03T01:55:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dheeth](https://onehack.st/user_avatar/onehack.st/dheeth/32/49096_2.png) [@dheeth](https://onehack.st/u/dheeth)\
**Post date:** [September 3, 2020, 5:48am UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/4 "2020-09-03T05:48:07Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![dillu\_dada](https://onehack.st/user_avatar/onehack.st/dillu_dada/32/26385_2.png) [@dillu\_dada](https://onehack.st/u/dillu_dada)\
**Post date:** [September 3, 2020, 10:33am UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/5 "2020-09-03T10:33:29Z")

</div>

> [@Skghd](#):
>
> d drive using rclone or with the google’s own gdrive mount method, though I would

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

---

<div class="post-metadata">

**Author:** ![Adnan\_Catper](https://onehack.st/user_avatar/onehack.st/adnan_catper/32/18110_2.png) [@Adnan\_Catper](https://onehack.st/u/Adnan_Catper)\
**Post date:** [September 3, 2020, 2:14pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/6 "2020-09-03T14:14:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arun\_Singham](https://onehack.st/user_avatar/onehack.st/arun_singham/32/49064_2.png) [@Arun\_Singham](https://onehack.st/u/Arun_Singham)\
**Post date:** [September 3, 2020, 2:18pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/7 "2020-09-03T14:18:12Z")

</div>

same question…

---

<div class="post-metadata">

**Author:** ![dillu\_dada](https://onehack.st/user_avatar/onehack.st/dillu_dada/32/26385_2.png) [@dillu\_dada](https://onehack.st/u/dillu_dada)\
**Post date:** [September 4, 2020, 8:52am UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/8 "2020-09-04T08:52:19Z")

</div>

somebody plz tell

---

<div class="post-metadata">

**Author:** ![Skghd](https://onehack.st/user_avatar/onehack.st/skghd/32/47234_2.png) [@Skghd](https://onehack.st/u/Skghd)\
**Post date:** [September 4, 2020, 4:41pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/9 "2020-09-04T16:41:07Z")

</div>

**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/](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:

```auto
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 🙂 Sorry for late reply guys

Read more one rclone configuration here:

> [https://rclone.org/docs/](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](https://github.com/Cloudbox/Cloudbox/wiki/Google-Drive-API-Client-ID-and-Client-Secret)

---

<div class="post-metadata">

**Author:** ![suv77m](https://onehack.st/user_avatar/onehack.st/suv77m/32/57708_2.png) [@suv77m](https://onehack.st/u/suv77m)\
**Post date:** [September 30, 2020, 11:04am UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/10 "2020-09-30T11:04:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![truemate](https://onehack.st/user_avatar/onehack.st/truemate/32/86596_2.png) [@truemate](https://onehack.st/u/truemate)\
**Post date:** [April 17, 2021, 11:25pm UTC](https://onehack.st/t/colab-notebook-to-compress-videos-using-handbrake/104456/11 "2021-04-17T23:25:06Z")

</div>

nice share bro… you Rock
