示例#1
0
def generate_gif():
    logger.info('gif THAT')
    exec_cmd.run('ffmpeg -y -i ' + 'temp/final.avi -vf ' +
                 'fps=24,scale=1080:-1:' +
                 'flags=lanczos,palettegen temp/palette.png')

    exec_cmd.run(
        'ffmpeg  -i temp/final.avi ' + '-i temp/palette.png -filter_complex ' +
        '"fps=24,scale=1080:-1:flags=lanczos[x];[x][1:v]paletteuse" ' +
        'out/you_can_code_a.gif')
示例#2
0
def concat_scenes():
    logger.info('concatenate the scenes')
    to_concat = [
        "cut1.avi", "dlvideo.avi", "cut5.avi", "subs.avi", "cut4.avi",
        "add_meta.avi", "cut3.avi", "concat.avi", "cut7.avi", "gifthat.avi",
        "empty_screen.avi", "meta.avi", "cut8.avi"
    ]
    with open('temp/list.txt', 'w') as f:
        for vid in to_concat:
            print("file '" + vid + "'", file=f)
    exec_cmd.run('ffmpeg -f concat -i temp/list.txt' +
                 ' -c copy -y temp/concat_nosub.avi')
示例#3
0
def cut_scenes():
    global invid
    logger.info('cut the scenes used in the gif')
    cuttimes = [("00:00:40.5", "00:00:57.0"), ("00:01:00.7", "00:01:04.5"),
                ("00:01:13.5", "00:01:15.2"), ("00:01:20.3", "00:01:31.5"),
                ("00:01:38.8", "00:01:40.9"), ("00:01:47.2", "00:01:48.3"),
                ("00:01:50.6", "00:01:53.3"), ("00:01:55.9", "00:02:00.0"),
                ("00:00:27.0", "00:00:27.1")]
    n = 1
    cuts = []
    for cut in cuttimes:
        outvid = 'temp/cut' + str(n) + '.avi'
        cuts.append(outvid)
        n += 1
        command = ("ffmpeg -i " + invid + " -ss " + cut[0] +
                   ' -filter:v "crop=1280:540:0:90"' + " -c:v ffv1" + " -to " +
                   cut[1] + ' -r 24 -y ' + outvid)
        exec_cmd.run(command)
示例#4
0
def subVideo(subs, inputvid, outputvid):
    """Take a list a subtitles, make each png with makePngSub()
    and add the pngs to the video at the given intervals"""
    n = 1
    subfiles = []
    for sub in subs:
        subfile = makePngSub(text=sub[0],
                             color=sub[1],
                             position=sub[2],
                             filename=str(n))
        subfiles.append(subfile)
        n += 1

    def writeFilterblocks(subs):
        """write the complex filter to chain-add all the png in one shot"""
        n = 0
        filter_blocks = []
        for sub in subs:
            timing = sub[3]
            blocks = [''] * 4
            if n == 0:
                blocks[0] = '"[0:v]'
            else:
                blocks[0] = '[tmp]'
            n += 1
            blocks[1] = '[' + str(n) + ':v]'
            blocks[2] = "overlay=enable='between(t,{})'".format(timing)
            if n != len(subs):
                blocks[3] = ' [tmp]; '
            else:
                blocks[3] = '"'
            filter_blocks += blocks
        return filter_blocks

    inputblocks = ['ffmpeg -i ' + inputvid
                   ] + ['-i ' + subfile for subfile in subfiles]
    inputstr = ' '.join(inputblocks)
    filterstr = '-filter_complex ' + ''.join(writeFilterblocks(subs))
    #outputstr = '-y '+ outputvid
    outputstr = '-y -c:v ffv1 ' + outputvid
    command = inputstr + ' ' + filterstr + ' ' + outputstr
    exec_cmd.run(command)
示例#5
0
def snapshotBackground(cutscene):
    """Take a 1-frame shot from the video, used as background for the terminal"""
    command = 'ffmpeg -ss 00:00:00 -i {} -vf "select=eq(n\,0)" -q:v 1 -y temp/background.png'.format(
        cutscene)
    exec_cmd.run(command)
示例#6
0
def makeVideo(seqname, framerate='24', r='24'):
    """Take all seqname png and join them in an AVI video."""
    exec_cmd.run('ffmpeg -framerate ' + framerate + ' -i temp/frames/' +
                 seqname + '%04d.png' + ' -c:v ffv1' + ' -r ' + r +
                 ' -pix_fmt yuv420p -y ' + 'temp/' + seqname + '.avi')
示例#7
0
def download_youtube():
    logger.info('Download youtube video via youtube-dl')
    url = 'https://www.youtube.com/watch?v=TS_59Y7bYoA'

    exec_cmd.run(r'youtube-dl -f 136 -o ' + invid + ' ' + url)