Recherche avancée

Médias (2)

Mot : - Tags -/doc2img

Autres articles (38)

  • Librairies et binaires spécifiques au traitement vidéo et sonore

    31 janvier 2010, par

    Les logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
    Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
    Binaires complémentaires et facultatifs flvtool2 : (...)

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

  • De l’upload à la vidéo finale [version standalone]

    31 janvier 2010, par

    Le chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
    Upload et récupération d’informations de la vidéo source
    Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
    Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)

Sur d’autres sites (7308)

  • attempting to save FuncAnimation changes the animation

    25 mars 2024, par pibion

    I am attempting to create and save an animation of a time-varying vector field using matplotlib's FuncAnimation. When I run the animation without attempting to save it, it updates smoothly as expected. However, when I try to save the animation, the vectors increase in length and the animation only appears to update a few times. I've been able to record the screen to get a video file, but I'd like to understand how to save the animation to a video in python.

    


    Here is the code to create the vector field animation. I ran this in a local jupyter notebook using python 3.9.12 on Windows.

    


    %matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

x_min, x_max = -20, 20
y_min, y_max = 0, 25
wire_x = -4
wire_y = 17

# Define the vector field function (example: rotating vector field)
def vector_field(x, y, t):
    x = x - wire_x
    y = y - wire_y
    r = np.sin(t) / (x**2 + y**2)
    u = -r * y
    v = r * x
    return (u, v)

# Define grid
x = np.linspace(x_min, x_max, 20)
y = np.linspace(y_min, y_max, 20)
X, Y = np.meshgrid(x, y)

# Create animation
fig, ax = plt.subplots(1,1)
ax.set_aspect('equal')
ax.set_xlim(x_min, x_max)
ax.set_ylim(y_min, y_max)
ax.set_xlabel('X (m)')
ax.set_ylabel('Y (m)')

u, v = vector_field(X, Y, 1)

quiver = ax.quiver(X, Y, u, v)

time_arr = np.linspace(0,20,200)

plt.show()

def update_quiver(num):
    t = num * 0.1  # Time step
    u, v = vector_field(X, Y, t)
    quiver.set_UVC(u, v)

ani = animation.FuncAnimation(fig, update_quiver, frames=200, interval=50, repeat=False)


    


    This produces an animation whose vectors smoothly vary in length on my computer.

    


    However, when I try to save the animation by adding the lines

    


    writervideo = animation.FFMpegWriter(fps=60) 
ani.save('field_leftWire.mp4', writer=writervideo) 


    


    then the animation changes - the vectors are much longer and it appears to only update a few times throughout the animation.

    


    I'll also note that I had to install ffmpeg and restart my computer as outlined in Installation of FFMPEG for Python in WIndows to get the last two lines to run without error.

    


  • Segmentation fault caused by FFMPEG / SFML on Macos

    12 avril 2024, par Med ali Damergi ReTr0

    I'm trying to code a basic video player function to use it in a game it's supposed to get a sfml window and a video link as inputs and run the video :

    


    extern "C" {&#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;#include <sfml></sfml>Graphics.hpp>&#xA;#include <iostream>&#xA;&#xA;const AVCodec* pCodec = nullptr;&#xA;&#xA;&#xA;void lecteurVideo(const std::string&amp; videoPath, sf::RenderWindow&amp; window) {&#xA;    // Open the video file&#xA;    AVFormatContext* pFormatCtx = avformat_alloc_context();&#xA;    if (avformat_open_input(&amp;pFormatCtx, videoPath.c_str(), nullptr, nullptr) != 0) {&#xA;        std::cerr &lt;&lt; "Failed to open video file" &lt;&lt; std::endl;&#xA;        return;&#xA;    }&#xA;&#xA;    // Retrieve stream information&#xA;    if (avformat_find_stream_info(pFormatCtx, nullptr) &lt; 0) {&#xA;        std::cerr &lt;&lt; "Failed to retrieve stream information" &lt;&lt; std::endl;&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Find the first video stream&#xA;    int videoStreamIndex = -1;&#xA;    for (unsigned int i = 0; i &lt; pFormatCtx->nb_streams; i&#x2B;&#x2B;) {&#xA;        if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {&#xA;            videoStreamIndex = i;&#xA;            break;&#xA;        }&#xA;    }&#xA;    if (videoStreamIndex == -1) {&#xA;        std::cerr &lt;&lt; "Failed to find video stream" &lt;&lt; std::endl;&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Get the codec parameters for the video stream&#xA;    AVCodecParameters* pCodecParams = pFormatCtx->streams[videoStreamIndex]->codecpar;&#xA;&#xA;    // Find the decoder for the video stream&#xA;    const AVCodec* pCodec = avcodec_find_decoder(pCodecParams->codec_id);&#xA;    if (pCodec == nullptr) {&#xA;        std::cerr &lt;&lt; "Failed to find video decoder" &lt;&lt; std::endl;&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Allocate a codec context for the decoder&#xA;    AVCodecContext* pCodecCtx = avcodec_alloc_context3(pCodec);&#xA;    if (pCodecCtx == nullptr) {&#xA;        std::cerr &lt;&lt; "Failed to allocate codec context" &lt;&lt; std::endl;&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Initialize the codec context with the codec parameters&#xA;    if (avcodec_parameters_to_context(pCodecCtx, pCodecParams) &lt; 0) {&#xA;        std::cerr &lt;&lt; "Failed to initialize codec context" &lt;&lt; std::endl;&#xA;        avcodec_free_context(&amp;pCodecCtx);&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Open the codec&#xA;    if (avcodec_open2(pCodecCtx, pCodec, nullptr) &lt; 0) {&#xA;        std::cerr &lt;&lt; "Failed to open codec" &lt;&lt; std::endl;&#xA;        avcodec_free_context(&amp;pCodecCtx);&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Create a frame to hold the decoded video data&#xA;    AVFrame* pFrame = av_frame_alloc();&#xA;    if (pFrame == nullptr) {&#xA;        std::cerr &lt;&lt; "Failed to allocate frame" &lt;&lt; std::endl;&#xA;        avcodec_close(pCodecCtx);&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Create a packet for reading compressed video data&#xA;    AVPacket* pPacket = av_packet_alloc();&#xA;    if (pPacket == nullptr) {&#xA;        std::cerr &lt;&lt; "Failed to allocate packet" &lt;&lt; std::endl;&#xA;        av_frame_free(&amp;pFrame);&#xA;        avcodec_close(pCodecCtx);&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Create a software scaler context for converting the video frame format&#xA;    SwsContext* pSwsCtx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,&#xA;                                         pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_RGB24,&#xA;                                         SWS_BILINEAR, nullptr, nullptr, nullptr);&#xA;    if (pSwsCtx == nullptr) {&#xA;        std::cerr &lt;&lt; "Failed to create software scaler context" &lt;&lt; std::endl;&#xA;        av_packet_free(&amp;pPacket);&#xA;        av_frame_free(&amp;pFrame);&#xA;        avcodec_close(pCodecCtx);&#xA;        avformat_close_input(&amp;pFormatCtx);&#xA;        return;&#xA;    }&#xA;&#xA;    // Create an SFML texture and sprite for displaying the video frames&#xA;    sf::Texture texture;&#xA;    sf::Sprite sprite;&#xA;&#xA;    // Read frames from the video file and display them in the SFML window&#xA;    while (av_read_frame(pFormatCtx, pPacket) >= 0) {&#xA;        if (pPacket->stream_index == videoStreamIndex) {&#xA;            // Decode the video packet into a frame&#xA;            if (avcodec_send_packet(pCodecCtx, pPacket) &lt; 0) {&#xA;                std::cerr &lt;&lt; "Failed to send packet to decoder" &lt;&lt; std::endl;&#xA;                break;&#xA;            }&#xA;            if (avcodec_receive_frame(pCodecCtx, pFrame) &lt; 0) {&#xA;                std::cerr &lt;&lt; "Failed to receive frame from decoder" &lt;&lt; std::endl;&#xA;                break;&#xA;            }&#xA;&#xA;            // Convert the frame format to RGB24&#xA;            uint8_t* rgbBuffer = new uint8_t[pCodecCtx->width * pCodecCtx->height * 3];&#xA;            uint8_t* rgbPlanes[1] = { rgbBuffer };&#xA;            int rgbStrides[1] = { pCodecCtx->width * 3 };&#xA;            sws_scale(pSwsCtx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height,&#xA;                      rgbPlanes, rgbStrides);&#xA;&#xA;            // Update the SFML texture with the RGB24 data&#xA;            texture.create(pCodecCtx->width, pCodecCtx->height);&#xA;            texture.update(rgbBuffer);&#xA;&#xA;            // Display the texture in the SFML window&#xA;            sprite.setTexture(texture);&#xA;            window.clear();&#xA;            window.draw(sprite);&#xA;            window.display();&#xA;&#xA;            delete[] rgbBuffer;&#xA;        }&#xA;&#xA;        av_packet_unref(pPacket);&#xA;    }&#xA;&#xA;    // Clean up resources&#xA;    av_packet_free(&amp;pPacket);&#xA;    av_frame_free(&amp;pFrame);&#xA;    avcodec_close(pCodecCtx);&#xA;    avformat_close_input(&amp;pFormatCtx);&#xA;    sws_freeContext(pSwsCtx);&#xA;}&#xA;&#xA;int main() {&#xA;    sf::RenderWindow window(sf::VideoMode(800, 600), "Lecteur Video SFML");&#xA;    lecteurVideo("/Users/mac/cours/spaceRevolution/Videos/58e62585-c143-483a-9149-b401ebc01d02.mp4", window);&#xA;    return 0;&#xA;}&#xA;</iostream>

    &#xA;

    It works on my other computer running on ubuntu but not on my main laptop on macOS : It dosent open any window and instantly cause a segmentation fault.

    &#xA;

    I've tried tu run valgrind on it but valgrind dosent run well on macOS.

    &#xA;

    Could anybody help me with this ?

    &#xA;

  • OpenEncodeSessionEx failed : no encode device (1) : (no details)

    11 mai 2024, par Jayce Li

    I'm testing the ddagrab filter with this command line :

    &#xA;

    ffmpeg -f lavfi -i ddagrab -c:v h264_nvenc -cq 18 -v 40 -t 10 -y out.mp4

    &#xA;

    FFmpeg exits with this error message :&#xA;OpenEncodeSessionEx failed : no encode device (1) : (no details)

    &#xA;

    My laptop has Nvidia Geforce GTX 1050 Ti, Driver version 527.37. Windows 10 Home, Version 22H2, OS build 19045.4291. DirectX version 12.

    &#xA;

    This command works without problems :&#xA;ffmpeg -f gdigrab -i desktop -c:v h264_nvenc -t 10 -y out.mp4

    &#xA;

    I test these command on my other laptop with Nvidia Geforce RTX 2060, Driver version 512.78.Windows 10 Home, Version 22H2, OS build 19045.3693. DirectX version 12. They both work fine.

    &#xA;

    How to solve the problem. OpenEncodeSessionEx failed : no encode device (1) : (no details)

    &#xA;