Recherche avancée

Médias (91)

Autres articles (66)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

Sur d’autres sites (5800)

  • fftools/ffplay : get rid of flush_pkt

    7 février 2021, par Marton Balint
    fftools/ffplay : get rid of flush_pkt
    

    The packet serial can be used instead to detect when a flush is needed.

    Signed-off-by : Marton Balint <cus@passwd.hu>

    • [DH] fftools/ffplay.c
  • How to set crontab in order to run multiple python and a shell scripts ?

    5 janvier 2021, par Alexander Mitsou

    I need to start three python3 scripts and a shell script using crontab. These scripts should run at the same time without any delay. Each script runs exactly for one minute. For instance I have scheduled crontab to run these scripts every 5 minutes.

    &#xA;

    My problem is that, if I attempt to run each script individually from terminal it executes with no further errors, but using crontab nothing happens.

    &#xA;

    DISCLAIMER : If I set up the Python3 scripts individually in crontab, they work fine !

    &#xA;

    Here's my crontab set up :

    &#xA;

    */5 * * * * cd /home/user/Desktop/ &amp;&amp; /usr/bin/python3 script1.py >> report1.log&#xA;&#xA;*/5 * * * * cd /home/user/Desktop/ &amp;&amp; /usr/bin/python3 script2.py >> report2.log&#xA;&#xA;*/5 * * * * cd /home/user/Desktop/ &amp;&amp; /usr/bin/python3 script3.py >> report3.log&#xA;&#xA;*/5 * * * * cd /home/user/Desktop/ &amp;&amp; /usr/bin/sh script4.sh >> report4.log &#xA;

    &#xA;

    In addition I need to mention that the shell script contains this command (FFMPEG) :

    &#xA;

    #!/bin/bash&#xA;&#xA;parent_dir=`dirname \`pwd\`` &#xA;folder_name="/Data/Webcam" &#xA;new_path=$parent_dir$folder_name  &#xA;&#xA;&#xA;if [ -d "$new_path" ]; then&#xA;    echo "video_audio folder exists..."&#xA;else&#xA;    echo "Creating video_audio folder in the current directory..."&#xA;    mkdir -p -- "$new_path"&#xA;    sudo chmod 777 "$new_path"&#xA;    echo "Folder created"&#xA;    echo&#xA;fi&#xA;&#xA;now=$(date &#x2B;%F) &#xA;now="$( echo -e "$now" | tr  &#x27;-&#x27; &#x27;_&#x27;  )"&#xA;sub_dir=$new_path&#x27;/&#x27;$now &#xA;&#xA;if [ -d "$sub_dir" ]; then&#xA;    echo "Date Sub-directory exists..."&#xA;    echo&#xA;else&#xA;    echo "Error: ${sub_dir} not found..."&#xA;    echo "Creating date sub-directory..."&#xA;    mkdir -p -- "$sub_dir"&#xA;    sudo chmod 777 "$sub_dir"&#xA;    echo "Date sub-directory created..."&#xA;    echo&#xA;fi&#xA;&#xA;fname=$(date &#x2B;%H_%M_%S)".avi"&#xA;video_dir=$sub_dir&#x27;/&#x27;$fname&#xA;ffmpeg -f pulse -ac 1 -i default -f v4l2 -i  /dev/video0 -vcodec libx264 -t 00:01:00 $video_dir &#xA;

    &#xA;

    The log file of that script contain the following :

    &#xA;

    video_audio folder exists...&#xA;Date Sub-directory exists...&#xA;&#xA;Package ffmpeg is already installed...&#xA;Package v4l-utils is already installed...&#xA;&#xA;Package: ffmpeg&#xA;Status: install ok installed&#xA;Priority: optional&#xA;Section: video&#xA;Installed-Size: 2010&#xA;Maintainer: Ubuntu Developers &lt;ubuntu-devel-discuss@lists.ubuntu.com&gt;&#xA;Architecture: amd64&#xA;Multi-Arch: foreign&#xA;Version: 7:4.2.4-1ubuntu0.1&#xA;Replaces: libav-tools (&lt;&lt; 6:12~~), qt-faststart (&lt;&lt; 7:2.7.1-3~)&#xA;Depends: libavcodec58 (= 7:4.2.4-1ubuntu0.1), libavdevice58 (= 7:4.2.4-1ubuntu0.1), libavfilter7 (= 7:4.2.4-1ubuntu0.1), libavformat58 (= 7:4.2.4-1ubuntu0.1), libavresample4 (= 7:4.2.4-1ubuntu0.1), libavutil56 (= 7:4.2.4-1ubuntu0.1), libc6 (>= 2.29), libpostproc55 (= 7:4.2.4-1ubuntu0.1), libsdl2-2.0-0 (>= 2.0.10), libswresample3 (= 7:4.2.4-1ubuntu0.1), libswscale5 (= 7:4.2.4-1ubuntu0.1)&#xA;Suggests: ffmpeg-doc&#xA;Breaks: libav-tools (&lt;&lt; 6:12~~), qt-faststart (&lt;&lt; 7:2.7.1-3~), winff (&lt;&lt; 1.5.5-5~)&#xA;Description: Tools for transcoding, streaming and playing of multimedia files&#xA; FFmpeg is the leading multimedia framework, able to decode, encode, transcode,&#xA; mux, demux, stream, filter and play pretty much anything that humans and&#xA; machines have created. It supports the most obscure ancient formats up to the&#xA; cutting edge.&#xA; .&#xA; This package contains:&#xA;  * ffmpeg: a command line tool to convert multimedia files between formats&#xA;  * ffplay: a simple media player based on SDL and the FFmpeg libraries&#xA;  * ffprobe: a simple multimedia stream analyzer&#xA;  * qt-faststart: a utility to rearrange Quicktime files&#xA;Homepage: https://ffmpeg.org/&#xA;Original-Maintainer: Debian Multimedia Maintainers &lt;debian-multimedia@lists.debian.org&gt;&#xA;Package: v4l-utils&#xA;Status: install ok installed&#xA;Priority: optional&#xA;Section: utils&#xA;Installed-Size: 2104&#xA;Maintainer: Ubuntu Developers &lt;ubuntu-devel-discuss@lists.ubuntu.com&gt;&#xA;Architecture: amd64&#xA;Version: 1.18.0-2build1&#xA;Replaces: ivtv-utils (&lt;&lt; 1.4.1-2), media-ctl&#xA;Depends: libv4l-0 (= 1.18.0-2build1), libv4l2rds0 (= 1.18.0-2build1), libc6 (>= 2.17), libgcc-s1 (>= 3.0), libstdc&#x2B;&#x2B;6 (>= 5.2), libudev1 (>= 183)&#xA;Breaks: ivtv-utils (&lt;&lt; 1.4.1-2), media-ctl&#xA;Description: Collection of command line video4linux utilities&#xA; v4l-utils contains the following video4linux command line utilities:&#xA; .&#xA;  decode_tm6000: decodes tm6000 proprietary format streams&#xA;  rds-ctl: tool to receive and decode Radio Data System (RDS) streams&#xA;  v4l2-compliance: tool to test v4l2 API compliance of drivers&#xA;  v4l2-ctl, cx18-ctl, ivtv-ctl: tools to control v4l2 controls from the cmdline&#xA;  v4l2-dbg: tool to directly get and set registers of v4l2 devices&#xA;  v4l2-sysfs-path: sysfs helper tool&#xA;Original-Maintainer: Gregor Jasny &lt;gjasny@googlemail.com&gt;&#xA;Homepage: https://linuxtv.org/downloads/v4l-utils/&#xA;

    &#xA;

    Due to the reason that the python files are of the same structure I'm uploading a sample file here :

    &#xA;

    # -*- coding: utf-8 -*-&#xA;from threading import Timer&#xA;from pynput.mouse import Listener&#xA;import logging&#xA;import sys&#xA;import os&#xA;sys.path.insert(0, os.path.join(os.path.dirname(&#xA;    os.path.realpath(__file__)), "../"))&#xA;&#xA;from Functions import utils as ut&#xA;&#xA;if __name__==&#x27;__main__&#x27;:&#xA;&#xA;    ut.initialize_dirs()&#xA;    rec_file = &#x27;&#x27;.join((&#x27;mouse_&#x27;,ut.get_date(),&#x27;.txt&#x27;))&#xA;    raw_data = ut.get_name(&#x27;Mouse&#x27;)&#xA;    rec_file = os.path.join(raw_data,rec_file)&#xA;    logging.basicConfig(filename=rec_file,level=logging.DEBUG,format="%(asctime)s    %(message)s")&#xA;&#xA;    try:&#xA;        with Listener(on_move=ut.on_move, on_click=ut.on_click,on_scroll=ut.on_scroll) as listener:&#xA;            Timer(60, listener.stop).start()&#xA;            listener.join()&#xA;    except KeyboardInterrupt as err:&#xA;        print(err)&#xA;        sys.exit(0)&#xA;&#xA;    print(&#x27;Exiting logger...&#x27;)&#xA;&#xA;

    &#xA;

    I'm also uploading the functions that I use :

    &#xA;

    # -*- coding: utf-8 -*-&#xA;from serial import Serial&#xA;from datetime import datetime, timedelta&#xA;import pandas as pd&#xA;import collections&#xA;import logging&#xA;import shutil&#xA;import serial&#xA;import time&#xA;import sys&#xA;import os&#xA;&#xA;click_held = False&#xA;button = None&#xA;&#xA;&#xA;def on_move(x,y):&#xA;    """The callback to call when mouse move events occur&#xA;&#xA;    Args:&#xA;        x (float): The new pointer position&#xA;        y (float): The new pointer poisition&#xA;    """&#xA;    if click_held:&#xA;        logging.info("MV    {0:>8}  {1:>8}  {2:>8}:".format(x,y,str(None)))&#xA;    else:&#xA;        logging.info("MV    {0:>8}  {1:>8}  {2:>8}:".format(x,y,str(None)))&#xA;&#xA;&#xA;def on_click(x,y,button,pressed):&#xA;    """The callback to call when a mouse button is clicked&#xA;&#xA;    Args:&#xA;        x (float): Mouse coordinates on screen&#xA;        y (float): Mouse coordinates on screen&#xA;        button (str): one of the Button values&#xA;        pressed (bool): Pressed is whether the button was pressed&#xA;    """&#xA;    global click_held&#xA;    if pressed:&#xA;        click_held = True&#xA;        logging.info("CLK    {0:>7}    {1:>6}    {2:>13}".format(x,y,button))&#xA;    else:&#xA;        click_held = False&#xA;        logging.info("RLS    {0:>7}    {1:>6}    {2:>13}".format(x,y,button))&#xA;&#xA;&#xA;def on_scroll(x,y,dx,dy):&#xA;    """The callback to call when mouse scroll events occur&#xA;&#xA;    Args:&#xA;        x (float): The new pointer position on screen&#xA;        y (float): The new pointer position on screen&#xA;        dx (int): The horizontal scroll. The units of scrolling is undefined&#xA;        dy (int): The vertical scroll. The units of scrolling is undefined&#xA;    """&#xA;    if dy == -1:&#xA;        logging.info("SCRD    {0:>6}    {1:>6}    {2:>6}".format(x,y,str(None)))&#xA;    elif dy == 1:&#xA;        logging.info("SCRU    {0:>6}    {1:>6}    {2:>6}".format(x,y,str(None)))&#xA;    else:&#xA;        pass&#xA;&#xA;&#xA;def on_press_keys(key):&#xA;    """The callback to call when a button is pressed.&#xA;&#xA;    Args:&#xA;        key (str): A KeyCode,a Key or None if the key is unknown&#xA;    """&#xA;    subkeys = [&#xA;    &#x27;Key.alt&#x27;,&#x27;Key.alt_gr&#x27;,&#x27;Key.alt_r&#x27;,&#x27;Key.backspace&#x27;,&#xA;    &#x27;Key.space&#x27;,&#x27;Key.ctrl&#x27;,&#x27;Key.ctrl_r&#x27;,&#x27;Key.down&#x27;,&#xA;    &#x27;Key.up&#x27;,&#x27;Key.left&#x27;,&#x27;Key.right&#x27;,&#x27;Key.page_down&#x27;,&#xA;    &#x27;Key.page_up&#x27;,&#x27;Key.enter&#x27;,&#x27;Key.shift&#x27;,&#x27;Key.shift_r&#x27;&#xA;    ]&#xA;&#xA;    key = str(key).strip(&#x27;\&#x27;&#x27;)&#xA;    if(key in subkeys):&#xA;        #print(key)&#xA;        logging.info(key)&#xA;    else:&#xA;        pass&#xA;&#xA;&#xA;def record_chair(output_file):&#xA;    """Read the data stream coming from the serial monitor&#xA;       in order to get the sensor readings&#xA;&#xA;    Args:&#xA;        output_file (str): The file name, where the data stream will be stored&#xA;    """&#xA;    serial_port = "/dev/ttyACM0"&#xA;    baud_rate = 9600&#xA;    ser = serial.Serial(serial_port,baud_rate)&#xA;    logging.basicConfig(filename=output_file,level=logging.DEBUG,format="%(asctime)s    %(message)s")&#xA;    flag = False&#xA;    start = time.time()&#xA;    while time.time() - start &lt; 60.0:&#xA;        try:&#xA;            serial_data = str(ser.readline().decode().strip(&#x27;\r\n&#x27;))&#xA;            time.sleep(0.2)&#xA;            tmp = serial_data.split(&#x27;  &#x27;)[0] #Getting Sensor Id&#xA;            if(tmp == &#x27;A0&#x27;):&#xA;                flag = True&#xA;            if (flag and tmp != &#x27;A4&#x27;):&#xA;                #print(serial_data)&#xA;                logging.info(serial_data)&#xA;            if(flag and tmp == &#x27;A4&#x27;):&#xA;                flag = False&#xA;                #print(serial_data)&#xA;                logging.info(serial_data)&#xA;        except (UnicodeDecodeError, KeyboardInterrupt) as err:&#xA;            print(err)&#xA;            print(err.args)&#xA;            sys.exit(0)&#xA;&#xA;&#xA;def initialize_dirs():&#xA;    """Create the appropriate directories in order to save&#xA;       and process the collected data&#xA;    """&#xA;    current_path = os.path.abspath(os.getcwd())&#xA;    os.chdir(&#x27;..&#x27;)&#xA;    current_path = (os.path.abspath(os.curdir)) #/Multodal_User_Monitoring&#xA;    current_path = os.path.join(current_path,&#x27;Data&#x27;)&#xA;    create_subdirs([current_path])&#xA;&#xA;    #Create mouse log folder&#xA;    mouse = os.path.join(current_path,&#x27;Mouse&#x27;)&#xA;    create_subdirs([mouse])&#xA;    #Create mouse subfolders&#xA;    names = concat_names(mouse)&#xA;    create_subdirs(names)&#xA;&#xA;    #Create keyboard log  folder&#xA;    keyboard = os.path.join(current_path,&#x27;Keyboard&#x27;)&#xA;    create_subdirs([keyboard])&#xA;    #Create keyboard subfolders&#xA;    names = concat_names(keyboard)&#xA;    create_subdirs(names)&#xA;&#xA;    #Create the chair log folder&#xA;    chair = os.path.join(current_path,&#x27;Chair&#x27;)&#xA;    create_subdirs([chair])&#xA;    #Create chair subfolders&#xA;    names = concat_names(chair)&#xA;    create_subdirs(names)&#xA;&#xA;    #Create webcam log folder&#xA;    webcam = os.path.join(current_path,&#x27;Webcam&#x27;)&#xA;    create_subdirs([webcam])&#xA;&#xA;def concat_names(dir) -> str:&#xA;    """Concatenate the given folder names&#xA;       with the appropriate path&#xA;&#xA;    Args:&#xA;        dir (str): The directory to create the subfolders&#xA;&#xA;    Returns:&#xA;        list: The new absolute paths&#xA;    """&#xA;    raw_data = os.path.join(dir,&#x27;Raw&#x27;)&#xA;    edited_data = os.path.join(dir,&#x27;Edited_logs&#x27;)&#xA;    csv_data = os.path.join(dir,&#x27;CSV&#x27;)&#xA;    features = os.path.join(dir,&#x27;Features&#x27;)&#xA;    dirs = [raw_data,edited_data,csv_data,features]&#xA;    return dirs&#xA;&#xA;&#xA;def create_subdirs(paths):&#xA;    """Create sub directories given some absolute paths&#xA;&#xA;    Args:&#xA;        paths (list): A list containing the paths to be created&#xA;    """&#xA;    for index,path in enumerate(paths):&#xA;        if(os.path.isdir(paths[index])):&#xA;            pass&#xA;        else:&#xA;            os.mkdir(paths[index])&#xA;&#xA;&#xA;def round_down(num,divisor) -> int:&#xA;    """Round the number of lines contained into the recording file,&#xA;       down to the nearest multiple of the given divisor&#xA;&#xA;    Args:&#xA;        num (int): The number of lines contained into the given log file&#xA;        divisor (int): The divisor in order to get tuples of divisor&#xA;&#xA;    Returns:&#xA;        int: The nearest multiple of five&#xA;    """&#xA;    return num-(num%divisor)&#xA;&#xA;&#xA;def get_date() -> str:&#xA;    """Get the current date in order to properly name&#xA;       the recored log files&#xA;    Returns:&#xA;        str: The current date in: YY_MM_DD format&#xA;    """&#xA;    return datetime.now().strftime(&#x27;%Y_%m_%d&#x27;)&#xA;&#xA;&#xA;def get_name(modality) -> str:&#xA;    """Save the recorded log into /Data//Raw&#xA;&#xA;    Args:&#xA;        modality (str): The log data source&#xA;&#xA;    Returns:&#xA;        str: The absolute path where each recording is saved&#xA;    """&#xA;    current_path = os.path.abspath(os.getcwd())&#xA;    current_path = os.path.join(current_path,&#x27;Data&#x27;)&#xA;&#xA;    if modality == &#x27;Chair&#x27;:&#xA;        chair_path = os.path.join(current_path,modality,&#x27;Raw&#x27;)&#xA;        return chair_path&#xA;&#xA;    elif modality == &#x27;Mouse&#x27;:&#xA;        mouse_path = os.path.join(current_path,modality,&#x27;Raw&#x27;)&#xA;        return mouse_path&#xA;&#xA;    elif modality == &#x27;Keyboard&#x27;:&#xA;        keyboard_path = os.path.join(current_path,modality,&#x27;Raw&#x27;)&#xA;        return keyboard_path&#xA;&#xA;&#xA;def crawl_dir(target,folder) -> str:&#xA;    """Enumerate all the given files in a directory&#xA;       based on the given file extension&#xA;&#xA;    Args:&#xA;        target (str): The file to search for&#xA;        folder (str): The folder to search&#xA;&#xA;    Returns:&#xA;        [type]: A list containing the file names&#xA;    """&#xA;    current_path = os.path.abspath(os.getcwd())&#xA;    path = os.path.join(current_path,folder)&#xA;    file_names =[]&#xA;    for f in os.listdir(path):&#xA;        if(f.endswith(target)):&#xA;            fname=os.path.join(path,f)&#xA;            file_names.append(fname)&#xA;    return file_names&#xA;&#xA;&#xA;def convert_keys2_csv(input_file,output_file):&#xA;    """Convert the data stream file(keylogger recording) from .txt to .csv format&#xA;&#xA;    Args:&#xA;        input_file (str): The data stream file in .txt format&#xA;        output_file (str): The csv extension file name&#xA;    """&#xA;    df = pd.read_fwf(input_file)&#xA;    col_names = [&#x27;Date&#x27;,&#x27;Time&#x27;,&#x27;Key&#x27;]&#xA;    df.to_csv(output_file,header=col_names,encoding=&#x27;utf-8&#x27;,index=False)&#xA;&#xA;&#xA;def convert_mouse2_csv(input_file,output_file):&#xA;    """Convert the data stream file(mouselogger recording) from .txt to .csv format&#xA;&#xA;    Args:&#xA;        input_file (str): The data stream file in .txt format&#xA;        output_file (str): The csv extension file name&#xA;    """&#xA;    df = pd.read_fwf(input_file)&#xA;    col_names = [&#x27;Date&#x27;,&#x27;Time&#x27;,&#x27;Action&#x27;,&#x27;PosX&#x27;,&#x27;PosY&#x27;,&#x27;Button&#x27;]&#xA;    df.to_csv(output_file,header=col_names,encoding=&#x27;utf-8&#x27;,index=False)&#xA;&#xA;&#xA;def convert_chair_2_csv(input_file,output_file):&#xA;    """Convert the data stream file(chair recording)&#xA;       from .txt to .csv format&#xA;&#xA;    Args:&#xA;        input_file (str): The data stream file in .txt format&#xA;        output_file (str): The csv extension file name&#xA;    """&#xA;    if(os.path.isfile(input_file)):&#xA;        pass&#xA;    else:&#xA;        print(&#x27;Invalid working directory...&#x27;)&#xA;        print(&#x27;Aborting...&#x27;)&#xA;        sys.exit(0)&#xA;&#xA;    tmp0,tmp1,tmp2,tmp3,tmp4 = 0,1,2,3,4&#xA;&#xA;    line_number = 0&#xA;    for line in open(input_file).readlines():&#xA;        line_number &#x2B;= 1&#xA;&#xA;    rounded_line = round_down(line_number,5)&#xA;    d = collections.defaultdict(list)&#xA;&#xA;    with open(input_file,&#x27;r&#x27;) as f1:&#xA;        lines = f1.readlines()&#xA;        for i in range(rounded_line // 5):&#xA;            #Sensor:Analog input 0 values&#xA;            Sid0 = lines[i&#x2B;tmp0]&#xA;            temp = Sid0.split()&#xA;            d[&#x27;Sid0&#x27;].append([temp[0],temp[1],temp[2],temp[3]])&#xA;            #Sensor:Analog input 1 values&#xA;            Sid1 = lines[i&#x2B;tmp1]&#xA;            temp = Sid1.split()&#xA;            d[&#x27;Sid1&#x27;].append([temp[0],temp[1],temp[2],temp[3]])&#xA;            #Sensor:Analog input 2 values&#xA;            Sid2 = lines[i&#x2B;tmp2]&#xA;            temp = Sid2.split()&#xA;            d[&#x27;Sid2&#x27;].append([temp[0],temp[1],temp[2],temp[3]])&#xA;            #Sensor:Analog input 3 values&#xA;            Sid3 = lines[i&#x2B;tmp3]&#xA;            temp = Sid3.split()&#xA;            d[&#x27;Sid3&#x27;].append([temp[0],temp[1],temp[2],temp[3]])&#xA;            #Sensor:Analog input 4 values&#xA;            Sid4 = lines[i&#x2B;tmp4]&#xA;            temp = Sid4.split()&#xA;            d[&#x27;Sid4&#x27;].append([temp[0],temp[1],temp[2],temp[3]])&#xA;&#xA;            tmp0 &#x2B;= 4&#xA;            tmp1 &#x2B;= 4&#xA;            tmp2 &#x2B;= 4&#xA;            tmp3 &#x2B;= 4&#xA;            tmp4 &#x2B;= 4&#xA;&#xA;    l = []&#xA;    for i in range(rounded_line // 5):&#xA;        date = d[&#x27;Sid0&#x27;][i][0]&#xA;        time = d[&#x27;Sid0&#x27;][i][1]&#xA;        A0_val = d[&#x27;Sid0&#x27;][i][3]&#xA;        A1_val = d[&#x27;Sid1&#x27;][i][3]&#xA;        A2_val = d[&#x27;Sid2&#x27;][i][3]&#xA;        A3_val = d[&#x27;Sid3&#x27;][i][3]&#xA;        A4_val = d[&#x27;Sid4&#x27;][i][3]&#xA;        l.append([date,time,A0_val,A1_val,A2_val,A3_val,A4_val])&#xA;&#xA;    sensor_readings_df = pd.DataFrame.from_records(l)&#xA;    sensor_readings_df.columns = [&#x27;Date&#x27;,&#x27;Time&#x27;,&#x27;A0&#x27;,&#x27;A1&#x27;,&#x27;A2&#x27;,&#x27;A3&#x27;,&#x27;A4&#x27;]&#xA;    sensor_readings_df.to_csv(output_file, encoding=&#x27;utf-8&#x27;, index=False)&#xA;    del l&#xA;&#xA;&#xA;def parse_raw_data(modality):&#xA;    """Convert each modality&#x27;s raw data into csv format and move&#xA;       the edited raw data into the appropriate Edited_logs folder&#xA;&#xA;    Args:&#xA;        modality (str): The data source&#xA;    """&#xA;    #Change directories&#xA;    current_path = os.path.abspath(os.getcwd()) #/Functions&#xA;    os.chdir(&#x27;..&#x27;)&#xA;    current_path = (os.path.abspath(os.curdir)) #/Multimodal_User_Monitoring&#xA;    os.chdir(&#x27;./Data&#x27;)#/Multimodal_User_Monitoring/Data&#xA;    current_path = (os.path.abspath(os.curdir)) #/Multimodal_User_Monitoring/Data&#xA;    current_path = os.path.join(current_path,modality) #example: /Multimodal_User_Monitoring/Data/<modality>&#xA;    raw_data_path = os.path.join(current_path,&#x27;Raw&#x27;)&#xA;    csv_data_path = os.path.join(current_path,&#x27;CSV&#x27;)&#xA;    edited_logs_path = os.path.join(current_path,&#x27;Edited_logs&#x27;)&#xA;&#xA;    txt_names = crawl_dir(&#x27;.txt&#x27;,raw_data_path)&#xA;    csv_names = []&#xA;    for elem in txt_names:&#xA;        name = elem.split(&#x27;/&#x27;)[-1].split(&#x27;.&#x27;)[0]&#xA;        csv_name = name&#x2B;&#x27;.csv&#x27;&#xA;        tmp = os.path.join(csv_data_path,csv_name)&#xA;        csv_names.append(tmp)&#xA;&#xA;    if modality == &#x27;Mouse&#x27;:&#xA;        if len(txt_names) == len(csv_names):&#xA;            for i, elem in enumerate(txt_names):&#xA;            #for i in range(len(txt_names)):&#xA;                convert_mouse2_csv(txt_names[i],csv_names[i])&#xA;                shutil.move(txt_names[i],edited_logs_path)&#xA;&#xA;    elif modality == &#x27;Keyboard&#x27;:&#xA;        if len(txt_names) == len(csv_names):&#xA;            for i, elem in enumerate(txt_names):&#xA;            #for i in range(len(txt_names)):&#xA;                convert_keys2_csv(txt_names[i],csv_names[i])&#xA;                shutil.move(txt_names[i],edited_logs_path)&#xA;&#xA;    elif modality == &#x27;Chair&#x27;:&#xA;        if len(txt_names) == len(csv_names):&#xA;            for i, elem in enumerate(txt_names):&#xA;            #for i in range(len(txt_names)):&#xA;                convert_chair_2_csv(txt_names[i],csv_names[i])&#xA;                shutil.move(txt_names[i],edited_logs_path)&#xA;&#xA;</modality>

    &#xA;

    I need to mention that the logs of the python3 scripts are empty

    &#xA;

  • ffmpeg takes too long to start

    17 octobre 2020, par Suspended

    I have this command in python script, in a loop :

    &#xA;

    ffmpeg -i somefile.mp4 -ss 00:03:12 -t 00:00:35 piece.mp4 -loglevel error -stats&#xA;

    &#xA;

    It cuts out pieces of input file (-i). Input filename, as well as start time (-ss) and length of the piece I cut out (-t) varies, so it reads number of mp4 files and cuts out number of pieces from each one. During execution of the script it might be called around 100 times. My problem is that each time before it starts, there is a delay of 6-15 seconds and it adds up to significant time. How can I get it to start immediately ?

    &#xA;

    Initially I thought it was process priority problem, but I noticed that even during the "pause", all processors work at 100%, so apparently some work is being done.

    &#xA;

    The script (process_videos.py) :

    &#xA;

    import subprocess&#xA;import sys&#xA;import math&#xA;import time&#xA;&#xA;class TF:&#xA;    """TimeFormatter class (TF).&#xA;This class&#x27; reason for being is to convert time in short&#xA;form, e.g. 1:33, 0:32, or 23 into long form accepted by&#xA;mp4cut function in bash, e.g. 00:01:22, 00:00:32, etc"""&#xA;&#xA;def toLong(self, shrt):&#xA;    """Converts time to its long form"""&#xA;    sx = &#x27;00:00:00&#x27;&#xA;    ladd = 8 - len(shrt)&#xA;    n = sx[:ladd] &#x2B; shrt&#xA;    return n&#xA;&#xA;def toShort(self, lng):&#xA;    """Converts time to short form"""&#xA;    if lng[0] == &#x27;0&#x27; or lng[0] == &#x27;:&#x27;:&#xA;        return self.toShort(lng[1:])&#xA;    else:&#xA;        return lng&#xA;&#xA;def toSeconds(self, any_time):&#xA;    """Converts time to seconds"""&#xA;    if len(any_time) &lt; 3:&#xA;        return int(any_time)&#xA;    tt = any_time.split(&#x27;:&#x27;)&#xA;    if len(any_time) &lt; 6:            &#xA;        return int(tt[0])*60 &#x2B; int(tt[1])&#xA;    return int(tt[0])*3600 &#x2B; int(tt[1])*60 &#x2B; int(tt[2])&#xA;&#xA;def toTime(self, secsInt):&#xA;    """"""&#xA;    tStr = &#x27;&#x27;&#xA;    hrs, mins, secs = 0, 0, 0&#xA;    if secsInt >= 3600:&#xA;        hrs = math.floor(secsInt / 3600)&#xA;        secsInt = secsInt % 3600&#xA;    if secsInt >= 60:&#xA;        mins = math.floor(secsInt / 60)&#xA;        secsInt = secsInt % 60&#xA;    secs = secsInt&#xA;    return str(hrs).zfill(2) &#x2B; &#x27;:&#x27; &#x2B; str(mins).zfill(2) &#x2B; &#x27;:&#x27; &#x2B; str(secs).zfill(2)&#xA;&#xA;def minus(self, t_start, t_end):&#xA;    """"""&#xA;    t_e = self.toSeconds(t_end)&#xA;    t_s = self.toSeconds(t_start)&#xA;    t_r = t_e - t_s&#xA;    hrs, mins, secs = 0, 0, 0&#xA;    if t_r >= 3600:&#xA;        hrs = math.floor(t_r / 3600)&#xA;        t_r = t_r - (hrs * 3600)&#xA;    if t_r >= 60:&#xA;        mins = math.floor(t_r / 60)&#xA;        t_r = t_r - (mins * 60)&#xA;    secs = t_r&#xA;    hrsf = str(hrs).zfill(2)&#xA;    minsf = str(mins).zfill(2)&#xA;    secsf = str(secs).zfill(2)&#xA;    t_fnl = hrsf &#x2B; &#x27;:&#x27; &#x2B; minsf &#x2B; &#x27;:&#x27; &#x2B; secsf&#xA;    return t_fnl&#xA;&#xA;def go_main():&#xA;    tf = TF()&#xA;    vid_n = 0&#xA;    arglen = len(sys.argv)&#xA;    if arglen == 2:&#xA;        with open(sys.argv[1], &#x27;r&#x27;) as f_in:&#xA;            lines = f_in.readlines()&#xA;            start = None&#xA;            end = None&#xA;            cnt = 0&#xA;            for line in lines:&#xA;                if line[:5] == &#x27;BEGIN&#x27;:&#xA;                    start = cnt&#xA;                if line[:3] == &#x27;END&#x27;:&#xA;                    end = cnt&#xA;                cnt &#x2B;= 1&#xA;            if start == None or end == None:&#xA;                print(&#x27;Invalid file format. start = {}, end = {}&#x27;.format(start,end))&#xA;                return&#xA;            else:&#xA;                lines_r = lines[start&#x2B;1:end]&#xA;                del lines&#xA;                print(&#x27;videos to process: {}&#x27;.format(len(lines_r)))&#xA;                f_out_prefix = ""&#xA;                for vid in lines_r:&#xA;                     vid_n &#x2B;= 1&#xA;                    print(&#x27;\nProcessing video {}/{}&#x27;.format(vid_n, len(lines_r)))&#xA;                    f_out_prefix = &#x27;v&#x27; &#x2B; str(vid_n) &#x2B; &#x27;-&#x27;&#xA;                    dat = vid.split(&#x27;!&#x27;)[1:3]&#xA;                    title = dat[0]&#xA;                    dat_t = dat[1].split(&#x27;,&#x27;)&#xA;                    v_pieces = len(dat_t)&#xA;                    piece_n = 0&#xA;                    video_pieces = []&#xA;                    cmd1 = "echo -n \"\" > tmpfile"&#xA;                    subprocess.run(cmd1, shell=True)                    &#xA;                    print(&#x27;  new tmpfile created&#x27;)&#xA;                    for v_times in dat_t:&#xA;                        piece_n &#x2B;= 1&#xA;                        f_out = f_out_prefix &#x2B; str(piece_n) &#x2B; &#x27;.mp4&#x27;&#xA;                        video_pieces.append(f_out)&#xA;                        print(&#x27;  piece filename {} added to video_pieces list&#x27;.format(f_out))&#xA;                        v_times_spl = v_times.split(&#x27;-&#x27;)&#xA;                        v_times_start = v_times_spl[0]&#xA;                        v_times_end = v_times_spl[1]&#xA;                        t_st = tf.toLong(v_times_start)&#xA;                        t_dur = tf.toTime(tf.toSeconds(v_times_end) - tf.toSeconds(v_times_start))&#xA;                        cmd3 = ["ffmpeg", "-i", title, "-ss", t_st, "-t", t_dur, f_out, "-loglevel", "error", "-stats"]&#xA;                        print(&#x27;  cutting out piece {}/{} - {}&#x27;.format(piece_n, len(dat_t), t_dur))&#xA;                        subprocess.run(cmd3)&#xA;                    for video_piece_name in video_pieces:&#xA;                        cmd4 = "echo \"file " &#x2B; video_piece_name &#x2B; "\" >> tmpfile"&#xA;                        subprocess.run(cmd4, shell=True)&#xA;                        print(&#x27;  filename {} added to tmpfile&#x27;.format(video_piece_name))&#xA;                    vname = f_out_prefix[:-1] &#x2B; ".mp4"&#xA;                    print(&#x27;  name of joined file: {}&#x27;.format(vname))&#xA;                    cmd5 = "ffmpeg -f concat -safe 0 -i tmpfile -c copy joined.mp4 -loglevel error -stats"&#xA;                    to_be_joined = " ".join(video_pieces)&#xA;                    print(&#x27;  joining...&#x27;)&#xA;                    join_cmd = subprocess.Popen(cmd5, shell=True)&#xA;                    join_cmd.wait()&#xA;                    print(&#x27;  joined!&#x27;)&#xA;                    cmd6 = "mv joined.mp4 " &#x2B; vname&#xA;                    rename_cmd = subprocess.Popen(cmd6, shell=True)&#xA;                    rename_cmd.wait()&#xA;                    print(&#x27;  File joined.mp4 renamed to {}&#x27;.format(vname))&#xA;                    cmd7 = "rm " &#x2B; to_be_joined&#xA;                    rm_cmd = subprocess.Popen(cmd7, shell=True)&#xA;                    rm_cmd.wait()&#xA;                    print(&#x27;rm command completed - pieces removed&#x27;)&#xA;                cmd8 = "rm tmpfile"&#xA;                subprocess.run(cmd8, shell=True)&#xA;                print(&#x27;tmpfile removed&#x27;)&#xA;                print(&#x27;All done&#x27;)&#xA;    else:&#xA;        print(&#x27;Incorrect number of arguments&#x27;)&#xA;&#xA;############################&#xA;if __name__ == &#x27;__main__&#x27;:&#xA;    go_main()&#xA;

    &#xA;

    process_videos.py is called from bash terminal like this :

    &#xA;

    $ python process_videos.py video_data   &#xA;

    &#xA;

    video_data file has the following format :

    &#xA;

    BEGIN&#xA;!first_video.mp4!3-23,55-1:34,2:01-3:15,3:34-3:44!&#xA;!second_video.mp4!2-7,12-44,1:03-1:33!&#xA;END&#xA;

    &#xA;

    My system details :

    &#xA;

    System:    Host: snowflake Kernel: 5.4.0-52-generic x86_64 bits: 64 Desktop: Gnome 3.28.4&#xA;           Distro: Ubuntu 18.04.5 LTS&#xA;Machine:   Device: desktop System: Gigabyte product: N/A serial: N/A&#xA;Mobo:      Gigabyte model: Z77-D3H v: x.x serial: N/A BIOS: American Megatrends v: F14 date: 05/31/2012&#xA;CPU:       Quad core Intel Core i5-3570 (-MCP-) cache: 6144 KB &#xA;           clock speeds: max: 3800 MHz 1: 1601 MHz 2: 1601 MHz 3: 1601 MHz 4: 1602 MHz&#xA;Drives:    HDD Total Size: 1060.2GB (55.2% used)&#xA;           ID-1: /dev/sda model: ST31000524AS size: 1000.2GB&#xA;           ID-2: /dev/sdb model: Corsair_Force_GT size: 60.0GB&#xA;Partition: ID-1: / size: 366G used: 282G (82%) fs: ext4 dev: /dev/sda1&#xA;           ID-2: swap-1 size: 0.70GB used: 0.00GB (0%) fs: swap dev: /dev/sda5&#xA;Info:      Processes: 313 Uptime: 16:37 Memory: 3421.4/15906.9MB Client: Shell (bash) inxi: 2.3.56&#xA;

    &#xA;
    &#xA;

    UPDATE :

    &#xA;

    Following Charles' advice, I used performance sampling :

    &#xA;

    # perf record -a -g sleep 180&#xA;

    &#xA;

    ...and here's the report :

    &#xA;

    Samples: 74K of event &#x27;cycles&#x27;, Event count (approx.): 1043554519767&#xA;  Children      Self  Command          Shared Object&#xA;-   50.56%    45.86%  ffmpeg           libavcodec.so.57.107.100                                                                                &#xA;   - 3.10% 0x4489480000002825                                                                                                                  &#xA;       0.64% 0x7ffaf24b92f0                                                                                                                   &#xA;   - 2.12% 0x5f7369007265646f                                                                                                                  &#xA;       av_default_item_name                                                                                                                   &#xA;     1.39% 0                                                                                                                                   &#xA;-   44.48%    40.59%  ffmpeg           libx264.so.152                                                                                          &#xA;     5.78% x264_add8x8_idct_avx2.skip_prologue                                                                                                 &#xA;     3.13% x264_add8x8_idct_avx2.skip_prologue                                                                                                 &#xA;     2.91% x264_add8x8_idct_avx2.skip_prologue                                                                                                 &#xA;     2.31% x264_add8x8_idct_avx.skip_prologue                                                                                                  &#xA;     2.03% 0                                                                                                                                   &#xA;     1.78% 0x1                                                                                                                                 &#xA;     1.26% x264_add8x8_idct_avx2.skip_prologue                                                                                                 &#xA;     1.09% x264_add8x8_idct_avx.skip_prologue                                                                                                  &#xA;     1.06% x264_me_search_ref                                                                                                                  &#xA;     0.97% x264_add8x8_idct_avx.skip_prologue                                                                                                  &#xA;     0.60% x264_me_search_ref                                                                                                                  &#xA;-   38.01%     0.00%  ffmpeg           [unknown]                                                                                               &#xA;     4.10% 0                                                                                                                                   &#xA;   - 3.49% 0x4489480000002825                                                                                                                  &#xA;        0.70% 0x7ffaf24b92f0                                                                                                                   &#xA;        0.56% 0x7f273ae822f0                                                                                                                   &#xA;        0.50% 0x7f0c4768b2f0                                                                                                                   &#xA;   - 2.29% 0x5f7369007265646f                                                                                                                  &#xA;        av_default_item_name                                                                                                                   &#xA;     1.99% 0x1                                                                                                                                 &#xA;    10.13%    10.12%  ffmpeg           [kernel.kallsyms]                                                                                       &#xA;-    3.14%     0.73%  ffmpeg           libavutil.so.55.78.100                                                                                  &#xA;     2.34% av_default_item_name                                                                                                                &#xA;-    1.73%     0.21%  ffmpeg           libpthread-2.27.so                                                                                      &#xA;   - 0.70% pthread_cond_wait@@GLIBC_2.3.2                                                                                                      &#xA;      - 0.62% entry_SYSCALL_64_after_hwframe                                                                                                   &#xA;         - 0.62% do_syscall_64                                                                                                                 &#xA;            - 0.57% __x64_sys_futex                                                                                                            &#xA;                 0.52% do_futex                                                                                                                &#xA;     0.93%     0.89%  ffmpeg           libc-2.27.so                                                                                            &#xA;-    0.64%     0.64%  swapper          [kernel.kallsyms]                                                                                       &#xA;     0.63% secondary_startup_64                                                                                                                &#xA;     0.21%     0.18%  ffmpeg           libavfilter.so.6.107.100                                                                                &#xA;     0.20%     0.11%  ffmpeg           libavformat.so.57.83.100                                                                                &#xA;     0.12%     0.11%  ffmpeg           ffmpeg                                                                                                  &#xA;     0.11%     0.00%  gnome-terminal-  [unknown]                                                                                               &#xA;     0.09%     0.07%  ffmpeg           libm-2.27.so                                                                                            &#xA;     0.08%     0.07%  ffmpeg           ld-2.27.so                                                                                              &#xA;     0.04%     0.04%  gnome-terminal-  libglib-2.0.so.0.5600.4&#xA;

    &#xA;

    &#xA;