how to fix video downloaded with pytube showing blank screen in phone

Viewed 28

I am making a YouTube downloader but the problem I am having is that when I download the video, the video has nothing like a thumbnail, it is just showing a blank screen. The video is playable despite it not showing a video preview

import os
from pytube import YouTube
import ffmpeg
import uuid
from flask import Flask, jsonify, request, send_file


app = Flask(__name__)


def download_video(yt, itag):
    audio_filename = f"{uuid.uuid4()}.mp4"
    video_filename = f"{uuid.uuid4()}.mp4"
    audio_video_path = f"downloads/{uuid.uuid4()}.mp4"


    
    video_stream = yt.streams.get_by_itag(itag)
    audio_stream = yt.streams.get_audio_only()
    
    video_path = video_stream.download(output_path="downloads/", filename=video_filename)
    audio_path = audio_stream.download(output_path="downloads/", filename=audio_filename)

    input_video = ffmpeg.input(video_path).video
    input_audio = ffmpeg.input(audio_path).audio
    
    ffmpeg.output(input_video, input_audio, audio_video_path, vcodec='copy', acodec="copy").run()
    
    
    os.remove(video_path)
    os.remove(audio_path)
    return audio_video_path


@app.route("/download", methods = ["GET"])
def download():
  url = request.args.get("url") #YouTube Video url
  itag = request.args.get("itag")
  
  if not url or not itag:
    return jsonify("url and itag query parameters are needed")
  
  yt = YouTube(url)
  title = yt.title
  
  video_path = download_video(yt, itag)
  return send_file(video_path, as_attachment=True, download_name= title + ".mp4", mimetype="video/mp4")


if __name__ == '__main__':
  app.run(debug = True)
  

This is how the downloaded video is been showed in the phone

0 Answers
Related