I am trying to use a custom filter to find the video duration using moviepy however the function is not able to access the files even though it seems the correct video path is being passed into the function in the custom filter.
I'm getting the following error:
OSError at /tape/tape/
MoviePy error: the file /media/video_files/channel_Busy/171003B_026_2k.mp4 could not be found!
Please check that you entered the correct path.
The custom filter:
vduration.py
from django import template
import moviepy.editor
register = template.Library()
@register.filter(name='vduration')
def vduration(videourl):
video = moviepy.editor.VideoFileClip(videourl)
video_time = int(video.duration)
return video_time
views.py
def tape(request):
tapes=VideoFiles.objects.all()
context={
"videos": tapes,
}
return render(request, "tape/tape.html", context)
tape.py
{% for video in videos %}
<div class="video-time">{{video.video.url | vduration}}</div>
{% endfor %}
models.py
class VideoFiles(models.Model):
id=models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
video=models.FileField(upload_to=channel_directory_path)
def get_absolute_url(self):
return reverse('video_watch', args=[str(self.id)])
def __str__(self):
return f"video_file_{self.id}"