Esempio n. 1
0
    def download(self, directory):
        bitrate = str(int(self.stream.bitrate / 1000)) + "k"
        url = self.stream.url
        extension = ".mp3" if self.onlyAudio else ".mp4"
        finalPath = os.path.join(directory,
                                 sanitizeFilename(self.name) + extension)

        clip = AudioFileClip(url) if self.onlyAudio else VideoFileClip(url)

        if self.stream.mediaType == "V":
            audioClip = AudioFileClip(self.audioStream.url)

            clip = clip.set_audio(audioClip)

        if self.volumeMultiplier != 0:
            newVolume = (
                1 + self.volumeMultiplier / 100
            )**2 if self.volumeMultiplier < 0 else self.volumeMultiplier / 5

            clip = clip.volumex(newVolume)

        if self.cut:

            # Clip the video
            low = self.lowCut
            high = self.highCut
            if low < 0:
                low = 0
            if high > clip.end:
                high = clip.end
            clip = clip.subclip(low, high)

            # Save as final path name

            if self.onlyAudio:
                clip.write_audiofile(finalPath, bitrate=bitrate)
                self.applyID3Tags(finalPath)
            else:
                clip.write_videofile(finalPath, threads=NUM_THREADS)

            clip.close()

        elif self.onlyAudio:

            clip.write_audiofile(finalPath, bitrate=bitrate)

            clip.close()

            self.applyID3Tags(finalPath)

        else:

            clip.write_videofile(finalPath, threads=NUM_THREADS)
            clip.close()
        try:
            clip.close()
        except:
            pass
        return finalPath
Esempio n. 2
0
def startPreview(onlyAudio, url, cut, low, high, volume):

    clip = None
    if onlyAudio:
        clip = AudioFileClip(url)
    else:
        clip = VideoFileClip(url)

    if volume != 0:

        clip = clip.volumex(volume)

    if cut:
        clip = clip.subclip(low, high)
    print("PREVIEWING WITH MOVIEPY")
    clip.preview()
    clip.close()

    # See https://github.com/Zulko/moviepy/issues/575
    pygame.quit()
# parse the arguments
args = parser.parse_args()
video_file = args.video_file
audio_file = args.audio_file
start = args.start
end = args.end
composite = args.composite
volume_factor = args.volume_factor
# print the passed parameters, just for logging
print(vars(args))
# load the video
video_clip = VideoFileClip(video_file)
# load the audio
audio_clip = AudioFileClip(audio_file)
# use the volume factor to increase/decrease volume
audio_clip = audio_clip.volumex(volume_factor)
# if end is not set, use video clip's end
if not end:
    end = video_clip.end
# make sure audio clip is less than video clip in duration
# setting the start & end of the audio clip to `start` and `end` paramters
audio_clip = audio_clip.subclip(start, end)
# composite with the existing audio in the video if composite parameter is set
if composite:
    final_audio = CompositeAudioClip([video_clip.audio, audio_clip])
else:
    final_audio = audio_clip
# add the final audio to the video
final_clip = video_clip.set_audio(final_audio)
# save the final clip
final_clip.write_videofile("final.mp4")