Recherche avancée

Médias (1)

Mot : - Tags -/copyleft

Autres articles (75)

  • Menus personnalisés

    14 novembre 2010, par

    MediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
    Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
    Menus créés à l’initialisation du site
    Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

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

  • Trying to convert code to be compatible with macOS by not using the .exe version of FFmpeg and FFmprobe. Cant open the .mp4 file when i go to run code

    9 juillet 2024, par Bruno Hawkins

    I am attempting to edit some code in python for extracting frames from a video (using parallel processing to make it faster) a friend created that works on windows, so that it can be used on macOS. However, i am running into some issues and i am not sure what the problem is.

    


    Essentially, when i go to run the frame extractor and try to select a video in the formats specified, it wont let me select it.

    


    i have commented my code best i can. i am an amateur programmer so apologies if it is straightforward.

    


    import os
import subprocess
import multiprocessing
import tkinter as tk
from tkinter import ttk, filedialog, messagebox

def extract_frames(video_path, output_folder, fps, start_time, duration, process_number):
    video_name = os.path.splitext(os.path.basename(video_path))[0]
    part_output_folder = os.path.join(output_folder, f"part_{process_number}")
    if not os.path.exists(part_output_folder):
        os.makedirs(part_output_folder)

    # Using 'ffmpeg' instead of 'ffmpeg.exe' for macOS compatibility
    ffmpeg_command = [
        'ffmpeg', '-ss', str(start_time), '-t', str(duration), '-i', video_path, '-vf', f'fps={fps}',
        os.path.join(part_output_folder, f'{video_name}_frame_%07d.png')
    ]

    print(f"Running FFmpeg command: {' '.join(ffmpeg_command)}")

    try:
        process = subprocess.run(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        if process.returncode != 0:
            print(f"Cannot process the file {video_path}: {process.stderr.decode('utf-8')}")
            return part_output_folder, 0
    except Exception as e:
        print(f"Failed to run FFmpeg command: {str(e)}")
        return part_output_folder, 0

    frame_count = len([f for f in os.listdir(part_output_folder) if f.endswith('.png')])
    return part_output_folder, frame_count

def worker_function(queue, video_path, output_folder, fps, start_time, duration, process_number):
    result = extract_frames(video_path, output_folder, fps, start_time, duration, process_number)
    queue.put(result)

def parallel_frame_extraction(video_path, output_folder, fps, num_processes):
    # Use 'ffprobe' instead of 'ffprobe.exe' for macOS compatibility
    ffprobe_command = [
        'ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'format=duration', '-of',
        'default=noprint_wrappers=1:nokey=1', video_path
    ]

    try:
        result = subprocess.run(ffprobe_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        duration = float(result.stdout.strip())
    except Exception as e:
        messagebox.showerror("Error", f"Failed to get video duration: {str(e)}")
        return

    chunk_duration = duration / num_processes
    processes = []
    manager = multiprocessing.Manager()
    queue = manager.Queue()

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

    for i in range(num_processes):
        start_time = i * chunk_duration
        p = multiprocessing.Process(target=worker_function,
                                    args=(queue, video_path, output_folder, fps, start_time, chunk_duration, i))
        p.start()
        processes.append(p)

    for p in processes:
        p.join()

    global_frame_offset = 0
    while not queue.empty():
        part_output_folder, frame_count = queue.get()
        frame_files = sorted([f for f in os.listdir(part_output_folder) if f.endswith('.png')])
        for i, frame_file in enumerate(frame_files):
            new_name = os.path.join(output_folder,
                                    f'{os.path.basename(video_path)}_frame_{global_frame_offset + i:07d}.png')
            os.rename(os.path.join(part_output_folder, frame_file), new_name)
        global_frame_offset += frame_count
        os.rmdir(part_output_folder)

    messagebox.showinfo("Complete",
                        f"Frame extraction completed for {video_path}. Total frames extracted: {global_frame_offset}")

def start_frame_extraction():
    video_path = filedialog.askopenfilename(filetypes=[("Video files", "*.mp4;*.avi;*.mkv")])
    if not video_path:
        return

    output_folder = output_folder_var.get()
    if not output_folder:
        return

    fps = int(fps_var.get())
    num_processes = int(num_processes_var.get())

    parallel_frame_extraction(video_path, output_folder, fps, num_processes)

if __name__ == "__main__":
    root = tk.Tk()
    root.title("Frame Extraction")

    output_folder_var = tk.StringVar()
    fps_var = tk.StringVar(value="1")
    num_processes_var = tk.StringVar(value="4")

    def browse_output_folder():
        folder_selected = filedialog.askdirectory()
        output_folder_var.set(folder_selected)

    tk.Label(root, text="Output Folder:").grid(row=0, column=0, padx=10, pady=10)
    tk.Entry(root, textvariable=output_folder_var, width=50).grid(row=0, column=1, padx=10, pady=10)
    tk.Button(root, text="Browse", command=browse_output_folder).grid(row=0, column=2, padx=10, pady=10)

    tk.Label(root, text="FPS:").grid(row=1, column=0, padx=10, pady=10)
    tk.Entry(root, textvariable=fps_var, width=10).grid(row=1, column=1, padx=10, pady=10)

    tk.Label(root, text="Number of Processes:").grid(row=2, column=0, padx=10, pady=10)
    tk.Entry(root, textvariable=num_processes_var, width=10).grid(row=2, column=1, padx=10, pady=10)

    tk.Button(root, text="Start Frame Extraction", command=start_frame_extraction).grid(row=3, column=0, columnspan=3,
                                                                                        padx=10, pady=20)

    root.mainloop()


    


    I tried changing the FFmpeg and FFmprobe path formats from

    


    ffmpeg_path = os.path.join(os.path.dirname(__file__), 'ffmpeg-7.0.1-essentials_build', 'bin', 'ffmpeg.exe')
ffprobe_path = os.path.join(os.path.dirname(__file__), 'ffmpeg-7.0.1-essentials_build', 'bin', 'ffprobe.exe')



    


    to

    


    ffmpeg_command = [
    'ffmpeg', '-ss', str(start_time), '-t', str(duration), '-i', video_path, '-vf', f'fps={fps}',
    os.path.join(part_output_folder, f'{video_name}_frame_%07d.png')
]

ffprobe_command = [
    'ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'format=duration', '-of',
    'default=noprint_wrappers=1:nokey=1', video_path
]



    


    I found this online so im not sure if it is the correct thing to do.

    


    Thanks for any help.

    


  • ffmpeg encoding slowly, not using much CPU

    30 juin 2012, par eblume

    I am using the latest (as of this post) version of ffmpeg on OS X as installed via homebrew (an OS X 3rd-party package manager with a good reputation.) I am trying to encode video that was recorded using Fraps on another machine to reduce the file size while preserving as much quality as is reasonably possible.

    Fraps records video in a .avi container and I believe does absolutely no encoding - instead, it's just a stream of image files. The resulting files are often enormous, obviously. I want to set up a cron job that finds recorded files and encodes them to H.264 with some sort of audio codec (I'm currently using libmp3lame but will revisit it when I get video working right - will probably switch to a lossless audio codec.)

    My problem is that while encoding seems to be working exactly how I want it - very few compression artifacts but about 5% of the original size - the encoding is taking forever. I'm averaging about 1.5 encoded frames per second, and these are 2-3 hours of 30FPS video. On top of that, my CPU is never fully utilized. On my dual-core CPU I am getting a median usage of about 40% of one core, with occasional peaks of 140% to 160%.

    So the question is : How can I speed up encoding ? I'm sure there's got to be some options I'm missing out on.

    Here's the command I use :

    ffmpeg -i INFILE -c copy -c:a libmp3lame -ar 44100 -q:a 5 \
                 -threads 0 -c:v libx264 OUTFILE

    Thanks !

    EDIT : Actually, it looks like this command isn't compressing that well either - I'll do some digging but it seems that this might be being too generous with the bitrate for H.264. At first I was getting around 2Mb/s but it's gone up to almost 20Mb/s - looks like I'm basically not compressing at all.

  • Cancelling ffpeg launched as a C# process

    22 avril 2016, par DarwinIcesurfer

    I’m launching ffmpeg in a c# process to encode a video. In a command window, ffmpeg can be interrupted by pressing CTRL-C. I have tried to achieve the same effect by closing the process, however ffmpeg does not appear to close (it is still visible in task manager and it does not release the handle on the file it was encoding)

    How can ffmpeg be interrupted programatically ?

    static Process proc;
    static BackgroundWorker bw;    

    public void EncodeVideoWithProgress(string filename, string arguments, BackgroundWorker worker, DoWorkEventArgs e)
    {
       proc = new Process();

       // assign the backgroud worker to a class member variable so all function within the class will have access
       bw = worker;

       proc.StartInfo.FileName = "ffmpeg";
       proc.StartInfo.Arguments = "-i " + " \"" + filename + "\" " + arguments;

       proc.StartInfo.UseShellExecute = false;
       proc.EnableRaisingEvents = true;
       proc.StartInfo.RedirectStandardError = true;
       proc.StartInfo.RedirectStandardOutput = false;
       proc.StartInfo.CreateNoWindow = true;

       proc.ErrorDataReceived += new DataReceivedEventHandler(NetErrorDataHandler);

       proc.Start();
       proc.BeginErrorReadLine();

       proc.WaitForExit();
    }

    private static void NetErrorDataHandler(object sendingProcess,
              DataReceivedEventArgs errLine)
    {
       if (bw.CancellationPending)
       {
           proc.CloseMainWindow();
           proc.Close();  
       }
       else
       {
        // do other tasks
       }
    }