0

I want to count the number of scenes(videos_files). I download many videos and cut them by the scene I count the number of videos(scenes) example: video 1 has 10 scenes video 2 has 15 scenes so the count is 25. I have an issue that it is working counting well and just from noting any expectation is to count 0 and it will start counting again I do not know why. imports:

from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pytube import YouTube
from pytube import Channel
import re
import random
import datetime
import time
import os
from scenedetect import open_video, ContentDetector, SceneManager, StatsManager
from pytube import Playlist
import youtube_dl
import requests
from pexels_api import API

find_scenes:

def find_scenes(video_path,):
   

    video_stream = open_video(video_path)
    stats_manager = StatsManager()
    # Construct our SceneManager and pass it our StatsManager.
    scene_manager = SceneManager(stats_manager)

    # Add ContentDetector algorithm (each detector's constructor
    # takes various options, e.g. threshold).
    scene_manager.add_detector(ContentDetector())

    # Save calculated metrics for each frame to {VIDEO_PATH}.stats.csv.
    stats_file_path = '%s.stats.csv' % video_path

    # Perform scene detection.
    scene_manager.detect_scenes(video=video_stream)
    scene_list = scene_manager.get_scene_list()
    n=0
    for i, scene in enumerate(scene_list):
      x=scene[0].get_timecode()
      y= scene[1].get_timecode()
      x = time.strptime(x.split('.')[0],'%H:%M:%S')
      x = datetime.timedelta(hours=x.tm_hour,minutes=x.tm_min,seconds=x.tm_sec).total_seconds()
      y = time.strptime(y.split('.')[0],'%H:%M:%S')
      y=datetime.timedelta(hours=y.tm_hour,minutes=y.tm_min,seconds=y.tm_sec).total_seconds()
      
      if y > 0:
        if y-x > 1:
          ffmpeg_extract_subclip(video_path, x,y, targetname=f"test{n}.mp4")
          print(f"This is a name of video: test{n}.mp4")
          n+=1
    return n

code:

#Sncrape video and find chanells url
c = Channel("https://www.youtube.com/c/BuildEmpire/videos")
for url in c.video_urls[:20]:
  video = YouTube(url)
  description2 = video.description
  try:
    videos_credits = slicer(description2,"Video Credits:")
    videos_credits = reversed_slicer(videos_credits,"Thumbnail:")
    urls = re.findall(r'(https?://[^\s]+)', videos_credits)
  except Exception:
    print("Sorry but I choose bad youtube video I will try it again")

#Scrape videos from chanells
n = 0
youtube_videos_list = []
lens = 0
channel= random.choice(urls)
chanell = Channel(channel)
try:
  for video in chanell.video_urls:
      youtube_videos_list.append(video)
      n+=1
except Exception:
  print(f"Error 404 on chanell{chanell}")

print(f"This is a number of urls: {n}")

#Download and cut by scenes
lens = 0
list_of_videos = []
n = 0
full_count = 0
count_of_scenes_per_video = 0
while lens < 600:
   videos = random.choice(youtube_videos_list)
   list_of_videos.append(videos)
   z = YouTube(videos)
   lenght = z.length
   lens = lens + lenght
   print(F"downolading video: {videos}")
   download(videos,n)
   print("download completed")

   #Just for clear output
   print(" ")
   print(" ")

   print(f"This is a temorary lengt of videos {lens}")
   print(f"This is a count_of_scenes_per_video {count_of_scenes_per_video}")
   count_of_scenes_per_video = find_scenes(f"video{n}.mp4",)
   print(f"This is a count_of_scenes_per_video after find_scenes {count_of_scenes_per_video}")
   n += 1
print(f"This is a full lengt of videos {lens}")

this is happening in the console:

This is the first shot This is a scene shot after error

ALex Break
  • 59
  • 10
  • Need more information. There are a bunch of functions in the code that are not built-in python functions without any import, and also appeared to incorrectly tagged ffmpeg – kesh Oct 15 '22 at 18:17
  • Sorry, this is all information that I have. That is a problem for me too. – ALex Break Oct 15 '22 at 18:35
  • I'd suggest addign `scenedetect` tag to attract someone who's knows the package. Also, you may have a better luck on [their discussion board](https://github.com/Breakthrough/PySceneDetect/discussions) – kesh Oct 15 '22 at 18:42
  • Sorry I am new on this platform I do not have a reputation to create a new tag scenedetection does not exist – ALex Break Oct 15 '22 at 18:52
  • You're right, the tag doesn't exist. my bad. I'd say post on their board as I mentioned. – kesh Oct 15 '22 at 19:01

0 Answers0