Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update encoder.py #54

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1 @@
<p align="center">
<img src="./LOCAL/Wavy_Lst-14_Single-06.jpg" alt="VideoConvertor poster">
</p>
<h1 align="center">
<b>ᴠɪᴅᴇᴏ ᴄᴏɴᴠᴇʀᴛᴏʀ</b>
</h1>


<p align="left"><a href="https://github.com/vasusen-code/videoconvertor"><img src="https://github-readme-stats.vercel.app/api/pin?username=vasusen-code&show_icons=true&theme=dracula&hide_border=true&repo=VideoConvertor"></a></p>

`Main branch` - For personal use
<p align="left">
<a href="https://github.com/vasusen-code/VIDEOconvertor/tree/main"> <img src="https://img.shields.io/badge/Github-main%20branch-blueviolet?style=for-the-badge&logo=github" width="220""/></a>
</p>

`Public branch` - For your channel
<p align="left">
<a href="https://github.com/vasusen-code/VIDEOconvertor/tree/public"> <img src="https://img.shields.io/badge/Github-public%20branch-blueviolet?style=for-the-badge&logo=github" width="220""/></a>
</p>

`Telegran Channel` - DroneBots
<p><a href="https://t.me/DroneBots"> <img src="https://img.shields.io/badge/Telegram-Join%20Channel-gold?style=for-the-badge&logo=telegram" width="220""/></a></p>

# Main branch
Main branch is to deploy a bot for your `personal` use only. Deploy from `public` branch if you need bot for your channel.

VARIABLES required are:

* `API_ID`

* `API_HASH`

* `BOT_TOKEN`

* `BOT_UN` - Username of yout Bot.

# Deploy (🌟Star the repo)

Deploy your bot on `heroku`

`Warning` - There are two different branches available, go to [public](github.com/vasusen-code/videoconvertor) branch if you need bot for your `channel`.

`Fork and Click on Deploy in your fork`
<p><a href="https://heroku.com/deploy"> <img src="https://img.shields.io/badge/Deploy%20To%20Heroku-black?style=for-the-badge&logo=heroku" width="250""/></a></p>

`Alternate way:`

If you are facing any problem while deploying through heroku button, just fork and `deploy manually` by creating a new app in heroku.

Add these buildpacks if you are deploying manually (Read tutorial) :

- `https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git`
- `heroku/python`

<p><a href="https://telegra.ph/Manual-Deploy-Video-Convertor-12-31"> <img src="https://img.shields.io/badge/Manual%20Deploy%20Tutorial-grey?style=for-the-badge&logo=telegraph" width="250""/></a></p>

Deploy your bot on `Okteto`

[![Develop on Okteto](https://okteto.com/develop-okteto.svg)](https://cloud.okteto.com)

LICENSE:

[![License](https://www.gnu.org/graphics/gplv3-127x51.png)](LICENSE)

Don't deploy this branch!!
36 changes: 17 additions & 19 deletions main/plugins/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# License can be found in < https://github.com/vasusen-code/VIDEOconvertor/blob/public/LICENSE> .

import asyncio, time, subprocess, re, os, ffmpeg
import asyncio, time, subprocess, re, os

from datetime import datetime as dt
from telethon import events
Expand All @@ -24,7 +24,7 @@
from .. import Drone, BOT_UN

from LOCAL.localisation import SUPPORT_LINK, JPG, JPG2, JPG3
from LOCAL.utils import ffmpeg_progress
from LOCAL.utils import ffmpeg_progress, ffmpeg_exec_progress

async def compress(event, msg, ffmpeg_cmd=0, ps_name=None):
Drone = event.client
Expand Down Expand Up @@ -63,38 +63,36 @@ async def compress(event, msg, ffmpeg_cmd=0, ps_name=None):
name = '__' + dt.now().isoformat("_", "seconds") + ".mp4"
os.rename(n, name)
await edit.edit("Extracting metadata...")
vid = ffmpeg.probe(name)
codec = vid['streams'][0]['codec_name']
hgt = video_metadata(name)["height"]
wdt = video_metadata(name)["width"]
if ffmpeg_cmd == 2:
if hgt == 360 or wdt == 640:
await edit.edit("Fast compress cannot be used for this media, try using HEVC!")
os.rmdir("encodemedia")
return
if ffmpeg_cmd == 3:
if codec == 'hevc':
await edit.edit("The given video is already in H.265 codec.")
os.rmdir("encodemedia")
return
if ffmpeg_cmd == 4:
if codec == 'h264':
await edit.edit("The given video is already in H.264 codec.")
os.rmdir("encodemedia")
return
FT = time.time()
progress = f"progress-{FT}.txt"
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" None """{out}""" -y'
cmd = "Join @MaheshChauhan"
if ffmpeg_cmd == 1:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -preset ultrafast -vcodec libx265 -crf 28 -acodec copy -c:s copy """{out}""" -y'
elif ffmpeg_cmd == 2:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -c:v libx265 -crf 22 -preset ultrafast -s 640x360 -c:a copy -c:s copy """{out}""" -y'
cmd = [
"ffmpeg", "-hide_banner", "-loglevel", "quiet", "-progress", progress,
"-i", name,
"-c:v", "libx265", "-crf 22", "-preset", "ultrafast", "-vf", "scale=640:trunc(ow/a/2)*2",
"-c:a", "copy",
"-c:s", "copy",
out, "-y"
]
elif ffmpeg_cmd == 3:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -preset ultrafast -vcodec libx265 -crf 20 -acodec copy -c:s copy """{out}""" -y'
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -preset ultrafast -vcodec libx265 -acodec copy -c:s copy """{out}""" -y'
elif ffmpeg_cmd == 4:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -preset ultrafast -vcodec libx264 -crf 20 -acodec copy -c:s copy """{out}""" -y'
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -preset ultrafast -vcodec libx264 -acodec copy -c:s copy """{out}""" -y'
try:
await ffmpeg_progress(cmd, name, progress, FT, edit, ps_name)
if ffmpeg_cmd != 2:
await ffmpeg_progress(cmd, name, progress, FT, edit, ps_name)
else:
await ffmpeg_exec_progress(cmd, name, progress, FT, edit, ps_name)
except Exception as e:
os.rmdir("encodemedia")
print(e)
Expand Down
50 changes: 39 additions & 11 deletions main/plugins/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# License can be found in < https://github.com/vasusen-code/VIDEOconvertor/blob/public/LICENSE> .

import asyncio, time, subprocess, re, os, ffmpeg
import asyncio, time, subprocess, re, os

from datetime import datetime as dt
from telethon import events
Expand All @@ -24,7 +24,7 @@
from .. import Drone, BOT_UN

from LOCAL.localisation import SUPPORT_LINK, JPG, JPG2, JPG3
from LOCAL.utils import ffmpeg_progress
from LOCAL.utils import ffmpeg_exec_progress

async def encode(event, msg, scale=0):
Drone = event.client
Expand Down Expand Up @@ -61,9 +61,9 @@ async def encode(event, msg, scale=0):
name = '__' + dt.now().isoformat("_", "seconds") + ".mp4"
os.rename(n, name)
await edit.edit("Extracting metadata...")
vid = ffmpeg.probe(name)
hgt = int(vid['streams'][0]['height'])
wdt = int(vid['streams'][0]['width'])
vid = video_metadata(name)
hgt = int(vid['height'])
wdt = int(vid['width'])
if scale == hgt:
os.rmdir("encodemedia")
return await edit.edit(f"The video is already in {scale}p resolution.")
Expand All @@ -85,17 +85,45 @@ async def encode(event, msg, scale=0):
return await edit.edit(f"The video is already in {scale}p resolution.")
FT = time.time()
progress = f"progress-{FT}.txt"
cmd = ''
cmd = ["Join @MaheshChauhan"]
if scale == 240:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -s 426x240 -crf 18 -c:a libopus -ac 2 -ab 128k -c:s copy """{out}""" -y'
cmd = [
"ffmpeg", "-hide_banner", "-loglevel", "quiet", "-progress", progress,
"-i", name,
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-preset", "faster", "-vf", "scale=426:trunc(ow/a/2)*2", "-crf", "22",
"-c:a", "libopus", "-ac", "2", "-ab", "128k",
"-c:s", "copy",
out, "-y"
]
elif scale == 360:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -s 640x360 -crf 20 -c:a libopus -ac 2 -ab 128k -c:s copy """{out}""" -y'
cmd = [
"ffmpeg", "-hide_banner", "-loglevel", "quiet", "-progress", progress,
"-i", name,
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-preset", "faster", "-vf", "scale=640:trunc(ow/a/2)*2", "-crf", "22",
"-c:a", "libopus", "-ac", "2", "-ab", "128k",
"-c:s", "copy",
out, "-y"
]
elif scale == 480:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -s 854x480 -crf 23 -c:a libopus -ac 2 -ab 128k -c:s copy """{out}""" -y'
cmd = [
"ffmpeg", "-hide_banner", "-loglevel", "quiet", "-progress", progress,
"-i", name,
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-preset", "faster", "-vf", "scale=854:trunc(ow/a/2)*2", "-crf", "22",
"-c:a", "libopus", "-ac", "2", "-ab", "256k",
"-c:s", "copy",
out, "-y"
]
elif scale == 720:
cmd = f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{name}""" -c:v libx264 -pix_fmt yuv420p -preset ultrafast -s 1280x720 -crf 27 -c:a libopus -ac 2 -ab 128k -c:s copy """{out}""" -y'
cmd = [
"ffmpeg", "-hide_banner", "-loglevel", "quiet", "-progress", progress,
"-i", name,
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-preset", "faster", "-vf", "scale=1280:trunc(ow/a/2)*2", "-crf", "22",
"-c:a", "libopus", "-ac", "2", "-ab", "256k",
"-c:s", "copy",
out, "-y"
]
try:
await ffmpeg_progress(cmd, name, progress, FT, edit, '**ENCODING:**')
await ffmpeg_exec_progress(cmd, name, progress, FT, edit, '**ENCODING:**')
except Exception as e:
os.rmdir("encodemedia")
print(e)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cryptg
ethon==1.3.8 #for VC
ffmpeg-python
tgcrypto