Recherche avancée

Médias (91)

Autres articles (26)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Le plugin : Podcasts.

    14 juillet 2010, par

    Le problème du podcasting est à nouveau un problème révélateur de la normalisation des transports de données sur Internet.
    Deux formats intéressants existent : Celui développé par Apple, très axé sur l’utilisation d’iTunes dont la SPEC est ici ; Le format "Media RSS Module" qui est plus "libre" notamment soutenu par Yahoo et le logiciel Miro ;
    Types de fichiers supportés dans les flux
    Le format d’Apple n’autorise que les formats suivants dans ses flux : .mp3 audio/mpeg .m4a audio/x-m4a .mp4 (...)

  • Selection of projects using MediaSPIP

    2 mai 2011, par

    The examples below are representative elements of MediaSPIP specific uses for specific projects.
    MediaSPIP farm @ Infini
    The non profit organizationInfini develops hospitality activities, internet access point, training, realizing innovative projects in the field of information and communication technologies and Communication, and hosting of websites. It plays a unique and prominent role in the Brest (France) area, at the national level, among the half-dozen such association. Its members (...)

Sur d’autres sites (4197)

  • Send inputs to a process (ffmpeg) using python

    10 mai 2023, par Noddy

    I am trying to program a custom screen recording functionality, but I have problems sending input to a process.

    


    To achieve this I use ffmpeg. The idea is that I have two scripts A and B

    


    A : Begin recording - create a ffmpeg subprocess that records the screen and writes the process id (pid) to a file

    


    B : Stop the recording - Read the pid from the file and send a 'q' input to the process to stop the recording

    


    This is my code :

    


    A :

    


    import shlex
import subprocess
import time
import datetime

# Variables
success = True
flowName = "workflow1"

# Get current date and time
now = datetime.datetime.now()

formatted_date = now.strftime("%Y-%m-%d %H:%M:%S")

folderDestination = f"C:\\Users\\MadPe\\Desktop\\pipRec\\workFlows\\{flowName}\\"

formatted_date = formatted_date.replace(":",".").replace(" ","_")

fileName = folderDestination + formatted_date + ".mp4"

ffmpegPath = r"C:\Users\MadPe\Desktop\pipRec\ffmpeg\bin\ffmpeg.exe"

command = shlex.split(f'"{ffmpegPath}" -f gdigrab -framerate 30 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -y "{fileName}"')
process = subprocess.Popen(command, stdin=subprocess.PIPE)

pid = process.pid
startTime = time.time()

with open("filename.txt", "w") as file:
    file.write(str(pid))

#process.stdin.write(b'q\n') #-- this is how I stop the recording
#process.stdin.flush()       #-- but I want to do this from another script


    


    B :

    


    import psutil

# Stop recording and kill Process
with open("filename.txt", "r") as f:
    pid = int(f.read().strip())

if psutil.pid_exists(pid):
    process = psutil.Process(pid)
    process.stdin.write(b'q\n')
    process.stdin.flush()
else:
    print(f"Process with PID {pid} is not running.")


    


    however, when I try to stop the running process I get this error :

    


    Error Message

    


    I hope some of you may be able to spot what I am doing wrong.
also if I comment in the last two lines in A it will make the recording stop, but I want to be able to do this from running B

    


    demo : https://www.veed.io/view/ab4ef053-bba9-43f9-85c5-6ca18204ea37?sharingWidget=true&panel=share

    


  • Excuting ffmpeg commands using Python to locate *.png failed

    18 mai 2023, par Leo

    The following command works well if I run it in the Bash terminal.

    


    ffmpeg -framerate 25 -pattern_type glob -i 'data/*.png' -i data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p data/download_youtube/_-91nXXjrVo_out.mp4


    


    However, If i run it using os.system() using Python.

    


    os.system(r"ffmpeg -framerate 25 -pattern_type glob -i '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png' -i /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p /data/share/VFHQ/data/download_youtube/out.mp4")


    


    I get Unknown encoder 'libx264'

    


    If I remove the quotation mark inside the commands

    


    os.system(r"ffmpeg -framerate 25 -pattern_type glob -i /data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png -i /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav -c:v libx264 -pix_fmt yuv420p /data/share/VFHQ/data/download_youtube/out.mp4")


    


    I get Option pattern_type not found.

    


    So I tried subprocess.run(command,shell=True) , I get same results as shown above.

    


    Running 'subprocess.run()' without Shell will result in the following"

    


    subprocess.run(['ffmpeg', '-framerate', '25','-pattern_type', 'glob', '-i','/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png',
                '-i','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav','-c:v','libx264','-pix_fmt','yuv420p','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'])



    


    [image2 @ 0x56001a8fee00] Could find no file with path '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png' and index in the range 0-4
/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png: No such file or directory


    



    


    With out the quotation marks on the picture directory :

    


    CompletedProcess(args=['ffmpeg', '-framerate', '25', '-pattern_type', 'glob', '-i', '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png', '-i', '/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav', '-c:v', 'libx264', '-pix_fmt', 'yuv420p', '/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'], returncode=1)


    


    Unknown encoder 'libx264'

    


    with quotation marks around the picture directory (also the correct way to run in the terminal) :

    


    subprocess.run(['ffmpeg', '-framerate', '25','-pattern_type', 'glob', '-i',"'/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png'",
                '-i','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav','-c:v','libx264','-pix_fmt','yuv420p','/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4'])


    


    '/data/share/VFHQ/data/extracted_cropped_face_results/_-91nXXjrVo/Clip+_-91nXXjrVo+P0+C0+F1537-1825/*.png': No such file or directory

    



    


    It was later found out that I have 2versions of ffmpeg. One is 4.3 the other is 4.4.2
The thing is running a subprocess with quotation marks (I know it is incorrect as it has been explained) will call v4.4.2. Running it without quotation marks will call the v4.3 ffmpeg.

    


    Also from V4.3 log, it suggests Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'libx264'. but in the end

    


    [wav @ 0x55eaef48b240] After avformat_find_stream_info() pos: 204878 bytes read:294990 seeks:1 frames:50
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from '/data/share/VFHQ/data/download_youtube/_-91nXXjrVo_cut.wav':
  Metadata:
    encoder         : Lavf58.45.100
  Duration: 00:00:11.44, bitrate: 1536 kb/s
    Stream #1:0, 50, 1/48000: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Successfully opened the file.
Parsing a group of options: output url /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4.
Applying option c:v (codec name) with argument libx264.
Applying option pix_fmt (set pixel format) with argument yuv420p.
Successfully parsed a group of options.
Opening an output file: /data/share/VFHQ/data/download_youtube/_-91nXXjrVo_out.mp4.
Unknown encoder 'libx264'
[AVIOContext @ 0x55eaef487fc0] Statistics: 294990 bytes read, 1 seeks


    


  • How to get frame-by-frame audio from the video in python

    7 juin 2023, par Usman Arshad

    So,first of all the description of my program is that I am viewing a video using opencv and whenever I press "p" the video paused for 5 seconds.At last I am saving that updated video in the same directory.I want to add audio to this video and whenever "p" pressed the audio must also be stopped for 5 second until next frame.

    


    import cv2

def save_frames(frames, output_filename, fps):
    # Get video information from the first frame
    height, width, _ = frames[0].shape

    # Create a VideoWriter object to save the frames
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    output = cv2.VideoWriter(output_filename, fourcc, fps, (width, height))

    # Write each frame to the video file
    for frame in frames:
        output.write(frame)

    # Release the VideoWriter
    output.release()
    
def main():
    # Load the video
    video_path = 'input_video.mp4'
    cap = cv2.VideoCapture(video_path)


    frames = []
    fps = cap.get(cv2.CAP_PROP_FPS)

    while cap.isOpened():
        # Read the current frame
        ret, frame = cap.read()

        if not ret:
            break

        # Display the frame
        cv2.imshow('Video', frame)

        # Append the frame to the list
        frames.append(frame)
        # Wait for key press
        key = cv2.waitKey(int(1000 / fps))

        if key == ord('p'):
            # Pause the video for 5 seconds
            paused = True
            for _ in range(int(fps * 5)):
                frames.append(frame)
                cv2.waitKey(int(1000 / fps))
            paused = False

    # Release the VideoCapture
    cap.release()

    # Save the frames to a video file
    output_filename = 'output.mp4'
    save_frames(frames, output_filename, fps)

if __name__ == '__main__':
    main()