sam pk
sam pk

Reputation: 23

How to add watermark to video file while saving using django using moviepy

To Accomplish : watermarked video
Process Followed :

  1. Create a models.py with user, video_file, upload_date fields
  2. Create a forms.py to accept video_file with validations
  3. Lastly views.py to link file and process watermark process while uploading the video.

Here is my views.py

def upload_video(request):
    if request.method == "POST":
        form = VideoUploaderForm(
            data    =   request.POST,
            files   =   request.FILES,
           )

        if form.is_valid():
            obj = form.save(commit = False)
            vid = request.FILES['video_file']
            clip = VideoFileClip(vid.temporary_file_path())
            #watermark
            video   = VideoFileClip(clip)
            logo    = (ImageClip(LOGO_PATH)
                    .set_duration(video.duration)
                    .resize(height=50)
                    .margin(right=8, top=8, opacity=0)
                    .set_pos(("center","bottom")))
            final_  = CompositeVideoClip([video, logo])
            final_.write_videofile("watermarked.mp4")
            obj.save()
            return redirect(page_to_load)
    else:
        form=VideoUploaderForm()
    return render(request,'page.html',{"form":form})

quote I also want to add LOGO to the video which can be a simple PNG image.

Error I got: 'VideoFileClip' object has no attribute 'endswith'

Upvotes: 1

Views: 710

Answers (0)

Related Questions