From 4ae9c9b9867f5c5211721f3eb3368b1dcb876af8 Mon Sep 17 00:00:00 2001 From: marko Date: Sat, 27 Feb 2021 11:41:31 +0100 Subject: [PATCH] youtube clipper first version --- onlineTraining/clips.json | 8 ++++++++ onlineTraining/yt-clipper.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 onlineTraining/clips.json create mode 100755 onlineTraining/yt-clipper.py diff --git a/onlineTraining/clips.json b/onlineTraining/clips.json new file mode 100644 index 0000000..f5108a8 --- /dev/null +++ b/onlineTraining/clips.json @@ -0,0 +1,8 @@ +[ +{ + "source": "https://www.youtube.com/embed/zDj1Yf4d07I", + "target": "taiso-sumo.webm", + "from": "03.103", + "to": "20.804" +} +] diff --git a/onlineTraining/yt-clipper.py b/onlineTraining/yt-clipper.py new file mode 100755 index 0000000..e2488af --- /dev/null +++ b/onlineTraining/yt-clipper.py @@ -0,0 +1,30 @@ +#! /usr/bin/env python3 + +import youtube_dl +import json +import ffmpeg + +jsonFileName = "clips.json" + +clipDict = {} +with open(jsonFileName) as jf: + clipDict = json.load(jf) + +ydl_opts = {"outtmpl": "%(id)s"} + +for clip in clipDict: + infoDict = None + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + infoDict = ydl.extract_info(clip['source'], download=False) + ydl.download([clip['source']]) + + if infoDict is not None: + stream = ffmpeg.input( + infoDict['webpage_url_basename']+"."+infoDict['ext'], + ss=clip['from'], + to=clip['to'], + ) + stream = ffmpeg.filter(stream, "scale", height="480", width="-2" ) + stream = ffmpeg.output(stream, clip['target'], vcodec='vp9', **{"an":None, "y":None}) + ffmpeg.run(stream) +