Example #1
0
async def main():
    tasks = [log_status(), button_observer(), steerwheel_observer()]
    try:
        await asyncio.gather(*tasks)

    except KeyboardInterrupt:
        print(clear_line, "\n")

    exit_program()
def create_clips(video_path, output_folder, interval_seconds, clip_length):
    # The output folder for the clips.
    output_folder = os.path.join(output_folder, 'clips')

    if not os.path.exists(video_path):
        raise ClipError('The specified video file does not exist.')

    if not os.path.exists(output_folder):
        os.mkdir(output_folder)

    provider = VideoInfoProvider(video_path)
    duration = int(float(provider.get_duration()))

    if interval_seconds > duration:
        raise ClipError(
            f'The interval ({interval_seconds}s) may not be longer than the video ({duration}s).'
        )

    number_steps = math.trunc(duration / interval_seconds)

    txt_file_path = f'{output_folder}/clips.txt'
    # Create the file.
    open(txt_file_path, 'w').close()

    print('Overview mode activated.')
    print(
        f'Creating a {clip_length} second clip every {interval_seconds} seconds from {video_path}...'
    )
    line()

    try:
        for step in range(1, number_steps):
            clip_name = f'clip{step}.mkv'
            with open(txt_file_path, 'a') as f:
                f.write(f"file '{clip_name}'\n")
            clip_output_path = os.path.join(output_folder, clip_name)
            clip_offset = step_to_movie_timestamp(step * interval_seconds)
            print(f'Creating clip {step} which starts at {clip_offset}...')
            subprocess_cut_args = [
                "ffmpeg", "-loglevel", "warning", "-stats", "-y", "-ss",
                clip_offset, "-i", video_path, "-map", "0:V", "-t",
                clip_length, "-c:v", "libx264", "-crf", "0", "-preset",
                "ultrafast", clip_output_path
            ]
            subprocess.run(subprocess_cut_args)
    except Exception as error:
        print('An error occurred while trying to create the clips.')
        exit_program(error)
    else:
        return txt_file_path
def create_movie_overview(video_path, output_folder, interval_seconds, clip_length):
    extension = Path(video_path).suffix
    try:
        txt_file_path = create_clips(video_path, output_folder, interval_seconds, clip_length)
        output_file = concatenate_clips(txt_file_path, output_folder, extension, interval_seconds, clip_length)
        result = True
    except ClipError as err:
        result = False
        exit_program(err.args[0])
    except ConcatenateError as err:
        result = False
        exit_program(err.args[0])

    if result:
        print(f'Overview Video: {clip_length}-{interval_seconds} (ClipLength-IntervalSeconds){extension}')
        line()
        return result, output_file
Example #4
0
def main():
    # Basic configuration
    data_dir = utils.ensure_path('~/data_analysis/fcb/')
#     group_id = 153748404666241
    group_id = 597682743580084
    
    # Load basic arguments
    log("Parsing basic arguments")
    missing_arg = utils.check_required_arg(utils.login_opt, utils.password_opt, utils.ch_driver_opt)
    if missing_arg is not None:
        utils.exit_program('Missing required argument ' + missing_arg)
    login = utils.get_arg(utils.login_opt)
    password = utils.get_arg(utils.password_opt)
    driver_path = utils.get_arg(utils.ch_driver_opt)


    log('Starting browser')
    browser = webdriver.Chrome(executable_path=driver_path)

    scrapper = FcbBrowserScrapper(browser, login, password)
    scrapper.log_in()
    
    # Scrap
    users = scrapper.scrap_group_members(group_id)

#     Temporary code for loading user from file rather from the web
#     to speed up the development
#     users_file = utils.ensure_path('~/data_analysis/mlyny_group.txt')
#     utils.save_data(users, users_file)
#     users = []
#     with open(users_file, encoding='utf-8') as f:
#         for line in f:
#             if line == '':
#                 break
#             s = line.split(',')
#             users.append((s[0], s[1]))

    # Process
    scrapper.process_users(users, data_dir)
    

    
 
    log('Closing the browser')
    browser.close()
    log('The end')
Example #5
0
def main():
    if len(sys.argv) == 1:
        line()
        print(
            "To see more details about the available arguments, enter 'python main.py -h'"
        )
        line()
    parser = ArgumentParser(formatter_class=RawTextHelpFormatter)
    # Original video path.
    parser.add_argument(
        '-ovp',
        '--original-video-path',
        type=str,
        required=True,
        help='Enter the path of the original '
        'video. A relative or absolute path can be specified. '
        'If the path contains a space, it must be surrounded in double quotes.\n'
        'Example: -ovp "C:/Users/H/Desktop/file 1.mp4"')
    # Set the number of threads to be used when computing VMAF.
    parser.add_argument(
        '--threads',
        type=str,
        default=str(os.cpu_count()),
        help='Set the number of threads to be used when computing VMAF.')
    # Which video encoder to use.
    parser.add_argument(
        '-e',
        '--video-encoder',
        type=str,
        default='x264',
        choices=['x264', 'x265', 'av1'],
        help='Specify the encoder to use (default: x264).\nExample: -e x265')
    # Set AV1 speed/quality ratio
    parser.add_argument(
        '--cpu-used',
        type=int,
        default=1,
        choices=range(1, 9),
        help=
        'Only applicable if choosing the AV1 encoder. Set speed/quality ratio. Value Range: 1-8\n'
        'Lower values mean slower encoding but better quality, and vice-versa.'
    )
    # CRF value(s).
    parser.add_argument('-crf',
                        '--crf-value',
                        type=int,
                        nargs='+',
                        choices=range(0, 52),
                        default=23,
                        help='Specify the CRF value(s) to use.',
                        metavar='CRF_VALUE(s)')
    # Preset(s).
    parser.add_argument('-p',
                        '--preset',
                        type=str,
                        nargs='+',
                        choices=[
                            'veryslow', 'slower', 'slow', 'medium', 'fast',
                            'faster', 'veryfast', 'superfast', 'ultrafast'
                        ],
                        default='medium',
                        help='Specify the preset(s) to use.',
                        metavar='PRESET(s)')
    # The time interval to use when creating the overview video.
    parser.add_argument(
        '-i',
        '--interval',
        type=int,
        choices=range(1, 600),
        default=0,
        help=
        'Create a lossless overview video by grabbing a <cliplength> seconds long segment '
        'every <interval> seconds from the original video and use this overview video '
        'as the "original" video that the transcodes are compared with.\nExample: -i 30',
        metavar='<an integer between 1 and 600>')
    # The length of each clip.
    parser.add_argument(
        '-cl',
        '--clip-length',
        type=int,
        choices=range(1, 60),
        default=1,
        help=
        'Defines the length of the clips. Only applies when used with -i > 0. Default: 1.\n'
        'Example: -cl 10',
        metavar='<an integer between 1 and 60>')
    # Use only the first x seconds of the original video.
    parser.add_argument(
        '-t',
        '--encode-length',
        type=str,
        help=
        'Create a lossless version of the original video that is just the first x seconds of the '
        'video, use the cut version as the reference and for all encodes. '
        'You cannot use this option in conjunction with the -i or -cl arguments.'
        'Example: -t 60')
    # Enable phone model?
    parser.add_argument('-pm',
                        '--phone-model',
                        action='store_true',
                        help='Enable VMAF phone model.')
    # Number of decimal places to use for the data.
    parser.add_argument(
        '-dp',
        '--decimal-places',
        type=int,
        default=2,
        help='The number of decimal places to use for the data '
        'in the table (default: 2).\nExample: -dp 3')
    # Calculate SSIM?
    parser.add_argument('-ssim',
                        '--calculate-ssim',
                        action='store_true',
                        help='Calculate SSIM in addition to VMAF.')
    # Calculate PSNR?
    parser.add_argument('-psnr',
                        '--calculate-psnr',
                        action='store_true',
                        help='Calculate PSNR in addition to VMAF.')
    # No transcoding mode.
    parser.add_argument(
        '-ntm',
        '--no-transcoding-mode',
        action='store_true',
        help=
        'Use this mode if you\'ve already transcoded a video and would like its VMAF and '
        '(optionally) the SSIM and PSNR to be calculated.\n'
        'Example: -ntm -tvp transcoded.mp4 -ovp original.mp4 -ssim -psnr')
    # Transcoded video path (only applicable when using the -ntm mode).
    parser.add_argument(
        '-tvp',
        '--transcoded-video-path',
        help=
        'The path of the transcoded video (only applicable when using the -ntm mode).'
    )

    args = parser.parse_args()

    if args.calculate_psnr:
        exit_program(
            'PSNR calculation is currently unavailable due to a change that was made in libvmaf v2.0.0.\n'
            'Visit https://github.com/Netflix/vmaf/issues/787 for more information.\n'
            'You can re-run your command without the psnr argument, but PSNR values will not be calculated.'
        )

    args_validator = ArgumentsValidator()
    validation_result, validation_errors = args_validator.validate(args)

    if not validation_result:
        for error in validation_errors:
            print(f'Error: {error}')
        exit_program('Argument validation failed.')

    decimal_places = args.decimal_places
    original_video_path = args.original_video_path
    filename = Path(original_video_path).name
    output_folder = f'({filename})'
    os.makedirs(output_folder, exist_ok=True)

    # this includes the dot eg '.mp4'
    output_ext = Path(original_video_path).suffix
    # The M4V container does not support the H.265 codec.
    if output_ext == '.m4v' and args.video_encoder == 'x265':
        output_ext = '.mp4'

    # Use class VideoInfoProvider  to get the framerate, bitrate and duration
    provider = VideoInfoProvider(original_video_path)
    fps = provider.get_framerate_fraction()
    fps_float = provider.get_framerate_float()
    original_bitrate = provider.get_bitrate()

    line()
    print(
        'Video Quality Metrics\nGitHub.com/BassThatHertz/video-quality-metrics'
    )
    line()
    print('Here\'s some information about the original video:')
    print(f'Filename: {filename}')
    print(f'Bitrate: {original_bitrate}')
    print(f'Framerate: {fps} ({fps_float}) FPS')
    line()

    table = PrettyTable()
    table_column_names = ['Encoding Time (s)', 'Size', 'Bitrate', 'VMAF']

    if args.calculate_ssim:
        table_column_names.append('SSIM')
    if args.calculate_psnr:
        table_column_names.append('PSNR')
    if args.no_transcoding_mode:
        del table_column_names[0]

    if args.interval > 0:
        clip_length = str(args.clip_length)
        result, concatenated_video = create_movie_overview(
            original_video_path, output_folder, args.interval, clip_length)
        if result:
            original_video_path = concatenated_video
        else:
            exit_program(
                'Something went wrong when trying to create the overview video.'
            )

    factory = FfmpegProcessFactory()
    timer = Timer()

    if not args.no_transcoding_mode:
        # args.crf_value is a list when more than one CRF value is specified.
        if is_list(args.crf_value) and len(args.crf_value) > 1:
            print('CRF comparison mode activated.')
            crf_values = args.crf_value
            crf_values_string = ', '.join(str(crf) for crf in crf_values)
            preset = args.preset[0] if is_list(args.preset) else args.preset
            print(
                f'CRF values {crf_values_string} will be compared and the {preset} preset will be used.'
            )
            video_encoder = args.video_encoder
            # Cannot use os.path.join for output_folder as this gives an error like the following:
            # No such file or directory: '(2.mkv)\\Presets comparison at CRF 23/Raw JSON Data/superfast.json'
            output_folder = f'({filename})/CRF comparison at preset {preset}'
            os.makedirs(output_folder, exist_ok=True)
            # The comparison table will be in the following path:
            comparison_table = os.path.join(output_folder, 'Table.txt')
            # Add a CRF column.
            table_column_names.insert(0, 'CRF')
            # Set the names of the columns
            table.field_names = table_column_names

            # The user only wants to transcode the first x seconds of the video.
            if args.encode_length and args.interval == 0:
                original_video_path = cut_video(filename, args, output_ext,
                                                output_folder,
                                                comparison_table)

            # Transcode the video with each CRF value.
            for crf in crf_values:
                transcode_output_path = os.path.join(output_folder,
                                                     f'CRF {crf}{output_ext}')
                graph_filename = f'CRF {crf} at preset {preset}'

                arguments = EncodingArguments()
                arguments.infile = str(original_video_path)
                arguments.encoder = Encoder[video_encoder]
                if video_encoder == 'av1':
                    arguments.av1_compression = str(args.cpu_used)
                arguments.crf = str(crf)
                arguments.preset = preset
                arguments.outfile = transcode_output_path

                process = factory.create_process(arguments)

                print(f'Transcoding the video with CRF {crf}...')
                timer.start()
                process.run()
                time_rounded = timer.end(decimal_places)
                print('Done!')

                transcode_size = os.path.getsize(
                    transcode_output_path) / 1_000_000
                transcoded_bitrate = provider.get_bitrate(
                    transcode_output_path)
                size_rounded = force_decimal_places(
                    round(transcode_size, decimal_places), decimal_places)
                data_for_current_row = [
                    f'{size_rounded} MB', transcoded_bitrate
                ]

                os.makedirs(os.path.join(output_folder, 'Raw JSON Data'),
                            exist_ok=True)
                # os.path.join doesn't work with libvmaf's log_path option so we're manually defining the path with
                # slashes.
                json_file_path = f'{output_folder}/Raw JSON Data/CRF {crf}.json'

                run_libvmaf(transcode_output_path, args, json_file_path, fps,
                            original_video_path, factory)

                create_table_plot_metrics(comparison_table, json_file_path,
                                          args, decimal_places,
                                          data_for_current_row, graph_filename,
                                          table, output_folder, time_rounded,
                                          crf)

            with open(comparison_table, 'a') as f:
                f.write(f'\nFile Transcoded: {filename}')
                f.write(f'\nBitrate: {original_bitrate}')
                f.write(f'\nEncoder used for the transcodes: {video_encoder}')
                f.write(f'\nPreset used for the transcodes: {preset}')

        # args.preset is a list when more than one preset is specified.
        elif is_list(args.preset):
            print('Presets comparison mode activated.')
            chosen_presets = args.preset
            presets_string = ', '.join(chosen_presets)
            crf = args.crf_value[0] if is_list(
                args.crf_value) else args.crf_value
            video_encoder = args.video_encoder
            print(
                f'Presets {presets_string} will be compared at a CRF of {crf}.'
            )
            # Cannot use os.path.join for output_folder as this gives an error like the following:
            # No such file or directory: '(2.mkv)\\Presets comparison at CRF 23/Raw JSON Data/superfast.json'
            output_folder = f'({filename})/Presets comparison at CRF {crf}'
            os.makedirs(output_folder, exist_ok=True)
            comparison_table = os.path.join(output_folder, 'Table.txt')
            table_column_names.insert(0, 'Preset')
            # Set the names of the columns
            table.field_names = table_column_names

            # The user only wants to transcode the first x seconds of the video.
            if args.encode_length:
                original_video_path = cut_video(filename, args, output_ext,
                                                output_folder,
                                                comparison_table)

            # Transcode the video with each preset.
            for preset in chosen_presets:
                transcode_output_path = os.path.join(output_folder,
                                                     f'{preset}{output_ext}')
                graph_filename = f"Preset '{preset}'"

                arguments = EncodingArguments()
                arguments.infile = original_video_path
                arguments.encoder = Encoder[video_encoder]
                arguments.crf = str(crf)
                arguments.preset = preset
                arguments.outfile = transcode_output_path

                process = factory.create_process(arguments)

                line()
                print(f'Transcoding the video with preset {preset}...')
                timer.start()
                process.run()
                time_rounded = timer.end(decimal_places)
                print('Done!')

                transcode_size = os.path.getsize(
                    transcode_output_path) / 1_000_000
                transcoded_bitrate = provider.get_bitrate(
                    transcode_output_path)
                size_rounded = force_decimal_places(
                    round(transcode_size, decimal_places), decimal_places)
                data_for_current_row = [
                    f'{size_rounded} MB', transcoded_bitrate
                ]

                os.makedirs(os.path.join(output_folder, 'Raw JSON Data'),
                            exist_ok=True)
                # os.path.join doesn't work with libvmaf's log_path option so we're manually defining the path with
                # slashes.
                json_file_path = f'{output_folder}/Raw JSON Data/{preset}.json'

                run_libvmaf(transcode_output_path, args, json_file_path, fps,
                            original_video_path, factory)

                create_table_plot_metrics(comparison_table, json_file_path,
                                          args, decimal_places,
                                          data_for_current_row, graph_filename,
                                          table, output_folder, time_rounded,
                                          preset)

            with open(comparison_table, 'a') as f:
                f.write(f'\nFile Transcoded: {filename}')
                f.write(f'\nBitrate: {original_bitrate}')
                f.write(f'\nEncoder used for the transcodes: {video_encoder}')
                f.write(f'\nCRF value used for the transcodes: {crf}')

    # -ntm argument was specified.
    else:
        line()
        output_folder = f'({filename})'
        os.makedirs(output_folder, exist_ok=True)
        comparison_table = os.path.join(output_folder, 'Table.txt')
        table.field_names = table_column_names
        # os.path.join doesn't work with libvmaf's log_path option so we're manually defining the path with slashes.
        json_file_path = f'{output_folder}/QualityMetrics.json'
        # Run libvmaf to get the quality metric(s).
        run_libvmaf(args.transcoded_video_path, args, json_file_path, fps,
                    original_video_path, factory)

        transcode_size = os.path.getsize(
            args.transcoded_video_path) / 1_000_000
        size_rounded = force_decimal_places(
            round(transcode_size, decimal_places), decimal_places)
        transcoded_bitrate = provider.get_bitrate(args.transcoded_video_path)
        data_for_current_row = [f'{size_rounded} MB', transcoded_bitrate]

        graph_filename = 'The variation of the quality of the transcoded video throughout the video'
        # Create the table and plot the metrics if -dqm was not specified.
        create_table_plot_metrics(json_file_path,
                                  args,
                                  decimal_places,
                                  data_for_current_row,
                                  graph_filename,
                                  table,
                                  output_folder,
                                  time_rounded=None,
                                  crf_or_preset=None)

    line()
    print(f'All done! Check out the ({filename}) folder.')
Example #6
0
Implemented is only logging to Faceebook according to
its login process at the time
"""

import requests, utils
from http.cookies import SimpleCookie
from http import cookies

# Loging of requests
# logging.basicConfig(level=logging.DEBUG)

url = 'http://www.facebook.com/login.php?login_attempt=1'

missing_arg = utils.check_required_arg(utils.login_opt, utils.password_opt)
if missing_arg is not None:
    utils.exit_program("Missing required argument " + missing_arg)



email = utils.get_arg(utils.login_opt)
password = utils.get_arg(utils.password_opt)
payload = {'email': email, 'pass' : password}

resp_counter = 0

def log_response(response):
    print('Response:', response)
    indent = '\t'
    print(indent, 'Status:', response.status_code)
    if response.status_code != 200:
        print(indent, 'Redirect to:', response.headers['location'])
Example #7
0
    line()
    log.info('For more details about the available arguments, enter "python main.py -h"')
    line()

args = parser.parse_args()
original_video_path = args.original_video_path
filename = Path(original_video_path).name
video_encoder = args.video_encoder

args_validator = ArgumentsValidator()
validation_result, validation_errors = args_validator.validate(args)

if not validation_result:
    for error in validation_errors:
        log.info(f'Error: {error}')
    exit_program('Argument validation failed.')


def create_output_folder_initialise_table(crf_or_preset):
    if args.output_folder:
        output_folder = f'{args.output_folder}/{crf_or_preset} Comparison'
    else:
        output_folder = f'({filename})/{crf_or_preset} Comparison'

    comparison_table = os.path.join(output_folder, 'Table.txt')
    table_column_names.insert(0, crf_or_preset)
    # Set the names of the columns
    table.field_names = table_column_names

    output_ext = Path(args.original_video_path).suffix
    # The M4V container does not support the H.265 codec.