How to get the absolute path to a video, that works in development (Windows) and production (Ubuntu), ive tried almost everything, here is the closest I've gotten to a solution, I am trying to generate a thumbnail for a video when its posted. `
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
def generate_thumbnail(instance):
filename = Path.joinpath(BASE_DIR, 'media/video_files')
print(filename)
thumbnail = VideoFileClip(str(filename)+instance.video.url)
name = instance.video.url + '.png'
time = random.randrange(60)
thumbnail.save_frame('media/uploads/thumbnail' + name, t=time, withmask=True)
instance.thumbnail = name
It never gives me a good path, its ether with '/' or with \ .
MoviePy error: the file C:\Users\User 1\Desktop\django\lumen\media\video_files/media/uploads/video_files/22/29/Elvis_-_If_I_Can_Dream_Official_Live_Performance_fcw0WKp.mp4 could not be found!
Please check that you entered the correct path.