import cv2 from django.http import HttpResponseRedirect from django.shortcuts import render from django.contrib import messages from core.forms import VideoUploadForm from core.models import VideoFile # Create your views here. def home(request): 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)