Recherche avancée

Médias (91)

Autres articles (109)

  • L’agrémenter visuellement

    10 avril 2011

    MediaSPIP est basé sur un système de thèmes et de squelettes. Les squelettes définissent le placement des informations dans la page, définissant un usage spécifique de la plateforme, et les thèmes l’habillage graphique général.
    Chacun peut proposer un nouveau thème graphique ou un squelette et le mettre à disposition de la communauté.

  • 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

  • Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs

    12 avril 2011, par

    La manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
    Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras.

Sur d’autres sites (11558)

  • Could anyone help me understand why moviepy is rendering at 2.5 it/s ?

    23 décembre 2023, par tristan

    I'm writing a program that uses moviepy to make those weird reddit thread videos with mc parkour playing in the background (real original ik), and everything is good except for when im rendering video which seems to consume a ton of memory and moves really... really slow, like 2.5 it/s. could anyone help ? also im a novice programmer that has no bearing on what is conventional or proper, so sorry if my code is very bad.

    


    from moviepy.video.fx.all import resize
from moviepy.video.tools.subtitles import SubtitlesClip
from moviepy.editor import (
    CompositeVideoClip,
    AudioFileClip,
    VideoFileClip,
    ImageClip,
    TextClip
)
import random
import moviepy.config as cfg
import librosa
from imagegenerator import draw_title
from audioeditor import concatenate_audios
import soundfile as sf
import numpy as np

# Constants
VIDEO_FADE_DURATION = 0.4
SPEED_FACTOR = 1.1
TEXT_WIDTH = 600
MINIMUM_FONT_SIZE = 60
FONT_COLOR = "white"
OUTLINE_COLOR = "black"
TITLE_ANIMATION_DURATION = 0.25
ANIMATION_DURATION = 0.2

# Configure imagemagick binary
cfg.change_settings(
    {
        "IMAGEMAGICK_BINARY": "magick/magick.exe"
    }
)

# Ease-out function
def ease_out(t):
    return 1 - (1 - t) ** 2

# Overlap audio files
def overlap_audio_files(audio_path1, audio_path2):
    # Load the first audio file
    audio1, sr1 = librosa.load(audio_path1, sr=None)

    # Load the second audio file
    audio2, sr2 = librosa.load(audio_path2, sr=None)

    # Ensure both audio files have the same sample rate
    if sr1 != sr2:
        raise ValueError("Sample rates of the two audio files must be the same.")

    # Calculate the duration of audio2
    audio2_duration = len(audio2)

    # Tile audio1 to match the duration of audio2
    audio1 = np.tile(audio1, int(np.ceil(audio2_duration / len(audio1))))

    # Trim audio1 to match the duration of audio2
    audio1 = audio1[:audio2_duration]

    # Combine the audio files by superimposing them
    combined_audio = audio1 + audio2

    # Save the combined audio to a new file
    output_path = "temp/ttsclips/combined_audio.wav"
    sf.write(output_path, combined_audio, sr1)

    return output_path

# Generator function for subtitles with centered alignment and outline
def centered_text_generator_white(txt):
    return TextClip(
        txt,
        font=r"fonts/Invisible-ExtraBold.otf",
        fontsize=86,
        color=FONT_COLOR,
        bg_color='transparent',  # Use a transparent background
        align='center',  # Center the text
        size=(1072, 1682),
        method='caption',  # Draw a caption instead of a title
    )

# Generator function for subtitles with centered alignment and blurred outline
def centered_text_generator_black_blurred_outline(txt, blur_factor=3):
    outline_clip = TextClip(
        txt,
        font=r"fonts/Invisible-ExtraBold.otf",
        fontsize=86,
        color=OUTLINE_COLOR,
        bg_color='transparent',  # Use a transparent background
        align='center',  # Center the text
        size=(1080, 1688),
        method='caption',  # Draw a caption instead of a title
    )

    # Blur the black text (outline)
    blurred_outline_clip = outline_clip.fx(resize, 1.0 / blur_factor)
    blurred_outline_clip = blurred_outline_clip.fx(resize, blur_factor)

    return blurred_outline_clip

# Compile video function
def compile_video(title_content, upvotes, comments, tone, subreddit, video_num):
    # Set the dimensions of the video (720x1280 in this case)
    height = 1280

    # Concatenate the audios
    concatenate_audios()

    concatenated_audio_path = r"temp/ttsclips/concatenated_audio.mp3"
    title_audio_path = r"temp/ttsclips/title.mp3"

    title_audio = AudioFileClip(title_audio_path)
    concatenated_audio = AudioFileClip(concatenated_audio_path)

    # Calculate for video duration
    title_duration = title_audio.duration
    duration = concatenated_audio.duration

    # Set background
    background_path = f"saved_videos/newmcparkour.mp4"
    background = VideoFileClip(background_path)
    background_duration = background.duration
    random_start = random.uniform(0, background_duration - duration)
    background = background.subclip(random_start, random_start + duration)

    # Apply fade-out effect to both background clips
    background = background.crossfadeout(VIDEO_FADE_DURATION)

    # Generate the background image with rounded corners
    background_image_path = draw_title(title_content, upvotes, comments, subreddit)

    # Load the background image with rounded corners
    background_image = ImageClip(background_image_path)

    # Set the start of the animated title clip
    animated_background_clip = background_image.set_start(0)

    # Set the initial position of the text at the bottom of the screen
    initial_position = (90, height)

    # Calculate the final position of the text at the center of the screen
    final_position = [90, 630]

    # Animate the title clip to slide up over the course of the animation duration
    animated_background_clip = animated_background_clip.set_position(
        lambda t: (
            initial_position[0],
            initial_position[1]
            - (initial_position[1] - final_position[1])
            * ease_out(t / TITLE_ANIMATION_DURATION),
        )
    )

    # Set the duration of the animated title clip
    animated_background_clip = animated_background_clip.set_duration(
        TITLE_ANIMATION_DURATION
    )

    # Assign start times to title image
    stationary_background_clip = background_image.set_start(TITLE_ANIMATION_DURATION)

    # Assign positions to stationary title image
    stationary_background_clip = stationary_background_clip.set_position(final_position)

    # Assign durations to stationary title image
    stationary_background_clip = stationary_background_clip.set_duration(
        title_duration - TITLE_ANIMATION_DURATION
    )

    #  Select background music
    if tone == "normal":
        music_options = [
            "Anguish",
            "Garden",
            "Limerence",
            "Lost",
            "NoWayOut",
            "Summer",
            "Never",
            "Miss",
            "Touch",
            "Stellar"
        ]
    elif tone == "eerie":
        music_options = [
            "Creepy",
            "Scary",
            "Spooky",
            "Space",
            "Suspense"
        ]
    background_music_choice = random.choice(music_options)
    background_music_path = f"music/eeriemusic/{background_music_choice}.mp3"

    # Create final audio by overlapping background music and concatenated audio
    final_audio = AudioFileClip(
        overlap_audio_files(background_music_path, concatenated_audio_path)
    )

    # Release the concatenated audio
    concatenated_audio.close()

    # Create subtitles clip using the centered_text_generator
    subtitles = SubtitlesClip("temp/ttsclips/content_speechmarks.srt",
                            lambda txt: centered_text_generator_white(txt))
    subtitles_outline = SubtitlesClip("temp/ttsclips/content_speechmarks.srt",
                            lambda txt: centered_text_generator_black_blurred_outline(txt))

    # Overlay subtitles on the blurred background
    final_clip = CompositeVideoClip(
        [background, animated_background_clip, stationary_background_clip, subtitles_outline, subtitles]
    )

    # Set the final video dimensions and export the video
    final_clip = final_clip.set_duration(duration)
    final_clip = final_clip.set_audio(final_audio)

    final_clip.write_videofile(
        f"temp/videos/{video_num}.mp4",
        codec="libx264",
        fps=60,
        bitrate="8000k",
        audio_codec="aac",
        audio_bitrate="192k",
        preset="ultrafast",
        threads=8
    )

    # Release the concatenated audio
    concatenated_audio.close()

    # Release the title audio
    title_audio.close()

    # Release the background video and image
    background.close()
    background_image.close()

    # Release the final audio
    final_audio.close()

    # Release the subtitle clips
    subtitles.close()
    subtitles_outline.close()

    # Release the final video clip
    final_clip.close()


    


    ive tried turning down my settings, like setting it to "ultrafast" and dropping the bitrate, but nothing seems to work. the only thing I can think of now is that there is something Im doing wrong with moviepy.

    


  • How to convert multiple jpg images to MP4 format using FFmpeg ?

    30 janvier 2024, par PDLAOZEI
      

    • I first used the FFmpeg command line to implement this function.
ffmpeg -framerate 1 -pattern_type glob -i "./image/*.jpg" -c:v libx264 -crf 25 -vf format=yuv420p -movflags +faststart test.mp4

      


    • 


    • Then I use FFmpeg's api to convert multiple jpg into MP4 format, the process is probably.

      


    • 


    


      

    1. Find the AV_CODEC_ID_MPEG4 encoder.
    2. 


    3. Turn on the encoder.
    4. 


    5. Set video stream parameters.
    6. 


    7. Open the output file.
    8. 


    9. Write file header.
    10. 


    11. Allocate image frame rate and buffer.
    12. 


    13. Write each jpg image to the video (write in a loop).
7-1. read jpg image.
7-2. Find video stream information.
7-3. Decoded image frame.
7-4. Transcode to yuv420p.
7-5. Encode and write video frames.
    14. 


    15. Finally, free memory.
    16. 


    


    update the reproducible example

    


    #include <iostream>&#xA;#include <vector>&#xA;#include <string>&#xA;#include <chrono>&#xA;#include <thread>&#xA;&#xA;#include <filesystem>&#xA;#include <algorithm>&#xA;#include <iomanip>&#xA;#include <sys></sys>stat.h>&#xA;&#xA;extern "C"&#xA;{&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libavutil></libavutil>imgutils.h>&#xA;}&#xA;&#xA;namespace fs = std::filesystem;&#xA;&#xA;bool compareFilenames(const std::string &amp;str1, const std::string &amp;str2)&#xA;{&#xA;    //ToDo Sort&#xA;}&#xA;&#xA;int main()&#xA;{&#xA;    &#xA;    fs::path folderPath = "" //replace your image foldePath&#xA;&#xA;    std::vector imageFiles;&#xA;    for (const auto &amp;entry : fs::directory_iterator(folderPath))&#xA;    {&#xA;        if (entry.is_regular_file() &amp;&amp; entry.path().extension() == ".jpg")&#xA;        {&#xA;            imageFiles.push_back(entry.path());&#xA;        }&#xA;    }&#xA;&#xA;    std::sort(imageFiles.begin(), imageFiles.end(), compareFilenames);&#xA;&#xA;    std::string outputVideoFile = "output.mp4";&#xA;&#xA;    AVFormatContext *formatContext = nullptr;&#xA;    AVCodecContext *codecContext = nullptr;&#xA;    AVStream *videoStream = nullptr;&#xA;&#xA;    av_register_all();&#xA;    avformat_alloc_output_context2(&amp;formatContext, nullptr, nullptr, outputVideoFile.c_str());&#xA;&#xA;&#xA;    AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MPEG4);//AV_CODEC_ID_H264&#xA;    videoStream = avformat_new_stream(formatContext, codec);&#xA;    codecContext = avcodec_alloc_context3(codec);&#xA;&#xA;    codecContext->codec_id = codec->id;&#xA;    codecContext->codec_type = AVMEDIA_TYPE_VIDEO;&#xA;    codecContext->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;    codecContext->width = 1920;&#xA;    codecContext->height = 1080;&#xA;    codecContext->time_base = {1, 2}; &#xA;    codecContext->bit_rate = 100000000;&#xA;    codecContext->gop_size = 1;&#xA;&#xA;    avcodec_open2(codecContext, codec, nullptr);&#xA;    avcodec_parameters_from_context(videoStream->codecpar, codecContext);&#xA;&#xA;    avio_open(&amp;formatContext->pb, outputVideoFile.c_str(), AVIO_FLAG_WRITE);&#xA;    avformat_write_header(formatContext, NULL);&#xA;&#xA;    AVFrame *frame = av_frame_alloc();&#xA;&#xA;    std::vector imageBuffer(codecContext->width * codecContext->height * 3);&#xA;    AVPacket packet;&#xA;&#xA;    for (const std::string &amp;imageFile : imageFiles)&#xA;    {&#xA;&#xA;        AVFormatContext *inputFormatContext = avformat_alloc_context();&#xA;        avformat_open_input(&amp;inputFormatContext, imageFile.c_str(), nullptr, nullptr);&#xA;&#xA;        avformat_find_stream_info(inputFormatContext, nullptr);&#xA;&#xA;        AVCodec *inputCodec = nullptr;&#xA;        AVCodecContext *inputCodecContext = nullptr;&#xA;        int videoStreamIndex = -1;&#xA;&#xA;        for (unsigned int i = 0; i &lt; inputFormatContext->nb_streams; i&#x2B;&#x2B;)&#xA;        {&#xA;            if (inputFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;            {&#xA;                videoStreamIndex = i;&#xA;                inputCodec = avcodec_find_decoder(inputFormatContext->streams[i]->codecpar->codec_id);&#xA;                inputCodecContext = avcodec_alloc_context3(inputCodec);&#xA;                avcodec_parameters_to_context(inputCodecContext, inputFormatContext->streams[i]->codecpar);&#xA;                avcodec_open2(inputCodecContext, inputCodec, NULL);&#xA;                break;&#xA;            }&#xA;        }&#xA;&#xA;        AVFrame *inputFrame = av_frame_alloc();&#xA;        while (av_read_frame(inputFormatContext, &amp;packet) >= 0)&#xA;        {&#xA;            if (packet.stream_index == videoStreamIndex)&#xA;            {&#xA;                int response = avcodec_send_packet(inputCodecContext, &amp;packet);&#xA;&#xA;                while (response >= 0)&#xA;                {&#xA;                    response = avcodec_receive_frame(inputCodecContext, inputFrame);&#xA;                    if (response == AVERROR(EAGAIN) || response == AVERROR_EOF)&#xA;                    {&#xA;                        break;&#xA;                    }&#xA;                    else if (response &lt; 0)&#xA;                    {&#xA;                        std::cerr &lt;&lt; "Failed to receive frame from input decoder" &lt;&lt; std::endl;&#xA;                        break;&#xA;                    }&#xA;&#xA;                                        AVFrame *yuvFrame = av_frame_alloc();&#xA;                    av_image_alloc(yuvFrame->data, yuvFrame->linesize, codecContext->width, codecContext->height, codecContext->pix_fmt, 1);&#xA;&#xA;                    SwsContext *yuvSwsContext = sws_getContext(inputFrame->width, inputFrame->height, AV_PIX_FMT_RGB24,&#xA;                                                               codecContext->width, codecContext->height, codecContext->pix_fmt,&#xA;                                                               0, nullptr, nullptr, nullptr);&#xA;&#xA;                    sws_scale(yuvSwsContext, inputFrame->data, inputFrame->linesize, 0, inputFrame->height,&#xA;                              yuvFrame->data, yuvFrame->linesize);&#xA;&#xA;&#xA;                    memcpy(imageBuffer.data(), yuvFrame->data[0], codecContext->width * codecContext->height);&#xA;                    memcpy(imageBuffer.data() &#x2B; codecContext->width * codecContext->height, yuvFrame->data[1], codecContext->width * codecContext->height / 4);&#xA;                    memcpy(imageBuffer.data() &#x2B; codecContext->width * codecContext->height * 5 / 4, yuvFrame->data[2], codecContext->width * codecContext->height / 4);&#xA;&#xA;                    frame->data[0] = imageBuffer.data();&#xA;                    frame->data[1] = frame->data[0] &#x2B; codecContext->width * codecContext->height;&#xA;                    frame->data[2] = frame->data[1] &#x2B; codecContext->width * codecContext->height / 4;&#xA;                    frame->linesize[0] = codecContext->width;&#xA;                    frame->linesize[1] = codecContext->width / 2;&#xA;                    frame->linesize[2] = codecContext->width / 2;&#xA;                    frame->width = codecContext->width;&#xA;                    frame->height = codecContext->height;&#xA;                    frame->format = codecContext->pix_fmt;&#xA;                    frame->pts = av_rescale_q(videoStream->nb_frames, videoStream->time_base, videoStream->codec->time_base);&#xA;&#xA;                    av_init_packet(&amp;packet);&#xA;                    packet.data = nullptr;&#xA;                    packet.size = 0;&#xA;&#xA;                    avcodec_send_frame(codecContext, frame);&#xA;&#xA;                    while (avcodec_receive_packet(codecContext, &amp;packet) >= 0)&#xA;                    {&#xA;                        av_packet_rescale_ts(&amp;packet, codecContext->time_base, videoStream->time_base);&#xA;                        packet.stream_index = videoStream->index;&#xA;&#xA;                        av_write_frame(formatContext, &amp;packet);&#xA;                        av_packet_unref(&amp;packet);&#xA;                    }&#xA;&#xA;                    av_freep(&amp;yuvFrame->data[0]);&#xA;                    av_freep(&amp;yuvFrame);&#xA;                    sws_freeContext(yuvSwsContext);&#xA;                }&#xA;            }&#xA;&#xA;            av_packet_unref(&amp;packet);&#xA;        }&#xA;&#xA;        av_frame_free(&amp;inputFrame);&#xA;        avcodec_close(inputCodecContext);&#xA;        avformat_close_input(&amp;inputFormatContext);&#xA;    }&#xA;&#xA;    av_write_trailer(formatContext);&#xA;&#xA;    av_frame_free(&amp;frame);&#xA;    avcodec_close(codecContext);&#xA;    av_free(codecContext);&#xA;    avio_close(formatContext->pb);&#xA;    avformat_free_context(formatContext);&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;&#xA;</iomanip></algorithm></filesystem></thread></chrono></string></vector></iostream>

    &#xA;

    But the encoding format is mpeg, which cannot be opened in the player included with windows, and the prompt is an unsupported format.

    &#xA;

    Although the vlc player can be opened and played normally, I need to play it normally on the player that comes with windows, because the output video will be played on the browser.

    &#xA;

    So I changed AV_CODEC_ID_MPEG4 to AV_CODEC_ID_H264, and the result is that although the file size of the output image is very large, only one picture is displayed during playback. I don't know what the problem is.

    &#xA;

    I was thinking about writing a new one, but I had no idea how to write a new one.&#xA;I would appreciate it if someone could write me an example.

    &#xA;

  • Use ffmpeg to pan right over an image and then pan left to the original location

    4 février 2024, par user1517922

    I'm using this command to pan to the right for 5 seconds on an image (like a 1080x1080 window moving across a larger image, 500px from the top) :

    &#xA;

    ffmpeg -loop 1 -r 30 -i image.jpg -vf crop=w=1080:h=1080:x=n:y=500 -frames:v 150 -pix_fmt yuv420p -preset fast -crf 30 video.mp4

    &#xA;

    I'd like to pan back to the left for 5 seconds to end up at the same spot.

    &#xA;

    The desired affect is when the video is on loop the square window pans right for 5 seconds then back left for 5 seconds then repeats, smooth and without flicker.

    &#xA;

    I suspect I need to use zoompan, but I haven't had success trying that.

    &#xA;