Skip to content

Commit

Permalink
Added a readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
MementoMori11723 committed Jan 23, 2024
1 parent 907fcca commit 3115543
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 174 deletions.
6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ verify_ssl = true
name = "pypi"

[packages]
streamlit = "*"
opencv-python = "*"
pillow = "*"
opencv-python = "==4.9.0.80"
streamlit = "==1.30.0"
pillow = "==10.2.0"

[dev-packages]

Expand Down
4 changes: 2 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# GIFNETOR

A gif creation appliction that takes input as a video files like mp4, mov, mvk and converts it into a gif image.

"How is it possiable ?", you ask.

By opening the video file and reading all the frames inside the file, then convering those high level color images to low level color images (since gif uses low level images) and then writing those images into a gif file, these files are stored in uploads folder.

And there you go, you have successfully converted a video to an image/gif.

> Note : The converted image will larger then the video file. Since gif files have limited colors compared to a video.
## Requirments

1. opencv-python
2. streamlit
3. pillow

## Code

```python
from PIL import Image
import streamlit as st
import cv2
import os

def main():
st.set_page_config(page_title="Gifnetor",page_icon=":vhs:",layout="centered")
st.title("Video to Gif converter")
video = st.file_uploader("Upload Video",type=["mp4","mov","mkv"],accept_multiple_files=False)
path = os.path.join("uploads/",video.name) if video else None
if video:
with open(path,"wb") as upload :
upload.write(video.getbuffer())
st.success("Uploaded successfully")
button = st.button("Convert to Gif")
if button:
output = convert(path)
st.image(output)
st.download_button("Download Gif",data=open(output,"rb"),file_name="output.gif",mime="image/gif")
reset = st.button("Remove Files")
if reset:
if os.path.exists(path) and os.path.exists(os.path.join("uploads/","output.gif")):
os.remove(path)
os.remove(os.path.join("uploads/","output.gif"))
st.warning(f"Files were removed")
else:
st.info(f"No Files were removed")

def convert(filepath):
cap = cv2.VideoCapture(filepath)
frames = []
if not cap.isOpened():
st.error("Error occured while opening the file")
exit()
while True:
ret,frame = cap.read()
if not ret:break
pil_image = Image.fromarray(cv2.cvtColor(frame,cv2.COLOR_BGR2RGB))
pil_image = pil_image.resize((pil_image.width // 4, pil_image.height // 4))
frames.append(pil_image)
gif_path = os.path.join("uploads/","output.gif")
frames[0].save(gif_path,save_all=True,append_images=frames[1:],loop=0,optimize=True,quality=50,duration=0)
cap.release()
return gif_path

if __name__ == "__main__":
main()
```

to Run this locally `streamlit Run app.py`

## Output

output 1
![output 1](images/Output-1.webp)

output 2
![output 2](images/Output-2.webp)
3 changes: 0 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ def main():
else:
st.info(f"No Files were removed")




def convert(filepath):
cap = cv2.VideoCapture(filepath)
frames = []
Expand Down
Binary file added images/Output-1.webp
Binary file not shown.
Binary file added images/Output-2.webp
Binary file not shown.
169 changes: 3 additions & 166 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,166 +1,3 @@
altair==5.2.0
anyio==4.2.0
argcomplete==2.0.0
arrow==1.3.0
attrs==23.2.0
Beaker==1.12.1
beautifulsoup4==4.12.2
binaryornot==0.4.4
blinker==1.7.0
blivet==3.8.2
blivet-gui==2.4.2
Brlapi==0.8.5
cachetools==5.3.2
certifi==2023.11.17
cffi==1.15.1
chardet==5.2.0
charset-normalizer==3.2.0
click==8.1.3
contourpy==1.2.0
cookiecutter==2.5.0
cryptography==41.0.3
cupshelpers==1.0
cycler==0.12.1
dasbus==1.7
dbus-python==1.3.2
decorator==4.4.2
distlib==0.3.8
distro==1.8.0
dnf==4.18.2
evdev==1.6.1
fedora-third-party==0.10
ffmpeg-python==0.2.0
file-magic==0.4.0
filelock==3.12.2
Flask==3.0.0
flet==0.19.0
flet-core==0.19.0
flet-runtime==0.19.0
fonttools==4.47.2
fros==1.1
Frozen-Flask==1.0.1
future==0.18.3
gitdb==4.0.11
GitPython==3.1.41
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
humanize==3.13.1
idna==3.4
imageio==2.33.1
imageio-ffmpeg==0.4.9
importlib-metadata==7.0.1
itsdangerous==2.1.2
Jinja2==3.1.3
joblib==1.3.2
jsonschema==4.21.0
jsonschema-specifications==2023.12.1
kiwisolver==1.4.5
langtable==0.0.64
legendary-gl==0.20.34
libcomps==0.1.20
libdnf==0.72.0
lutris==0.5.14
lxml==4.9.3
Mako==1.2.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.8.2
mdurl==0.1.2
moddb==0.8.1
moviepy==1.0.3
nftables==0.1
nltk==3.8.1
numpy==1.26.3
oauthlib==3.2.2
olefile==0.46
opencv-python==4.9.0.80
packaging==23.1
pandas==2.1.4
Paste==3.5.3
pexpect==4.8.0
pid==2.2.3
pillow==10.2.0
pipenv==2023.11.17
platformdirs==4.1.0
ply==3.11
productmd==1.38
proglog==0.1.10
protobuf==4.25.2
ptyprocess==0.7.0
pwquality==1.4.5
pyarrow==14.0.2
pycairo==1.25.1
pycparser==2.20
pycrypto==2.6.1
pycups==2.0.1
pycurl==7.45.2
pydeck==0.8.1b0
pyenchant==3.2.2
Pygments==2.17.2
PyGObject==3.46.0
pykickstart==3.48
pyOpenSSL==23.2.0
pyparsing==3.1.1
pyparted==3.13.0
pypng==0.20220715.0
pypresence==4.3.0
PyQt5==5.15.9
PyQt5-sip==12.12.2
pyrate-limiter==3.1.0
PySocks==1.7.1
python-augeas==1.1.0
python-dateutil==2.8.2
python-meh==0.51
python-slugify==8.0.1
pytz==2023.3.post1
pyudev==0.24.1
pyxdg==0.27
PyYAML==6.0.1
qrcode==7.4.2
referencing==0.32.1
regex==2023.12.25
repath==0.9.0
reportlab==4.0.4
requests==2.28.2
requests-file==1.5.1
requests-ftp==0.3.1
rich==13.7.0
rpds-py==0.17.1
rpm==4.19.1
scikit-learn==1.3.2
scipy==1.11.4
selinux @ file:///builddir/build/BUILD/libselinux-3.5/src
sepolicy @ file:///builddir/build/BUILD/selinux-3.5/python/sepolicy
setools==4.4.3
setuptools==67.7.2
simpleaudio==1.0.4
simpleline==1.9.0
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
sos==4.6.0
soupsieve==2.5
streamlit==1.30.0
systemd-python==235
Tempita==0.5.2
tenacity==8.2.3
text-unidecode==1.3
threadpoolctl==3.2.0
toml==0.10.2
toolz==0.12.0
tornado==6.4
tqdm==4.66.1
types-python-dateutil==2.8.19.20240106
typing_extensions==4.9.0
tzdata==2023.4
tzlocal==5.2
urllib3==1.26.18
validators==0.22.0
virtualenv==20.25.0
watchdog==3.0.0
websocket-client==1.7.0
websockets==11.0.3
Werkzeug==3.0.1
wheel==0.40.0
zipp==3.17.0
opencv-python == 4.9.0.80
streamlit == 1.30.0
pillow == 10.2.0

0 comments on commit 3115543

Please sign in to comment.