WTV2D/core/views.py

30 lines
956 B
Python
Raw Normal View History

2022-06-09 15:11:48 +02:00
import cv2
from django.http import HttpResponseRedirect
2022-06-09 14:39:12 +02:00
from django.shortcuts import render
2022-06-09 15:11:48 +02:00
from django.contrib import messages
from core.forms import VideoUploadForm
from core.models import VideoFile
2022-06-09 14:39:12 +02:00
# Create your views here.
2022-06-09 14:52:42 +02:00
def home(request):
2022-06-09 15:11:48 +02:00
form = VideoUploadForm()
if request.method == "POST":
form = VideoUploadForm(request.POST, request.FILES)
if form.is_valid():
video_file = VideoFile(file=request.FILES['file'])
video_file.save()
video = cv2.VideoCapture(video_file.file.path)
video_file.fps = video.get(cv2.CAP_PROP_FPS)
video_file.video_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
video_file.video_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
video_file.save()
else:
messages.error(request, "Something went wrong")
context = {'form': form}
return render(request, 'core/home.html', context)