Recherche avancée

Médias (1)

Mot : - Tags -/bug

Autres articles (46)

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

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (7803)

  • FFMPEG eating up ram in railway deployment [flask app]

    23 juin 2024, par Eshan Das

    I created a flask app , meme generator, hosting it in railway using gunicorn, i am suspecting ffmpeg is eating the most ram.....
so what i am doing is , generating a tts, and a text adding into one of the parts of the video , and then finally combining all together

    


    from flask import Flask, request, jsonify, send_file, url_for&#xA;from moviepy.editor import VideoFileClip, ImageClip, CompositeVideoClip, AudioFileClip, concatenate_videoclips&#xA;from pydub import AudioSegment&#xA;from PIL import Image, ImageDraw, ImageFont&#xA;from gtts import gTTS&#xA;from flask_cors import CORS&#xA;import os&#xA;&#xA;app = Flask(__name__)&#xA;CORS(app)&#xA;app.config[&#x27;UPLOAD_FOLDER&#x27;] = &#x27;uploads&#x27;&#xA;&#xA;def generate_video(name, profile_image_path, song_path, start_time):&#xA;    first_video = VideoFileClip("first.mp4")&#xA;    second_video = VideoFileClip("second.mp4")&#xA;    third_video = VideoFileClip("third.mp4")&#xA;&#xA;    #font_path = os.path.join("fonts", "arial.ttf")  # Updated font path&#xA;    font_size = 70&#xA;    font = ImageFont.load_default()&#xA;    text = name&#xA;    image_size = (second_video.w, second_video.h)&#xA;    text_image = Image.new(&#x27;RGBA&#x27;, image_size, (0, 0, 0, 0))&#xA;    draw = ImageDraw.Draw(text_image)&#xA;    text_width, text_height = draw.textsize(text, font=font)&#xA;    text_position = ((image_size[0] - text_width) // 2, (image_size[1] - text_height) // 2)&#xA;    draw.text(text_position, text, font=font, fill="black")&#xA;&#xA;    text_image_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], f"text_{name}.png")&#xA;    text_image.save(text_image_path)&#xA;&#xA;    txt_clip = ImageClip(text_image_path, duration=second_video.duration)&#xA;&#xA;    tts = gTTS(text=name, lang=&#x27;en&#x27;)&#xA;    audio_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], f"audio_{name}.wav")&#xA;    tts.save(audio_path)&#xA;&#xA;    sound = AudioSegment.from_file(audio_path)&#xA;    chipmunk_sound = sound._spawn(sound.raw_data, overrides={&#xA;        "frame_rate": int(sound.frame_rate * 1.5)&#xA;    }).set_frame_rate(sound.frame_rate)&#xA;&#xA;    chipmunk_audio_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], f"chipmunk_audio_{name}.wav")&#xA;    chipmunk_sound.export(chipmunk_audio_path, format="wav")&#xA;&#xA;    audio_clip_second = AudioFileClip(chipmunk_audio_path)&#xA;&#xA;    second_video = CompositeVideoClip([second_video, txt_clip.set_position((45, 170))])&#xA;    second_video = second_video.set_audio(audio_clip_second)&#xA;&#xA;    song = AudioSegment.from_file(song_path)&#xA;    start_ms = start_time * 1000&#xA;    cropped_song = song[start_ms:start_ms &#x2B; 20000]&#xA;&#xA;    chipmunk_song = cropped_song._spawn(cropped_song.raw_data, overrides={&#xA;        "frame_rate": int(cropped_song.frame_rate * 1.5)&#xA;    }).set_frame_rate(cropped_song.frame_rate)&#xA;&#xA;    chipmunk_song_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], f"chipmunk_song_{name}.wav")&#xA;    chipmunk_song.export(chipmunk_song_path, format="wav")&#xA;&#xA;    audio_clip_third = AudioFileClip(chipmunk_song_path)&#xA;    third_video = third_video.set_audio(audio_clip_third)&#xA;&#xA;    profile_image = ImageClip(profile_image_path).set_duration(first_video.duration).resize(height=first_video.h / 8).set_position((950, 500))&#xA;    first_video = CompositeVideoClip([first_video, profile_image])&#xA;    &#xA;    profile_image = ImageClip(profile_image_path).set_duration(second_video.duration).resize(height=second_video.h / 8).set_position((950, 500))&#xA;    second_video = CompositeVideoClip([second_video, profile_image])&#xA;    &#xA;    profile_image = ImageClip(profile_image_path).set_duration(third_video.duration).resize(height=third_video.h / 8).set_position((950, 500))&#xA;    third_video = CompositeVideoClip([third_video, profile_image])&#xA;&#xA;    final_video = concatenate_videoclips([first_video, second_video, third_video])&#xA;    final_video = final_video.subclip(0, 10)&#xA;&#xA;    output_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], f"output_{name}.mp4")&#xA;    final_video.write_videofile(output_path, codec="libx264", audio_codec=&#x27;aac&#x27;)&#xA;&#xA;    final_video.close()&#xA;    first_video.close()&#xA;    second_video.close()&#xA;    third_video.close()&#xA;    audio_clip_second.close()&#xA;    audio_clip_third.close()&#xA;&#xA;    os.remove(audio_path)&#xA;    os.remove(text_image_path)&#xA;    os.remove(chipmunk_song_path)&#xA;    os.remove(chipmunk_audio_path)&#xA;    &#xA;    return output_path&#xA;&#xA;@app.route(&#x27;/generate&#x27;, methods=[&#x27;POST&#x27;])&#xA;async def generate():&#xA;    if not os.path.exists(app.config[&#x27;UPLOAD_FOLDER&#x27;]):&#xA;        os.makedirs(app.config[&#x27;UPLOAD_FOLDER&#x27;])&#xA;&#xA;    name = request.form[&#x27;name&#x27;]&#xA;    start_time = float(request.form[&#x27;start_time&#x27;])&#xA;&#xA;    profile_image = request.files[&#x27;profile_image&#x27;]&#xA;    profile_image_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], profile_image.filename)&#xA;    profile_image.save(profile_image_path)&#xA;&#xA;    song = request.files[&#x27;song&#x27;]&#xA;    song_path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], song.filename)&#xA;    song.save(song_path)&#xA;&#xA;    video_path = generate_video(name, profile_image_path, song_path, start_time)&#xA;    return jsonify({"video_url": url_for(&#x27;uploaded_file&#x27;, filename=os.path.basename(video_path))})&#xA;&#xA;@app.route(&#x27;/uploads/<filename>&#x27;)&#xA;def uploaded_file(filename):&#xA;    path = os.path.join(app.config[&#x27;UPLOAD_FOLDER&#x27;], filename)&#xA;    return send_file(path, as_attachment=True)&#xA;&#xA;if __name__ == "__main__":&#xA;    if not os.path.exists(app.config[&#x27;UPLOAD_FOLDER&#x27;]):&#xA;        os.makedirs(app.config[&#x27;UPLOAD_FOLDER&#x27;])&#xA;    app.run(host=&#x27;0.0.0.0&#x27;, port=5000)&#xA;</filename>

    &#xA;

    I am trying to solve this issue, any way to optimize my code , or any other alternative of ffmpeg which i can use , to reduce the ram consumption

    &#xA;

  • How to hold the mpegts stream for few seconds ?

    8 août 2024, par Aven

    How to hold the mpegts stream for 5 seconds without changing frams's PTS ?

    &#xA;

    I tried the tsduck command as below :

    &#xA;

    aven.cheng@tgcusers-MacBook-Pro ~ % tsp -I ip 235.35.3.5:3535 -P timeshift --time 5000 -O ip 235.35.3.5:3536&#xA;&#xA;* Warning: timeshift: unknown initial bitrate, discarding packets until a valid bitrate can set the buffer size&#xA;

    &#xA;

    the stream of 235.35.3.5:3536 did come out 5 seconds later after i executed the above command..&#xA;But the frames' PTS of 235.35.3.5:3536 are not the same anymore. For exsample, the PTS of my target frame is 10935000 from 235.35.3.5:3535, but the PTS of my target frame has changed to 10830542 from 235.35.3.5:3536.

    &#xA;

    Is that possible to hold the stream for few seconds and also keep the PTS unchanged ? I don't necessarily have to use tsduck ; I am open to using other tools.

    &#xA;

  • local.ERROR : ffmpeg failed to execute command

    20 août 2024, par AMNA IQBAL

    I am trying to draw points on a video.

    &#xA;

    The Video is 12 seconds long and for one second there are 17 data points which needs to be plotted on the video of one frame (1 second).
    &#xA;It works for 6 seconds but not for 12 seconds.

    &#xA;

    Why it's not working for longer videos ? Is there any limitations of commands in ffmpeg ?

    &#xA;

    public function overlayCoordinates(Request $request)&#xA;{&#xA;Log::info(&#x27;Received request to overlay coordinates on video.&#x27;);&#xA;&#xA;    set_time_limit(600); // 600 seconds = 10 minutes&#xA;    try {&#xA;&#xA;        $request->validate([&#xA;            &#x27;video&#x27; => &#x27;required|file|mimes:mp4,avi,mkv,webm|max:102400&#x27;, // Video max size 100MB&#xA;            &#x27;coordinates&#x27; => &#x27;required|file|mimes:txt|max:5120&#x27;, // Coordinates text file max size 5MB&#xA;        ]);&#xA;&#xA;        $videoFile = $request->file(&#x27;video&#x27;);&#xA;        $coordinatesFile = $request->file(&#x27;coordinates&#x27;);&#xA;&#xA;        $videoFilePath = $videoFile->getRealPath();&#xA;        $videoFileName = $videoFile->getClientOriginalName();&#xA;&#xA;        // Move the video file to the desired location if needed&#xA;        $storedVideoPath = $videoFile->storeAs(&#x27;public/videos&#x27;, $videoFileName);&#xA;&#xA;        // Open the video file using Laravel FFmpeg&#xA;        $media = FFMpeg::fromDisk(&#x27;public&#x27;)->open(&#x27;videos/&#x27; . $videoFileName);&#xA;        $duration = $media->getDurationInSeconds();&#xA;&#xA;        Log::info(&#x27;Duration: &#x27; . $duration);&#xA;&#xA;        $coordinatesJson = file_get_contents($coordinatesFile->getPathname());&#xA;        $coordinatesArray = json_decode($coordinatesJson, true);&#xA;&#xA;        $frameRate = 30; // Assuming a frame rate of 30 fps&#xA;        $visibilityDuration = 0.5; // Set duration to 0.5 second&#xA;&#xA;        for ($currentTime = 0; $currentTime &lt; 7; $currentTime&#x2B;&#x2B;) {&#xA;            $filterString = ""; // Reset filter string for each frame&#xA;            $frameIndex = intval($currentTime * $frameRate); // Convert current time to an index&#xA;&#xA;            if (isset($coordinatesArray[&#x27;graphics&#x27;][$frameIndex])) {&#xA;                // Loop through the first 5 keypoints (or fewer if not available)&#xA;                $keypoints = $coordinatesArray[&#x27;graphics&#x27;][$frameIndex][&#x27;kpts&#x27;];&#xA;                for ($i = 0; $i &lt; min(12, count($keypoints)); $i&#x2B;&#x2B;) {&#xA;                    $keypoint = $keypoints[$i];&#xA;&#xA;                    $x = $keypoint[&#x27;p&#x27;][0] * 1920; // Scale x coordinate to video width&#xA;                    $y = $keypoint[&#x27;p&#x27;][1] * 1080; // Scale y coordinate to video height&#xA;&#xA;                    $startTime = $frameIndex / $frameRate; // Calculate start time&#xA;                    $endTime = $startTime &#x2B; $visibilityDuration; // Set end time for 0.5 second duration&#xA;&#xA;                    // Add drawbox filter for the current keypoint&#xA;                    $filterString .= "drawbox=x={$x}:y={$y}:w=10:h=10:color=red@0.5:t=fill:enable=&#x27;between(t,{$startTime},{$endTime})&#x27;,";&#xA;                }&#xA;                   Log::info("Processing frame index: {$frameIndex}, Drawing first 5 keypoints.");&#xA;        }&#xA;&#xA;            $filterString = rtrim($filterString, &#x27;,&#x27;);&#xA;            &#xA;            // Apply the filter for the current frame&#xA;            if (!empty($filterString)) {&#xA;                $media->addFilter(function ($filters) use ($filterString) {&#xA;                    $filters->custom($filterString);&#xA;                });&#xA;            }&#xA;        }&#xA;&#xA;        $filename = uniqid() . &#x27;_overlayed.mp4&#x27;;&#xA;        $destinationPath = &#x27;videos/&#x27; . $filename;&#xA;&#xA;        $format = new \FFMpeg\Format\Video\X264(&#x27;aac&#x27;);&#xA;        $format->setKiloBitrate(5000) // Increase bitrate for better quality&#xA;               ->setAdditionalParameters([&#x27;-profile:v&#x27;, &#x27;high&#x27;, &#x27;-preset&#x27;, &#x27;veryslow&#x27;, &#x27;-crf&#x27;, &#x27;18&#x27;]) // High profile, very slow preset, and CRF of 18 for better quality&#xA;               ->setAudioCodec(&#x27;aac&#x27;)&#xA;               ->setAudioKiloBitrate(192); // Higher audio bitrate&#xA;        &#xA;&#xA;        // Export the video in one pass to a specific disk and directory&#xA;        $media->export()&#xA;              ->toDisk(&#x27;public&#x27;)&#xA;              ->inFormat($format)&#xA;              ->save($destinationPath);&#xA;&#xA;        return response()->json([&#xA;            &#x27;message&#x27; => &#x27;Video processed successfully with overlays.&#x27;,&#xA;            &#x27;path&#x27; => Storage::url($destinationPath)&#xA;        ]);&#xA;    } catch (\Exception $e) {&#xA;        Log::error(&#x27;Overlay process failed: &#x27; . $e->getMessage());&#xA;        return response()->json([&#x27;error&#x27; => &#x27;Overlay process failed. Please check logs for details.&#x27;], 500);&#xA;    }&#xA;}&#xA;

    &#xA;