Recherche avancée

Médias (1)

Mot : - Tags -/livre électronique

Autres articles (76)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

  • Contribute to a better visual interface

    13 avril 2011

    MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
    Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.

Sur d’autres sites (10848)

  • Video generation and ffmpeg and locally stored images [closed]

    3 juillet, par Rahul Patil

    I am facing issue in ffmpeg while running the below code

    


    I'm working on a Flask application that generates a video by combining a sequence of images from a folder and a synthesized audio track using Bark (suno/bark-small). The idea is to use FFmpeg to stitch the images into a video, apply padding and scaling, and then merge it with the generated audio. I'm triggering the /generate-video endpoint with a simple curl POST request, passing a script that gets converted to audio. While the image and audio processing work as expected, FFmpeg fails during execution, and the server returns a 500 error. I've added error logging to capture FFmpeg’s stderr output, which suggests something is going wrong either with the generated input.txt file or the format of the inputs passed to FFmpeg. I'm not sure if the issue is related to file paths, the concat demuxer formatting, or possibly audio/video duration mismatch. Any insights on how to debug or correct the FFmpeg command would be appreciated.

    


    the curl request is

    


    curl -X POST http://localhost:5000/generate-video \
     -H "Content-Type: application/json" \
     -d '{"script": "Hello, this is a test script to generate a video."}' \
     --output output_video.mp4


    


    import os
import uuid
import subprocess
from pathlib import Path
import numpy as np
from flask import Flask, request, jsonify, send_file
from transformers import AutoProcessor, AutoModelForTextToWaveform
from scipy.io.wavfile import write as write_wav
import torch

# ========== CONFIG ==========
IMAGE_FOLDER = "./images"
OUTPUT_FOLDER = "./output"
RESOLUTION = (1280, 720)
IMAGE_DURATION = 3  # seconds per image
SAMPLE_RATE = 24000

app = Flask(__name__)
os.makedirs(OUTPUT_FOLDER, exist_ok=True)

# Load Bark-small model and processor
device = "cuda" if torch.cuda.is_available() else "cpu"
processor = AutoProcessor.from_pretrained("suno/bark-small")
model = AutoModelForTextToWaveform.from_pretrained("suno/bark-small").to(device)


# ========== UTILS ==========
def run_ffmpeg(cmd):
    result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if result.returncode != 0:
        print("[FFmpeg ERROR]\n", result.stderr.decode())
        raise RuntimeError("FFmpeg failed.")
    else:
        print("[FFmpeg] Success.")


def find_images(folder):
    return sorted([
        f for f in Path(folder).glob("*")
        if f.suffix.lower() in {".jpg", ".jpeg", ".png"}
    ])


def create_ffmpeg_input_list(images, list_file_path):
    with open(list_file_path, "w") as f:
        for img in images:
            f.write(f"file '{img.resolve()}'\n")
            f.write(f"duration {IMAGE_DURATION}\n")
        # Repeat last image to avoid cutoff
        f.write(f"file '{images[-1].resolve()}'\n")


# ========== FLASK ROUTE ==========
@app.route('/generate-video', methods=['POST'])
def generate_video():
    data = request.get_json()
    script = data.get("script")
    if not script:
        return jsonify({"error": "No script provided"}), 400

    images = find_images(IMAGE_FOLDER)
    if not images:
        return jsonify({"error": "No images found in ./images"}), 400

    # Generate audio
    print("[1/3] Generating audio with Bark...")
    inputs = processor(script, return_tensors="pt").to(device)
    with torch.no_grad():
        audio_values = model.generate(**inputs)

    audio_np = audio_values[0].cpu().numpy().squeeze()
    audio_np = np.clip(audio_np, -1.0, 1.0)
    audio_int16 = (audio_np * 32767).astype(np.int16)

    audio_path = os.path.join(OUTPUT_FOLDER, f"{uuid.uuid4()}.wav")
    write_wav(audio_path, SAMPLE_RATE, audio_int16)

    # Create FFmpeg concat file
    print("[2/3] Preparing image list for FFmpeg...")
    list_file = os.path.join(OUTPUT_FOLDER, "input.txt")
    create_ffmpeg_input_list(images, list_file)

    # Final video path
    final_video_path = os.path.join(OUTPUT_FOLDER, f"{uuid.uuid4()}.mp4")

    # Run FFmpeg
    print("[3/3] Running FFmpeg to create video...")
    ffmpeg_cmd = [
        "ffmpeg", "-y",
        "-f", "concat", "-safe", "0", "-i", list_file,
        "-i", audio_path,
        "-vf", f"scale={RESOLUTION[0]}:{RESOLUTION[1]}:force_original_aspect_ratio=decrease,"
               f"pad={RESOLUTION[0]}:{RESOLUTION[1]}:(ow-iw)/2:(oh-ih)/2:color=black",
        "-c:v", "libx264", "-pix_fmt", "yuv420p",
        "-c:a", "aac", "-b:a", "192k",
        "-shortest", "-movflags", "+faststart",
        final_video_path
    ]

    try:
        run_ffmpeg(ffmpeg_cmd)
    except RuntimeError:
        return jsonify({"error": "FFmpeg failed. Check server logs."}), 500

    return send_file(final_video_path, as_attachment=True)


# ========== RUN APP ==========
if __name__ == '__main__':
    app.run(debug=True)


    


  • ffmpeg_kit_flutter_full : Video created from ffmpeg not showing in the web

    16 décembre 2024, par Đoàn Thanh Thảo

    I am implementing a screen capture widget to create a video. The video was successfully created in MP4 format and I can view it in my app and then I posted it to my web. However, on the web, I cannot see the video preview, only when I download the video and view it on my phone can I see it. I think the problem is that there is some missing format that makes the video not playable on Https. Here is my code :

    


        final command = '-y -f image2 -i $imagesPath '
    '${fps != null ? "-r $fps" : ""} '
    '-vf "scale=2000:5000" '
    // '-vf "scale=iw*$scaleMultiplier:ih*$scaleMultiplier" '
    '-c:v mpeg4 -q:v $qValue -pix_fmt yuv420p -movflags +faststart $outputVideoPath';


    


    I try to use libx264 nhưng bị báo lỗi

    


  • launch ffmpeg on Maui Android

    4 décembre 2024, par lolveley

    I have an Maui app which is deployed on an Android tablet, a Samsung tab S9 FE.
I have copied the ARM8 version of the ffmpeg executable in the AppDataDirectory of my deployed app. The executable, named "ffmpeg", has the rights _rwxrwxrwx (the underscore means this is a file, and not a directory).

    


    I try to execute the file with the command Process.Start :

    


    private void GetThumbnail(string inputFile, string imageFullPath, string ffmpegFullPath)
{
        ProcessStartInfo startInfo = new ProcessStartInfo();

        string arguments = $"-i {inputFile} -ss 00:01:00.000 -vframes 1 {imageFullPath}";

        startInfo.FileName = ffmpegFullPath;
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        startInfo.RedirectStandardError = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.Arguments = arguments;

        try
        {
            Process process = Process.Start(startInfo);
            process.WaitForExit(5000);
            process.Close();
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
}


    


    There is an exception saying the access is denied :

    


    


    System.ComponentModel.Win32Exception (13) : An error occurred trying to
start process '/data/user/0/sxb.explorateur.de.fichiers/files/ffmpeg'
with working directory '/data/data/sxb.explorateur.de.fichiers/files'.
Permission denied

    


    


    The error message doesn't say more, and I do not see what to do, the directory usually is dedicated to the application, and the file is executable.

    


    I know that Android has restricted policies with file execution, and maybe it's even harder for the Samsung operating system, namely One UI 6.1.1 and Android 14.

    


    thank you.