def test_video2():
    fnin = 'BU.avi'
    fnout = 'BU720.avi'

    orig_meta = ffprobe_sync(fnin)
    orig_duration = float(orig_meta['streams'][0]['duration'])

    convert(fnin, '720', '1', fnout)

    meta_720 = ffprobe_sync(fnout)
    duration_720 = float(meta_720['streams'][0]['duration'])

    assert orig_duration == approx(duration_720, rel=0.01)
def test_video1():
    fnin = 'BU.avi'
    fnout = 'BU480.avi'

    orig_meta = ffprobe_sync(fnin)
    orig_duration = float(orig_meta['streams'][0]['duration'])

    convert(fnin, '480', '2', fnout)

    meta_480 = ffprobe_sync(fnout)
    duration_480 = float(meta_480['streams'][0]['duration'])

    assert orig_duration == approx(duration_480, rel=0.01)
    def pp(self, filename):
        cw = self.cw
        print_ = get_print(cw)
        ui_setting = utils.ui_setting
        ext = os.path.splitext(filename)[1].lower()
        if not os.path.isfile(filename):
            print('no file: {}'.format(filename))
            return
        
        filename_new = None
        if self.type == 'video' and (self.audio is not None or ext != '.mp4') and not self.stream.live: # UHD or non-mp4
            if self.audio is not None: # merge
                print_('Download audio: {}'.format(self.audio))
                hash = uuid()
                path = os.path.join(os.path.dirname(filename), '{}_a.tmp'.format(hash))
                if cw is not None:
                    cw.trash_can.append(path)
                if constants.FAST:
                    downloader_v3.download(self.audio, chunk=1024*1024, n_threads=2, outdir=os.path.dirname(path), fileName=os.path.basename(path), customWidget=cw, overwrite=True)
                else:
                    downloader.download(self.audio, outdir=os.path.dirname(path), fileName=os.path.basename(path), customWidget=cw, overwrite=True)
                ext, out = ffmpeg.merge(filename, path, cw=cw, vcodec=self.vcodec)
                #print(out)
                name, ext_old = os.path.splitext(filename)
                if ext_old.lower() != ext.lower():
                    print_('rename ext {} --> {}'.format(ext_old, ext))
                    filename_new = '{}{}'.format(name, ext)
                    if os.path.isfile(filename_new):
                        os.remove(filename_new)
                    os.rename(filename, filename_new)
            else: # convert non-mp4 video -> mp4
                name, ext_old = os.path.splitext(filename)
                filename_new = '{}.mp4'.format(name)
                print_('Convert video: {} -> {}'.format(filename, filename_new))
                ffmpeg.convert(filename, filename_new, cw=cw)
        elif self.type == 'audio' and ext != '.mp3': # convert non-mp3 audio -> mp3
            name, ext_old = os.path.splitext(filename)
            filename_new = '{}.mp3'.format(name)
            ffmpeg.convert(filename, filename_new, '-shortest -preset ultrafast -b:a {}k'.format(get_abr()), cw=cw)

        if self.type == 'audio' and ui_setting.albumArt.isChecked():
            try:
                self.thumb.seek(0)#
                ffmpeg.add_cover(filename_new, self.thumb, {'artist':self.username, 'title':self.title}, cw=cw)
            except Exception as e:
                s = print_error(e)[-1]
                print_(s)

        utils.pp_subtitle(self, filename, cw)

        return filename_new
Example #4
0
def main():
    model = ""
    opts, args = getopt.getopt(sys.argv[1:], "ht:p:m:")
    for op, value in opts:
        if op == "-h":
            usage()
            sys.exit()
        elif op == "-t":
            input_file = value
        elif op == "-p":
            input_file = value
        elif op == "-m":
            model = value

    input_wav = ffmpeg.convert(input_file)
    if model == "":
        input_wav = "20160203c.wav"
        songs_20160203c = [[0, 265], [1028, 1245], [1440, 1696], [2177, 2693]]
        song_dump(songs_20160203c)
        model = train.run(input_wav, songs_20160203c)
    Y, delimit_points = predict.run(input_wav, model)
    for i in delimit_points:
        print str(i / 3600) + ":" + str(i % 3600 / 60) + ":" + str(i % 60)

    ffmpeg.cut(input_file, delimit_points)

    plt.figure()
    plt.plot(-0.2)
    plt.plot(1.2)
    if model == "":
        plt.plot(songs_20160203c, 'b')
    plt.plot(Y, 'r')
    plt.show()
Example #5
0
    def pp(self, filename):
        if self.format == 'mp4':
            return
        name, ext_old = os.path.splitext(filename)
        filename_new = '{}.mp3'.format(name)
        ffmpeg.convert(filename,
                       filename_new,
                       '-shortest -preset ultrafast -b:a {}k'.format(
                           get_abr()),
                       cw=self.cw)

        if utils.ui_setting.albumArt.isChecked():
            self.thumb.seek(0)  #
            ffmpeg.add_cover(filename_new,
                             self.thumb, {
                                 'artist': self.username,
                                 'title': self.title
                             },
                             cw=self.cw)

        return filename_new
    def _pp(self, filename):
        cw = self.cw
        print_ = get_print(cw)
        ui_setting = utils.ui_setting
        ext = os.path.splitext(filename)[1].lower()
        if not os.path.isfile(filename):
            print(u'no file: {}'.format(filename))
            return

        filename_new = None
        if self.type == 'video' and (self.audio is not None
                                     or ext != '.mp4'):  # UHD or non-mp4
            if self.audio is not None:  # merge
                print_(u'Download audio: {}'.format(self.audio))
                hash = uuid()
                path = os.path.join(os.path.dirname(filename),
                                    '{}_a.tmp'.format(hash))
                if cw is not None:
                    cw.trash_can.append(path)
                if constants.FAST:
                    downloader_v3.download(self.audio,
                                           chunk=1024 * 1024,
                                           n_threads=2,
                                           outdir=os.path.dirname(path),
                                           fileName=os.path.basename(path),
                                           customWidget=cw,
                                           overwrite=True)
                else:
                    downloader.download(self.audio,
                                        outdir=os.path.dirname(path),
                                        fileName=os.path.basename(path),
                                        customWidget=cw,
                                        overwrite=True)
                ext, out = ffmpeg.merge(filename,
                                        path,
                                        cw=cw,
                                        vcodec=self.vcodec)
                #print(out)
                name, ext_old = os.path.splitext(filename)
                if ext_old.lower() != ext.lower():
                    print_(u'rename ext {} --> {}'.format(ext_old, ext))
                    filename_new = u'{}{}'.format(name, ext)
                    if os.path.isfile(filename_new):
                        os.remove(filename_new)
                    os.rename(filename, filename_new)
            else:  # convert non-mp4 video -> mp4
                name, ext_old = os.path.splitext(filename)
                filename_new = u'{}.mp4'.format(name)
                print_(u'Convert video: {} -> {}'.format(
                    filename, filename_new))
                ffmpeg.convert(filename, filename_new, cw=cw)
        elif self.type == 'audio' and ext != '.mp3':  # convert non-mp3 audio -> mp3
            name, ext_old = os.path.splitext(filename)
            filename_new = u'{}.mp3'.format(name)
            ffmpeg.convert(filename,
                           filename_new,
                           '-shortest -preset ultrafast -b:a {}k'.format(
                               get_abr()),
                           cw=cw)

        if self.type == 'audio' and ui_setting.albumArt.isChecked():
            try:
                self.thumb.seek(0)  #
                ffmpeg.add_cover(filename_new,
                                 self.thumb, {
                                     'artist': self.username,
                                     'title': self.title
                                 },
                                 cw=cw)
            except Exception as e:
                s = print_error(e)[-1]
                print_(s)

        if ui_setting and ui_setting.subtitle.isChecked():
            lang = {
                'korean': 'ko',
                'english': 'en',
                'japanese': 'ja'
            }[compatstr(ui_setting.subtitleCombo.currentText()).lower()]
            if lang in self.subtitles:
                try:
                    subtitle = self.subtitles[lang]
                    filename_sub = u'{}.vtt'.format(
                        os.path.splitext(filename)[0])
                    downloader.download(
                        subtitle,
                        os.path.dirname(filename_sub),
                        fileName=os.path.basename(filename_sub),
                        overwrite=True)
                    filename_sub_new = u'{}.srt'.format(
                        os.path.splitext(filename_sub)[0])
                    cw.imgs.append(filename_sub_new)
                    cw.dones.add(
                        os.path.realpath(filename_sub_new).replace(
                            '\\\\?\\', ''))
                    srt_converter.convert(filename_sub, filename_sub_new)
                    cw.setSubtitle(True)
                finally:
                    try:
                        os.remove(filename_sub)
                    except:
                        pass

        return filename_new
Example #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# """
# mp4をmp3に変える
#
# """

from ydl import download
from ffmpeg import convert
from remove import rmMp4
import os, glob

if __name__ == '__main__':
    print("Input url")
    url = input(">>> ")
    download(url)
    os.chdir("./youtube/")
    fnames = glob.glob("*.mp4")
    for fname in fnames:
        bname = os.path.splitext(fname)[0]
        convert(fname, bname + '.mp3')
        rmMp4()
        print("Next")
    print("finish")
 def convert_file(self, from_path, to_path, quality):
     try:
         ffmpeg.convert(from_path, to_path, quality=quality)
     except Exception as e:
         print("Failed to export file: {}".format(e))