Recherche avancée

Médias (0)

Mot : - Tags -/optimisation

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (83)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, 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 (...)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

Sur d’autres sites (13851)

  • Split h.264 stream into multiple parts in python

    31 janvier 2023, par BillPlayz

    My objective is to split an h.264 stream into multiple parts, meaning while reading the stream from a pipe i would like to save it into x second long packages (in my case 10).

    


    I am using a libcamera-vid subprocess on my Raspberry Pi that outputs the h.264 stream into stdout.
    
Might be irrelevant, depends : libcamera-vid outputs a message every frame and I am able to locate it at isFrameStopLine
To convert the stream, I use an ffmpeg subprocess, as you can see in the code below.

    


    Imagine it like that :
    
Stream is running...
    
- Start recording to a file
    
- Sleep x seconds
    
- Finish recording to file
    
- Start recording a new file
    
- Sleep x seconds
    
- Finish recording the new file
    
- and so on...

    


    Here is my current code, however upon running the first export succeeds, and after the second or third the ffmpeg-subprocess is terminating with the error :
    
pipe:: Invalid data found when processing input
    &#xA;And shortly after, the python process, because of the ffmpeg termination i believe.&#xA;Traceback (most recent call last):   File "/home/survpi-camera/main.py", line 56, in <module>     processStreamLine(readData)   File "/home/survpi-camera/main.py", line 16, in processStreamLine     streamInfo["process"].stdin.write(data) BrokenPipeError: [Errno 32] Broken pipe</module>

    &#xA;

    recentStreamProcesses = []&#xA;streamInfo = {&#xA;    "lastStreamStart": -1,&#xA;    "process": None&#xA;}&#xA;&#xA;def processStreamLine(data):&#xA;    isInfoLine = ((data.startswith(b"[") and (b"INFO" in data)) or (data == b"Preview window unavailable"))&#xA;    isFrameStopLine = (data.startswith(b"#") and (b" fps) exp" in data))&#xA;    if ((not isInfoLine) and (not isFrameStopLine)):&#xA;        streamInfo["process"].stdin.write(data)&#xA;    &#xA;    if (isFrameStopLine):&#xA;        if (time.time() - streamInfo["lastStreamStart"] >= 10):&#xA;            print("10 seconds passed, exporting...")&#xA;            exportStream()&#xA;            createNewStream()&#xA;&#xA;def createNewStream():&#xA;    streamInfo["lastStreamStart"] = time.time()&#xA;    streamInfo["process"] = subprocess.Popen([&#xA;        "ffmpeg",&#xA;        "-r","30",&#xA;        "-i","-",&#xA;        "-c","copy",("/home/survpi-camera/" &#x2B; str(round(time.time())) &#x2B; ".mp4")&#xA;    ],stdin=subprocess.PIPE,stderr=subprocess.STDOUT)&#xA;    print("Created new streamProcess.")&#xA;&#xA;def exportStream():&#xA;    print("Exporting...")&#xA;    streamInfo["process"].stdin.close()&#xA;    recentStreamProcesses.append(streamInfo["process"])&#xA;&#xA;&#xA;cameraProcess = subprocess.Popen([&#xA;    "libcamera-vid",&#xA;    "-t","0",&#xA;    "--width","1920",&#xA;    "--height","1080",&#xA;    "--codec","h264",&#xA;    "--inline",&#xA;    "--listen",&#xA;    "-o","-"&#xA;],stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.STDOUT)&#xA;&#xA;createNewStream()&#xA;&#xA;while True:&#xA;    readData = cameraProcess.stdout.readline()&#xA;    &#xA;    processStreamLine(readData)&#xA;

    &#xA;

    Thank you in advance !

    &#xA;

  • Why do I get UnknownValueError when trying to run .recognize_google ?

    21 juillet 2022, par John Smith

    Following code is meant to transcribe a long audio file to text. It is to do this piece by piece. trimmed.wav holds a 15-second-long piece of a longer audio file (whose path is stored in fname) :

    &#xA;

    #!/usr/bin/env python3&#xA;&#xA;from subprocess import run&#xA;from sys import exit&#xA;&#xA;italic = &#x27;\33[3m&#x27;&#xA;end = &#x27;\33[m&#x27;&#xA;&#xA;try:&#xA;    from speech_recognition import AudioFile, Recognizer&#xA;except:&#xA;    run("pip3 install SpeechRecognition", shell=True)&#xA;    from speech_recognition import AudioFile, Recognizer&#xA;&#xA;def transcribe_piece(fname, lang, stime):&#xA;    extension = fname[-3:]&#xA;    etime = stime &#x2B; 15&#xA;    cmd = f"ffmpeg -ss {stime} -to {etime} -i {fname} -c copy trimmed.{extension} >/dev/null 2>&amp;1"&#xA;    run(cmd, shell=True)&#xA;    cmd = f"ffmpeg -i trimmed.{extension} -f wav trimmed.wav >/dev/null 2>&amp;1"&#xA;    run(cmd, shell=True)&#xA;    r = Recognizer()    &#xA;    af = AudioFile("trimmed.wav")&#xA;    with af as source:&#xA;        r.adjust_for_ambient_noise(source)&#xA;        audio = r.record(source)&#xA;        t = r.recognize_google(audio, language=lang)#UnknownValueError() speech_recognition.UnknownValueError&#xA;        print(f"{italic}{t}{end}")&#xA;        with open("of", "w") as f:&#xA;            f.write(f"{t}\n")&#xA;    run(f"rm trimmed.{extension}", shell=True) &#xA;    run(f"rm trimmed.wav", shell=True)&#xA;    &#xA;    &#xA;&#xA;fname = input("File name? Skip the path if the file is in CWD. The usage of ~ is allowed.\n")&#xA;&#xA;lang = input("""Specify one of the following languages:&#xA;fr-BE, fr-CA, fr-FR, fr-CH&#xA;&#xA;en-AU, en-CA, en-GH, en-HK, en-IN, en-IE, en-KE, en-NZ, en-PK, en-PH, en-SG, en-ZA, en-TZ, en-GB, en-US&#xA;&#xA;es-AR, es-BO, es-BO, es-CL, es-CO, es-CR, es-DO, es-EC, es-SV, es-SV, es-GT, es-HN, es-MX, es-NI, es-PA, es-PY, es-PE, es-PR, es-ES, es-US, es-UY, es-VE\n""")&#xA;&#xA;&#xA;#for stime in range(0, 10000, 15):&#xA;#    try:&#xA;#        transcribe_piece(fname, lang, stime)&#xA;#    except:&#xA;#        run("shred -u trimmed.wav" , shell=True) &#xA;        #run("shred -u trimmed.wav >/dev/null 2>&amp;1" , shell=True) &#xA;#        exit(0)&#xA;        &#xA;for stime in range(0, 10000, 15):#this loop is only for the sake of debugging, use try/except above&#xA;    transcribe_piece(fname, lang, stime)&#xA;&#xA;

    &#xA;

    It gives me the following error :

    &#xA;

    Traceback (most recent call last):&#xA;  File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 61, in <module>&#xA;    transcribe_piece(fname, lang, stime)&#xA;  File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 31, in transcribe_piece&#xA;    t = r.recognize_google(audio, language=lang)&#xA;  File "/home/jim/.local/lib/python3.10/site-packages/speech_recognition/__init__.py", line 858, in recognize_google&#xA;    if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()&#xA;speech_recognition.UnknownValueError&#xA;&#xA;</module>

    &#xA;

    The said error refers to line 31, that is t = r.recognize_google(audio, language=lang).&#xA;Why do I get this error ? How might I rewrite this code so that such error does not appear ?

    &#xA;

  • Why do I get UnknownValueError() speech_recognition.UnknownValueError when trying to run .recognize_google ?

    20 juillet 2022, par John Smith

    Following code is meant to transcribe a long audio file to text. It is to do this piece by piece. trimmed.wav holds a 15-second-long piece of a longer audio file (whose path is stored in fname) :

    &#xA;

    #!/usr/bin/env python3&#xA;&#xA;from subprocess import run&#xA;from sys import exit&#xA;&#xA;italic = &#x27;\33[3m&#x27;&#xA;end = &#x27;\33[m&#x27;&#xA;&#xA;try:&#xA;    from speech_recognition import AudioFile, Recognizer&#xA;except:&#xA;    run("pip3 install SpeechRecognition", shell=True)&#xA;    from speech_recognition import AudioFile, Recognizer&#xA;&#xA;def transcribe_piece(fname, lang, stime):&#xA;    extension = fname[-3:]&#xA;    etime = stime &#x2B; 15&#xA;    cmd = f"ffmpeg -ss {stime} -to {etime} -i {fname} -c copy trimmed.{extension} >/dev/null 2>&amp;1"&#xA;    run(cmd, shell=True)&#xA;    cmd = f"ffmpeg -i trimmed.{extension} -f wav trimmed.wav >/dev/null 2>&amp;1"&#xA;    run(cmd, shell=True)&#xA;    r = Recognizer()    &#xA;    af = AudioFile("trimmed.wav")&#xA;    with af as source:&#xA;        r.adjust_for_ambient_noise(source)&#xA;        audio = r.record(source)&#xA;        t = r.recognize_google(audio, language=lang)#UnknownValueError() speech_recognition.UnknownValueError&#xA;        print(f"{italic}{t}{end}")&#xA;        with open("of", "w") as f:&#xA;            f.write(f"{t}\n")&#xA;    run(f"rm trimmed.{extension}", shell=True) &#xA;    run(f"rm trimmed.wav", shell=True)&#xA;    &#xA;    &#xA;&#xA;fname = input("File name? Skip the path if the file is in CWD. The usage of ~ is allowed.\n")&#xA;&#xA;lang = input("""Specify one of the following languages:&#xA;fr-BE, fr-CA, fr-FR, fr-CH&#xA;&#xA;en-AU, en-CA, en-GH, en-HK, en-IN, en-IE, en-KE, en-NZ, en-PK, en-PH, en-SG, en-ZA, en-TZ, en-GB, en-US&#xA;&#xA;es-AR, es-BO, es-BO, es-CL, es-CO, es-CR, es-DO, es-EC, es-SV, es-SV, es-GT, es-HN, es-MX, es-NI, es-PA, es-PY, es-PE, es-PR, es-ES, es-US, es-UY, es-VE\n""")&#xA;&#xA;&#xA;#for stime in range(0, 10000, 15):&#xA;#    try:&#xA;#        transcribe_piece(fname, lang, stime)&#xA;#    except:&#xA;#        run("shred -u trimmed.wav" , shell=True) &#xA;        #run("shred -u trimmed.wav >/dev/null 2>&amp;1" , shell=True) &#xA;#        exit(0)&#xA;        &#xA;for stime in range(0, 10000, 15):#this loop is only for the sake of debugging, use try/except above&#xA;    transcribe_piece(fname, lang, stime)&#xA;&#xA;

    &#xA;

    It gives me the following error :

    &#xA;

    Traceback (most recent call last):&#xA;  File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 61, in <module>&#xA;    transcribe_piece(fname, lang, stime)&#xA;  File "/home/jim/CS/SoftwareDevelopment/MySoftware/Python/speech-to-text/long-audio-to-text.py", line 31, in transcribe_piece&#xA;    t = r.recognize_google(audio, language=lang)&#xA;  File "/home/jim/.local/lib/python3.10/site-packages/speech_recognition/__init__.py", line 858, in recognize_google&#xA;    if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()&#xA;speech_recognition.UnknownValueError&#xA;&#xA;</module>

    &#xA;

    The said error refers to line 31, that is t = r.recognize_google(audio, language=lang).&#xA;Why do I get this error ? How might I rewrite this code so that such error does not appear ?

    &#xA;