예제 #1
0
 def convert_tomp4(self):
     info = pipeffmpeg.get_info(self.savepath)
     w, h = 320, 240
     if 'streams' in info:
         for stream in info['streams']:
             if 'width' in stream and 'height' in stream:
                 w = int(stream['width'])
                 h = int(stream['height'])
                 break
     # 'w1:%s,h2:%s'%(w,h)
     if w > h:
         #宽度度大于高度
         h = int(h * 320.0 / w)
         w = 320
     else:
         #宽度小于高度
         w = int(w * 320.0 / h)
         h = 320
     # 'w1:%s,h2:%s'%(w,h)
     if h % 2 != 0:
         h += 1
     if w % 2 != 0:
         w += 1
     rotate = defaultRotate.get(self.rotate, '')
     pipeffmpeg.convert_to(
         self.savepath,
         self.newmp4path,
         '-filter_complex',
         'scale=%d:%d%s,overlay=10:10' % (w, h, rotate),
         inputs=[
             '-i',
             os.path.join(self.root_path,
                          'static/images/videos/vself_overlay48.png')
         ])
예제 #2
0
 def convert_tomp4(self):
     info = pipeffmpeg.get_info(self.savepath)
     w, h = 320, 240
     if 'streams' in info:
         for stream in info['streams']:
             if 'width' in stream and 'height' in stream:
                 w = int(stream['width'])
                 h = int(stream['height'])
                 break
     # 'w1:%s,h2:%s'%(w,h)
     if w > h:
         #宽度度大于高度
         h = int(h*320.0/w)
         w = 320
     else:
         #宽度小于高度
         w = int(w*320.0/h)
         h = 320
     # 'w1:%s,h2:%s'%(w,h)
     if h % 2 != 0:
         h += 1
     if w % 2 != 0:
         w += 1
     rotate = defaultRotate.get(self.rotate,'')
     pipeffmpeg.convert_to(self.savepath, self.newmp4path,
                           '-filter_complex', 'scale=%d:%d%s,overlay=10:10'%(w, h, rotate),
                           inputs = ['-i', os.path.join(self.root_path, 'static/images/videos/vself_overlay48.png')])
예제 #3
0
def play(file_path):
    """play a video file"""
    iv = pipeffmpeg.InputVideoStream()
    iv.open(file_path)

    # Getting the frame rate of the video
    # Got this from the source code of pipeffmpeg (Can be replaced by Popen)
    file_info = pipeffmpeg.get_info(file_path)

    try:
        f_rate = file_info["streams"][0]["r_frame_rate"]
        # Getting the number of seconds for a frame
        delay = 1.0 / int(f_rate.split("/")[0])
    except (KeyError, IndexError):
        # Setting a default delay if frame rate not obtained
        delay = 0.02

    stdscr = curses.initscr()
    max_h, max_w = stdscr.getmaxyx()

    start_time = time.time()
    for i, bmp in enumerate(iv.readframe()):
        # timestap when frame start
        frame_start_time = time.time()
        # resize each frame to proper size, and covert to gray
        image = Image.open(StringIO.StringIO(bmp))\
                    .resize((max_w, max_h), Image.ANTIALIAS)\
                    .convert('L')

        stdscr.clear()
        data = ''.join(gray_scale[pix] for pix in image.getdata())
        for h in range(max_h - 1):
            stdscr.addstr(h, 0, data[h * max_w:(h + 1) * max_w])

        time_eclipsed = time.time() - start_time
        minutes, seconds = time_eclipsed / 60, time_eclipsed % 60
        stdscr.addstr(
            max_h - 1, 0, 'Resolution:[%d*%d] Frame:%d Time:[%d:%d]' %
            (max_w, max_h, i, minutes, seconds))
        stdscr.refresh()

        # Adding a delay if needed
        real_delay = delay - (time.time() - frame_start_time)
        if real_delay > 0:
            time.sleep(real_delay)

    curses.endwin()
예제 #4
0
def play(file_path):
    """play a video file"""
    iv = pipeffmpeg.InputVideoStream()
    iv.open(file_path)

    # Getting the frame rate of the video
    # Got this from the source code of pipeffmpeg (Can be replaced by Popen)
    file_info = pipeffmpeg.get_info(file_path)

    try:
        f_rate = file_info["streams"][0]["r_frame_rate"]
        # Getting the number of seconds for a frame
        delay = 1.0 / int(f_rate.split("/")[0])
    except (KeyError, IndexError):
        # Setting a default delay if frame rate not obtained
        delay = 0.02

    stdscr = curses.initscr()
    max_h, max_w =  stdscr.getmaxyx()

    start_time = time.time()
    for i, bmp in enumerate(iv.readframe()):
        # timestap when frame start
        frame_start_time = time.time()
        # resize each frame to proper size, and covert to gray
        image = Image.open(StringIO.StringIO(bmp))\
                    .resize((max_w, max_h), Image.ANTIALIAS)\
                    .convert('L')

        stdscr.clear()
        data = ''.join(gray_scale[pix] for pix in image.getdata())
        for h in range(max_h-1):
            stdscr.addstr(h, 0, data[h*max_w:(h+1)*max_w])

        time_eclipsed = time.time() - start_time
        minutes, seconds = time_eclipsed/60, time_eclipsed % 60
        stdscr.addstr(max_h-1, 0, 'Resolution:[%d*%d] Frame:%d Time:[%d:%d]' % (max_w, max_h, i, minutes, seconds))
        stdscr.refresh()

        # Adding a delay if needed
        real_delay = delay - (time.time() - frame_start_time)
        if real_delay > 0:
            time.sleep(real_delay)

    curses.endwin()
예제 #5
0
 def get_meta(self):
     if self.finalpath and os.path.exists(self.finalpath):
         return pipeffmpeg.get_info(self.finalpath)
     return {}
예제 #6
0
 def get_meta(self):
     if self.finalpath and os.path.exists(self.finalpath):
         return pipeffmpeg.get_info(self.finalpath)
     return {}