Recherche avancée

Médias (1)

Mot : - Tags -/bug

Autres articles (32)

  • La file d’attente de SPIPmotion

    28 novembre 2010, par

    Une file d’attente stockée dans la base de donnée
    Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
    Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...)

  • 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 (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (4475)

  • How to parallelize ffmpeg setPTS filter when using GPU ? [closed]

    28 février, par Souvic Chakraborty

    We have a long python code which chunks the video into multiple parts and changes the speed using setPTS filter.

    


    import ffmpeg
ffmpeg.input(segment_path).filter("setpts", f"{1/speed_factor}*PTS").output(
                                adjusted_segment_path,vcodec="h264_nvenc", acodec="aac",preset="fast", crf=23, g=30, keyint_min=30, sc_threshold=0,r=30,vsync='cfr',threads=1
                            ).global_args("-hwaccel", "cuda").run(quiet=True, overwrite_output=True,capture_stdout=True, capture_stderr=True)


    


    Now, because this happens multiple times before concatenation, we thought, instead of sequential processing using a ThreadPool, it may help reduce the time.
So we did that :

    


    import ffmpeg
import concurrent.futures

def process_video(segment_path, adjusted_segment_path, speed_factor):
    ffmpeg.input(segment_path).filter("setpts", f"{1/speed_factor}*PTS").output(
        adjusted_segment_path,
        vcodec="h264_nvenc",
        acodec="aac",
        preset="fast",
        crf=23,
        g=30,
        keyint_min=30,
        sc_threshold=0,
        r=30,
        vsync='cfr',
        threads=1
    ).global_args("-hwaccel", "cuda").run(
        quiet=True, overwrite_output=True, capture_stdout=True, capture_stderr=True
    )


segment_paths = ["input1.mp4", "input2.mp4", "input3.mp4"]  # List of input video segments
output_paths = ["output1.mp4", "output2.mp4", "output3.mp4"]  # Corresponding output paths
speed_factor = 1.5  

# Using ThreadPoolExecutor for concurrent processing
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
    futures = [
        executor.submit(process_video, seg, out, speed_factor)
        for seg, out in zip(segment_paths, output_paths)
    ]
    
    # Wait for all tasks to complete
    for future in concurrent.futures.as_completed(futures):
        try:
            future.result()  # This will raise any exceptions encountered in the thread
        except Exception as e:
            print(f"Error processing video: {e}")


    


    But the time required did not reduce. Previously, it was 50 seconds for a long video input, now too, it remains the same.

    


    Is there any other way I can improve the code ?

    


    I also noticed the GPU utilization is low and the code is still executed sequentially (I can see when I run nvtop, which processes are running)

    


    I am using an L4 GPU with CUDA Version : 12.4, nvcc CUDA Toolkit is also at 12.4

    


  • piping data into an ffmpeg subprocess. Why does write() get stuck ? [closed]

    12 mai 2024, par Tebyy

    It displays the number of frames at the beginning and shows that there are over 300, but when I count all the frames in the loop, the last one I see is 53, and then it only displays the value of 'ret', which is always true. I'm wondering what could be causing this issue of not reading all the frames, resulting in the file not being closed after reading. From what I've read, 'ret' should return false when there are no more frames to read, but because it's not reading all the frames, this isn't happening. Does anyone have any idea what could be causing this ?

    


    Edit : I solved the problem by adding a Thread. Thanks everyone for the help !

    


    I changed those lines of code :

    


    recogniteAndPushFramesToFfmpeg("video-979257305707693982.mp4", ffmpeg_process)
# In function "recogniteAndPushFramesToFfmpeg"
process.stdin.write(frame)


    


    to these :

    


    ffmpeg_thread = Thread(target=recogniteAndPushFramesToFfmpeg, args=("video-979257305707693982.mp4", ffmpeg_process))
ffmpeg_thread.start()
# In function "recogniteAndPushFramesToFfmpeg"
process.stdin.write(frame.tobytes())


    


    Code :

    


    import subprocess
import cv2

def recogniteAndPushFramesToFfmpeg(video_path, process):
    cap = cv2.VideoCapture(video_path)
    i = 1
    print('Frames:', cap.get(cv2.CAP_PROP_FRAME_COUNT))
    while cap.isOpened():
        ret, frame = cap.read()
        print(ret)
        if not ret:
            break

        process.stdin.write(frame)
        process.stdin.flush()
        print('Frame:', i)
        i += 1

    cap.release()
    process.stdin.close()
    #process.wait()
    return
    

ffmpeg_command = [
    'ffmpeg', '-f', 'rawvideo', '-s:v', '1920x1080', '-r', '60',
    '-i', '-', '-vf', 'setpts=2.5*PTS',
    '-c:v', 'libvpx-vp9', '-g', '60',
    '-f', 'webm', '-'
]
ffmpeg_process = subprocess.Popen(ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1)
recogniteAndPushFramesToFfmpeg("video-979257305707693982.mp4", ffmpeg_process)


    


    Python Logs :

    


    Frames: 328.0
...
True
Frame 50
True
Frame 51
True
Frame 52
True
Frame 53
True


    


    I placed cap.isOpened() in the loop to check if it always returns true, and when I printed it, it always showed true

    


    Link to video : Tested Video

    


  • Python moviepy, CompositeVideoClip is Slow and Wierd

    4 mars 2023, par Dan

    I want to add a .mov transparent overlay on top of a .mp4 video, and for that I am using movipy and CompositeVideoClip, but it's too slow.

    


    The speed is 40 it/s when only the video is rendering but when it comes to the overlay it is only 5 it/s. To speed it up I have used use_bgclip=True and now I get 90 it/s but when the overlay comes I still get 5 it/s, and when I use use_bgclip=True there are 2 'bugs' that appears :

    


      

    1. The video freezes after the overlay is done playing.
    2. 


    3. The audio of the video is lost and the overlay sound is the only one left
    4. 


    


    For the two 'bugs', I found a good enough solution, but I want to speed up the process when the overlay comes, because 5 it/s it's way too slow. I have tried to use codec="h264_nvenc" or higher crf but the speed is the same.

    


    Is there a way to speed this up ? (I don't care if I need to use other libraries)

    


    import moviepy.editor as mp
video = mp.VideoFileClip("video.mp4")

overlay = mp.VideoFileClip("overlay.mov", has_mask=True)
overlay = overlay.set_start(5) # start the overlay 5 seconds after the video starts

compose = mp.CompositeVideoClip([video, overlay], use_bgclip=True, size=video.size)
compose = compose.set_duration(video.duration) # fix bug 1
compose = compose.set_audio(video.audio) # fix bug 2 (but I lost the audio from the overlay)

compose.write_videofile("cf15.mp4", codec="libx264", preset="veryfast", ffmpeg_params=["-crf", "15"])

compose.close()
video.close()