示例#1
0
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None

    if arch in ('armv6l', 'armv7l'):
        try:
            omxplayer(file, info=True, _err_to_out=True)
        except Exception as e:
            for line in ("%s" % e).split('\n'):
                if 'Duration' in line:
                    match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
                    if match:
                        time_input = match.group()
                        time_split = time_input.split(':')
                        hours = int(time_split[0])
                        minutes = int(time_split[1])
                        seconds = float(time_split[2])
                        time = hours * 3600 + minutes * 60 + seconds
                    break
    else:
        try:
            run_mplayer = mplayer('-identify', '-frames', '0', '-nosound',
                                  file)
            for line in run_mplayer.split('\n'):
                if 'ID_LENGTH=' in line:
                    time = int(round(float(line.split('=')[1])))
                    break
        except Exception as e:
            pass

    return time
示例#2
0
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None

    try:
        if arch in ('armv6l', 'armv7l'):
            run_player = omxplayer(file, info=True, _err_to_out=True, _ok_code=[0, 1], _decode_errors='ignore')
        else:
            run_player = ffprobe('-i', file, _err_to_out=True)
    except sh.ErrorReturnCode_1:
        raise Exception('Bad video format')

    for line in run_player.split('\n'):
        if 'Duration' in line:
            match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
            if match:
                time_input = match.group()
                time_split = time_input.split(':')
                hours = int(time_split[0])
                minutes = int(time_split[1])
                seconds = float(time_split[2])
                time = timedelta(hours=hours, minutes=minutes, seconds=seconds)
            break

    return time
示例#3
0
def view_video(uri):

    ## For Raspberry Pi
    if arch == 'armv6l':
        logging.debug('Displaying video %s. Detected Raspberry Pi. Using omxplayer.' % uri)

        if asset_is_accessible(uri):
            run = omxplayer(uri, o=settings['audio_output'])
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))

        # Clean up after omxplayer
        omxplayer_logfile = path.join(getenv('HOME'), 'omxplayer.log')
        if path.isfile(omxplayer_logfile):
            remove(omxplayer_logfile)

    ## For x86
    elif arch in ['x86_64', 'x86_32']:
        logging.debug('Displaying video %s. Detected x86. Using mplayer.' % uri)

        if asset_is_accessible(uri):
            run = mplayer(uri, fs=True, nosound=True)
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))
示例#4
0
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None
    try:
        if arch in ('armv6l', 'armv7l'):
            run_omxplayer = omxplayer(file, info=True, _err_to_out=True)
            for line in run_omxplayer.split('\n'):
                if 'Duration' in line:
                    match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
                    if match:
                        time_input = match.group()
                        time_split = time_input.split(':')
                        hours = int(time_split[0])
                        minutes = int(time_split[1])
                        seconds = float(time_split[2])
                        time = timedelta(hours=hours, minutes=minutes, seconds=seconds)
                    break
        else:
            run_mplayer = mplayer('-identify', '-frames', '0', '-nosound', file)
            for line in run_mplayer.split('\n'):
                if 'ID_LENGTH=' in line:
                    time = timedelta(seconds=int(round(float(line.split('=')[1]))))
                    break
    except:
        pass

    return time
示例#5
0
def url_fails(url):
    """
    If it is streaming
    """
    if urlparse(url).scheme in ('rtsp', 'rtmp'):
        if arch in ('armv6l', 'armv7l'):
            run_omxplayer = omxplayer(url, info=True, _err_to_out=True, _ok_code=[0, 1])
            for line in run_omxplayer.split('\n'):
                if 'Input #0' in line:
                    return False
            return True
        else:
            run_mplayer = mplayer('-identify', '-frames', '0', '-nosound', url)
            for line in run_mplayer.split('\n'):
                if 'Clip info:' in line:
                    return False
            return True

    """
    Try HEAD and GET for URL availability check.
    """

    # Use Certifi module and set to True as default so users stop seeing InsecureRequestWarning in logs
    if settings['verify_ssl']:
        verify = certifi.where()
    else:
        verify = True

    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/538.15 (KHTML, like Gecko) Version/8.0 Safari/538.15'
    }
    try:
        if not validate_url(url):
            return False

        if requests.head(
            url,
            allow_redirects=True,
            headers=headers,
            timeout=10,
            verify=verify
        ).status_code in HTTP_OK:
            return False

        if requests.get(
            url,
            allow_redirects=True,
            headers=headers,
            timeout=10,
            verify=verify
        ).status_code in HTTP_OK:
            return False

    except (requests.ConnectionError, requests.exceptions.Timeout):
        pass

    return True
示例#6
0
def view_video(uri):
    logging.debug('Displaying video %s', uri)

    if arch == 'armv6l':
        run = sh.omxplayer(uri, o=settings['audio_output'], _bg=True)
    else:
        run = sh.mplayer(uri, '-nosound', _bg=True)

    browser_clear(force=True)
    run.wait()
 def display_content(self, content):
     assert content.content_type == Media.VIDEO
     self.logger.debug('VideoPlayer receiving content %s', content)
     uri = content.content_uri
     if platform.linux_distribution()[0] in self.NON_PI_PLATFORMS:
         self.process = sh.vlc(
             '--no-osd', '-f', '--no-interact', '--repeat',
             '--mouse-hide-timeout', '--no-video-title-show',
             '--video-on-top', uri, _bg=True
         )
     else:
         self.process = sh.omxplayer(
             '--no-osd', '-b', '--loop', uri, _bg=True)
示例#8
0
 def display_content(self, content):
     assert content.content_type == Media.VIDEO
     self.logger.debug('VideoPlayer receiving content %s', content)
     uri = content.content_uri
     if platform.linux_distribution()[0] in self.NON_PI_PLATFORMS:
         self.process = sh.vlc('--no-osd',
                               '-f',
                               '--no-interact',
                               '--repeat',
                               '--mouse-hide-timeout',
                               '--no-video-title-show',
                               '--video-on-top',
                               uri,
                               _bg=True)
     else:
         self.process = sh.omxplayer('--no-osd',
                                     '-b',
                                     '--loop',
                                     uri,
                                     _bg=True)
示例#9
0
def view_video(uri):

    ## For Raspberry Pi
    if arch == 'armv6l':
        logging.debug('Displaying video %s. Detected Raspberry Pi. Using omxplayer.' % uri)

        if asset_is_accessible(uri):
            run = omxplayer(uri, o=settings['audio_output'], _bg=True)
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        # Wait until omxplayer is starting before clearing the browser. This minimises delay between
        # web and image content. Omxplayer will run on top of the browser so the delay in clearing
        # won't be visible. This minimises delay between web and video.
        browser_clear()
        run.wait()

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))

        # Clean up after omxplayer
        omxplayer_logfile = path.join(getenv('HOME'), 'omxplayer.log')
        if path.isfile(omxplayer_logfile):
            remove(omxplayer_logfile)

    ## For x86
    elif arch in ['x86_64', 'x86_32']:
        logging.debug('Displaying video %s. Detected x86. Using mplayer.' % uri)

        if asset_is_accessible(uri):
            run = mplayer(uri, fs=True, nosound=True, _bg=True)
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        browser_clear()
        run.wait()

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))
示例#10
0
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None
    try:
        run_omxplayer = omxplayer(file, info=True, _err_to_out=True)
        for line in run_omxplayer.split('\n'):
            if 'Duration' in line:
                match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
                if match:
                    time_input = match.group()
                    time_split = time_input.split(':')
                    hours = int(time_split[0])
                    minutes = int(time_split[1])
                    seconds = float(time_split[2])
                    time = timedelta(hours=hours, minutes=minutes, seconds=seconds)
                break
    except:
        pass

    return time
示例#11
0
文件: utils.py 项目: cyuste/yp_viewer
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None
    try:
        run_omxplayer = omxplayer(file, info=True, _err_to_out=True)
        for line in run_omxplayer.split('\n'):
            if 'Duration' in line:
                match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
                if match:
                    time_input = match.group()
                    time_split = time_input.split(':')
                    hours = int(time_split[0])
                    minutes = int(time_split[1])
                    seconds = float(time_split[2])
                    time = timedelta(hours=hours, minutes=minutes, seconds=seconds)
                break
    except:
        pass

    return time
示例#12
0
      r_sensor_value = r_acc / NUM_CAMP

      i = 0
      r_acc = 0

      #print('R: ', r_sensor_value)

      if r_sensor_value >= R_SENSOR_MAX:

        if VIDEO_STARTED == False:
          print("Starting video...")
          sendUDP('1') # open
          VIDEO_STARTED = True
          VIDEO_PAUSED = False
          run = omxplayer('-s', VIDEO_NAME, _bg=True, _out=interact, _out_bufsize=250)
          time.sleep(1)
          run_audio = aplay(AUDIO_NAME, _bg=True)
          screen.fill((0,0,0))
          pygame.display.update()
          R_SENSOR_MAX = R_SENSOR_MAX - 3 
      
      elif r_sensor_value <= R_SENSOR_MIN:
        sendUDP('0') # closed

      else:
        sendUDP('2') # motion

        if VIDEO_STARTED == True:
          VIDEO_STARTED = False
          R_SENSOR_MAX = R_SENSOR_MAX + 3
示例#13
0
pygame.display.update()

while True:
    try:

        if VIDEO_STARTED == False:
            if (not (GPIO.input(GPIO_PIN))):
                print("Starting video...")
                sendUDP('1')  # open
                VIDEO_STARTED = True
                VIDEO_PAUSED = False
                time.sleep(.5)
                run = omxplayer('-s',
                                VIDEO_NAME,
                                _bg=True,
                                _out=interact,
                                _out_bufsize=250)
                time.sleep(1)
                run_audio = aplay(AUDIO_NAME, _bg=True)
                screen.fill((0, 0, 0))
                pygame.display.update()

        else:

            # check if chapter button is pressed
            if omx_stdin:
                chapter = read_buttons()

                if chapter > 0:
                    if VIDEO_PAUSED == True: