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

Experimental2 #10

Open
wants to merge 6 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ frame_list.txt
token.txt
*.mp4
*.spec
*.mov
libnvrtc-builtins.so.11.1
*.jpg
*.webm
Empty file modified 1.json
100644 → 100755
Empty file.
68 changes: 26 additions & 42 deletions 1.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def delete():
async def gpu(ctx):
await ctx.channel.send(content=f"bot run on {torch.cuda.get_device_name(0)}\nvram: {int(torch.cuda.get_device_properties('cuda').total_memory/1024/1024/1024)}GB")
@bot.command()
async def interpolate(ctx, arg1="--model",arg2="stable_e3", arg3="--discord", arg4="x"):
async def interpolate(ctx, arg1="--model",arg2="converted", arg3="--discord", arg4="x"):
wrong=False
ytdl=False
gifuse=False
ytdlurl="none"
model_name="stable_e3"
model_name="converted"
################ ################

if arg1=="--model":
Expand Down Expand Up @@ -92,7 +92,7 @@ async def interpolate(ctx, arg1="--model",arg2="stable_e3", arg3="--discord", ar
else:
ytdlurl="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
await ctx.channel.send(embed=embedVar)
filename=int(random()*1000000000)
filename=int(random()*100000000000000)
delete()

################ Downloading video ################
Expand All @@ -111,7 +111,7 @@ async def interpolate(ctx, arg1="--model",arg2="stable_e3", arg3="--discord", ar
gifuse=True
else:
gifuse=False
#


################ Using cv2 to get fps, width, height, frames number ################

Expand All @@ -123,33 +123,27 @@ async def interpolate(ctx, arg1="--model",arg2="stable_e3", arg3="--discord", ar
height = video.get(cv2.CAP_PROP_FRAME_HEIGHT) # float `height` round(width)
frames = video.get(cv2.CAP_PROP_FRAME_COUNT)
length = int(frames/fps)+2
if length>75:
length=75+7
bitrate = int(63200/length)
await message.edit(content=f"bitrate {bitrate}K/s, fps: {fps*2}, frames: {frames}\n")
except Exception as e:
await ctx.channel.send(content=f"error❌\n\n{e}")


################ Using ffmpeg to extract frames and audio ################

await message.edit(content=f"starting frame extraction🎞️\n")
if width<height:
os.system(f"ffmpeg -i 1.mkv -vf scale=256:{int(((height/width)*256)/8)*8} -pix_fmt rgb24 -t 75 frames/%6d.png")
else:
os.system(f"ffmpeg -i 1.mkv -vf scale={int(((width/height)*256)/8)*8}:256 -pix_fmt rgb24 -t 75 frames/%6d.png")
os.system("ffmpeg -i 1.mkv -pix_fmt rgb24 -t 75 1.wav")
await message.edit(content="finished frame extracting🎞️\n")

os.system(f"ffmpeg -i 1.mkv -vf scale=640:360 -pix_fmt rgb24 -t 80 frames/%6d.png")
os.system(f"ffmpeg -i 1.mkv -t 80 1.wav")
if fps==0.0:
fps=25
await message.edit(content="finished frame extracting🎞️\n")


################ using interpolation ################


await message.edit(content="interpolating✨\n")
try:
generate.interpolation(batch_size=10, img_fmt="png", torch_device="cuda", temp_img = f"frames", GPUid=0, GPUid2=False, fp16=False, modelp=f"models/{model_name}.pth")
generate.interpolation(batch_size=3, img_fmt="png", torch_device="cuda", temp_img = f"frames", GPUid=0, GPUid2=False, fp16=True, modelp=f"{model_name}.pth", TensorRT=True)
except Exception as e:
await ctx.channel.send(content=f"its oom? interpolation crashed❌\n{e}")
await message.edit(content="finished interpolation✨\n")
Expand All @@ -159,7 +153,7 @@ async def interpolate(ctx, arg1="--model",arg2="stable_e3", arg3="--discord", ar
if ossystem=='Linux':
print("skip")
else:
input_and_output.list_frame(dir="./frames", text_path="./")
input_and_output.listframe(dir="./frames", text_path="./")


await message.edit(content=f"starting encoding🗄️➡️🎞️\n")
Expand All @@ -177,35 +171,25 @@ async def interpolate(ctx, arg1="--model",arg2="stable_e3", arg3="--discord", ar
filemp4=discord.File(f"{filename}.gif")
await ctx.channel.send(file=filemp4, content="finished!✔️")





################ mp4 encoidng ################
if ossystem=='Linux':
try:
os.system(f'ffmpeg -r {fps*2} -pattern_type glob -i "frames/*.png" -i 1.wav -b:v {bitrate-69}k -pix_fmt yuv420p -c:v libx264 -preset veryslow -strict -2 -vf hqdn3d -fs 7.95M "{filename}.mp4"')#-preset veryslow
filemp4=discord.File(f"{filename}.mp4")
await ctx.channel.send(file=filemp4, content="finished!✔️")
except:
os.system(f'ffmpeg -r {fps*2} -pattern_type glob -i "frames/*.png" -b:v {bitrate-69}k -pix_fmt yuv420p -c:v libx264 -preset veryslow -strict -2 -vf hqdn3d -fs 7.95M "{filename}.mp4"')#-vf scale={int((width/height)*320)/8*8}:320:flags=lanczos
filemp4=discord.File(f"{filename}.mp4")
await ctx.channel.send(file=filemp4, content="finished!✔️")
torch.cuda.empty_cache()
os.remove(f"{filename}.mp4")
os.remove(f"{filename}.gif")
if os.path.isfile('1.wav'):
os.system(f'ffmpeg -r {fps*2} -pattern_type glob -i "frames/*.png" -i 1.wav -b:v {bitrate-69}k -pix_fmt yuv420p -c:v libsvt_vp9 -vf scale={int(width)}:{int(height)} -vf hqdn3d -qp 48 -preset 7 -b:a 69k -fs 7.50M "{filename}.webm"')#-preset veryslow
else:
os.system(f'ffmpeg -r {fps*2} -pattern_type glob -i "frames/*.png" -b:v {bitrate-69}k -pix_fmt yuv420p -c:v libsvt_vp9 -vf scale={int(width)}:{int(height)} -qp 48 -preset 7 -vf hqdn3d -b:a 69k -fs 7.50M "{filename}.webm"')#-vf scale={int((width/height)*320)/8*8}:320:flags=lanczos
filemp4=discord.File(f"{filename}.webm")
else:
try:
os.system(f'ffmpeg -f concat -safe 0 -r {fps*2} -i "frame_list.txt" -i 1.wav -b:v {bitrate-69}k -pix_fmt yuv420p -c:v h264_nvenc -preset hq -strict -2 -tune hq -vf hqdn3d -rc vbr -fs 7.95M "{filename}.mp4"')#-preset veryslow
filemp4=discord.File(f"{filename}.mp4")
await ctx.channel.send(file=filemp4, content="finished!✔️")
except:
os.system(f'ffmpeg -f concat -safe 0 -r {fps*2} -i "frame_list.txt" -b:v {bitrate-69}k -pix_fmt yuv420p -c:v h264_nvenc -preset hq -strict -2 -tune hq -vf hqdn3d -rc vbr -fs 7.95M "{filename}.mp4"')#-vf scale={int((width/height)*320)/8*8}:320:flags=lanczos
filemp4=discord.File(f"{filename}.mp4")
await ctx.channel.send(file=filemp4, content="finished!✔️")
torch.cuda.empty_cache()
os.remove(f"{filename}.mp4")
os.remove(f"{filename}.gif")
if os.path.isfile('1.wav'):
os.system(f'ffmpeg -f concat -safe 0 -r {fps*2} -i "frame_list.txt" -i 1.wav -b:v {bitrate-69}k -pix_fmt yuv420p -vf scale={int(width)}:{int(height)} -c:v h264_nvenc -preset hq -strict -2 -tune hq -vf hqdn3d -rc vbr -fs 7.95M "{filename}.mp4"')
else:
os.system(f'ffmpeg -f concat -safe 0 -r {fps*2} -i "frame_list.txt" -b:v {bitrate-69}k -pix_fmt yuv420p -c:v h264_nvenc -preset hq -strict -2 -vf scale={int(width)}:{int(height)} -tune hq -vf hqdn3d -rc vbr -fs 7.95M "{filename}.mp4"')
filemp4=discord.File(f"{filename}.mp4")


await ctx.channel.send(file=filemp4, content="finished!✔️")
os.remove(f"{filename}.mp4")
os.remove(f"{filename}.gif")
torch.cuda.empty_cache()

@bot.command()
async def ping(ctx):
Expand Down
2 changes: 2 additions & 0 deletions LICENSE
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

:)
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified common.py
100644 → 100755
Empty file.
20 changes: 20 additions & 0 deletions conv_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import torch
import numpy as np
import torchvision
import os
from model.cain import CAIN
os.system("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64")
print("Building model: CAIN")
model = CAIN(depth=3)
model = torch.nn.DataParallel(model).to("cuda")
checkpoint = torch.load("1.pth")
model.load_state_dict(checkpoint['state_dict'])
model.cuda().cpu()
model.eval()
try:
state_dict = model.module.state_dict()
except AttributeError:
state_dict = model.state_dict()

torch.save(state_dict, 'temp_conv.pth')
os.system("python3 trt.py")
Empty file modified credits.py
100644 → 100755
Empty file.
92 changes: 46 additions & 46 deletions form.ui
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>759</width>
<width>755</width>
<height>521</height>
</rect>
</property>
Expand Down Expand Up @@ -475,43 +475,11 @@
<string>Interpolation factor</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_4">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>102</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>half precision</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_7">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>102</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>multi gpu mode</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label_12">
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<y>70</y>
<width>102</width>
<height>20</height>
</rect>
Expand All @@ -524,7 +492,7 @@
<property name="geometry">
<rect>
<x>80</x>
<y>130</y>
<y>70</y>
<width>141</width>
<height>20</height>
</rect>
Expand All @@ -540,7 +508,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<y>100</y>
<width>41</width>
<height>21</height>
</rect>
Expand All @@ -553,7 +521,7 @@
<property name="geometry">
<rect>
<x>80</x>
<y>160</y>
<y>100</y>
<width>141</width>
<height>20</height>
</rect>
Expand All @@ -563,7 +531,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<y>130</y>
<width>102</width>
<height>20</height>
</rect>
Expand All @@ -576,7 +544,7 @@
<property name="geometry">
<rect>
<x>80</x>
<y>190</y>
<y>130</y>
<width>139</width>
<height>20</height>
</rect>
Expand Down Expand Up @@ -671,13 +639,13 @@
<property name="geometry">
<rect>
<x>10</x>
<y>220</y>
<width>211</width>
<height>17</height>
<y>160</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>resume (expeprimental work only for 2x)</string>
<string>TRT</string>
</property>
</widget>
</widget>
Expand Down Expand Up @@ -720,14 +688,14 @@
<widget class="QPushButton" name="pushButton_6">
<property name="geometry">
<rect>
<x>0</x>
<x>-10</x>
<y>0</y>
<width>171</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>save settings look at github repo</string>
<string>save settings</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_7">
Expand All @@ -740,7 +708,39 @@
</rect>
</property>
<property name="text">
<string>load</string>
<string>load (beta)</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_4">
<property name="geometry">
<rect>
<x>790</x>
<y>120</y>
<width>102</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>half precision</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_7">
<property name="geometry">
<rect>
<x>950</x>
<y>370</y>
<width>102</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>multi gpu mode</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</widget>
Expand Down
Loading