Recherche avancée

Médias (29)

Mot : - Tags -/Musique

Autres articles (63)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

Sur d’autres sites (4825)

  • Download m3u8 segments with ffmpeg without writing the .ts files to disk

    22 avril 2021, par O R

    I am trying to download m3u8 segments from an HLS live stream with ffmpeg without writing the .ts files to disk. I intend to run opencv on the image data in real time. Here is what I have tried, but I am only able to get one segment at a time and don't know how to just keep it in memory without writing to disk. When inspecting the network requests using developer tools on the Twitch site, I see the m3u8's arriving in real time, although, these don't work in the script. I have to refresh the page and get the URL of the first request that arrives, which is a URL not ending in .m3u8 (the one i'm using in the script)

    


    import requests
import m3u8

url = 'https://usher.ttvnw.net/api/channel/hls/gernaderjake.m3u8?allow_source=true&fast_bread=true&p=4466372&play_session_id=d66db58de3bf6be70a5f5824bbb72763&player_backend=mediaplayer&playlist_include_framerate=true&reassignments_supported=true&sig=2b97079328898fdae56b041616be6fc7b01bd13c&supported_codecs=avc1&token=%7B%22adblock%22%3Afalse%2C%22authorization%22%3A%7B%22forbidden%22%3Afalse%2C%22reason%22%3A%22%22%7D%2C%22blackout_enabled%22%3Afalse%2C%22channel%22%3A%22gernaderjake%22%2C%22channel_id%22%3A1423946%2C%22chansub%22%3A%7B%22restricted_bitrates%22%3A%5B%5D%2C%22view_until%22%3A1924905600%7D%2C%22ci_gb%22%3Afalse%2C%22geoblock_reason%22%3A%22%22%2C%22device_id%22%3A%22ec6cb1f95615ed0b%22%2C%22expires%22%3A1618772589%2C%22extended_history_allowed%22%3Afalse%2C%22game%22%3A%22%22%2C%22hide_ads%22%3Afalse%2C%22https_required%22%3Atrue%2C%22mature%22%3Afalse%2C%22partner%22%3Afalse%2C%22platform%22%3A%22web%22%2C%22player_type%22%3A%22site%22%2C%22private%22%3A%7B%22allowed_to_view%22%3Atrue%7D%2C%22privileged%22%3Afalse%2C%22role%22%3A%22%22%2C%22server_ads%22%3Afalse%2C%22show_ads%22%3Atrue%2C%22subscriber%22%3Afalse%2C%22turbo%22%3Afalse%2C%22user_id%22%3Anull%2C%22user_ip%22%3A%22173.22.40.125%22%2C%22version%22%3A2%7D&cdm=wv&player_version=1.3.0'

r = requests.get(url)

m3u8_master = m3u8.loads(r.text)

playlist_url = m3u8_master.data['playlists'][0]['uri']

r = requests.get(playlist_url)

playlist = m3u8.loads(r.text)

playlist.data['segments'][0]['uri']

r = requests.get(playlist.data['segments'][0]['uri'])

with open('video.ts', 'wb') as f:
    for segment in playlist.data['segments']:
        url = segment['uri']
        r = requests.get(url)
        f.write(r.content)


    


  • Streaming windows desktop to Youtube with ffmpeg [closed]

    23 mai 2021, par rarahim

    I've been spending days trying to stream my live desktop to Youtube using ffmpeg. There are too many questions and answers on SO about this topic but none really works for me, or perhaps because working with ffmpeg is non-trivial task with it's never ending list of available options.

    


    So far, what sort of works for me is using the following (which is a mixture of what was gathered from various sources) :

    


    


    ffmpeg -threads:v 2 -threads:a 8 -filter_threads 2 -thread_queue_size
5096 -f dshow -i video="screen-capture-recorder" -f dshow -i
audio="Stereo Mix (Realtek High Definition Audio)" -pix_fmt yuv420p
-c:v libx264 -qp:v 19 -profile:v high -rc:v cbr_ld_hq -level:v 4.2 -r:v 60 -g:v 120 -bf:v 3 -refs:v 16 -f flv rtmp ://a.rtmp.youtube.com/live2/KEY

    


    


    My questions are :

    


      

    1. how do i only stream video ? i do not want to stream audio, simply removing '-f dshow -i audio="Stereo Mix (Realtek High Definition Audio)"' causes it to fail

      


    2. 


    3. after a while, ffmpeg starts to hog my memory causing my system to slow down terribly, what causes this and how can i fix it ?

      


    4. 


    5. my video feed when viewed from Youtube keeps buffering rather frequently, how can this be fixed/improved ?

      


    6. 


    


    Thanks.

    


    UPDATE :
I've managed to somewhat figure out a workaround for these issues. Not sure if these are the right solutions but they work for now.

    


      

    1. Youtube apparently requires streams to have audio component. So instead of just removing the audio device form the options, i had to put in "-f lavfi -i anullsrc" to use null audio device.

      


    2. 


    3. The memory hog issue was improved by adding "-framerate 10" and "-r 10" to the input and output options, this reduces target frame rate to 10fps.

      


    4. 


    5. The overall stream performance seem to be indirectly improved by doing the above actions.

      


    6. 


    


    So finally the working simplified version of my ffmpeg command is :

    


    


    ffmpeg -framerate 10 -f dshow -i video="screen-capture-recorder" -f
lavfi -i anullsrc -vcodec libx264 -preset:v ultrafast -pix_fmt yuv420p
-f flv -r 10 rtmp ://a.rtmp.youtube.com/live2/KEY

    


    


    I'm updating here in case it might be useful to someone at some point in the future.

    


  • Encoding RGB Frame Data with H264

    16 avril 2021, par Henwill8

    So I am trying to use ffmpeg c++ to encode rgb h264 video and I see two options :

    


      

    1. use sws_scale to convert the rgb frame data to yuv420 and encode it normally (this works but it seems to have a memory leak of some sort and freezes after around 20 seconds)

      


    2. 


    3. use libx264rgb to encode directly with the rgb data (preferable as then there isnt the loss and color shift of converting rgb to yuv to my knowledge but when I tried using this method the outputted video was completely black)

      


    4. 


    


    This is on android so I am using the ffmpeg mobile kit (https://github.com/tanersener/ffmpeg-kit) full-gpl build which I think includes libx264rgb and when I try opening the codec by first finding it by name it opens successfully, is there anything else needed to be done differently when encoding with 264rgb ?

    


    Here is my current code :

    


    #include "include/video_recorder.hpp"

void VideoCapture::Encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile, int framesToWrite = 1) {
    int ret;

    /* send the frame to the encoder */
    // if (frame)
    // {
        // log("Send frame %i at time %li", frameCounter, frame->pts);
    // }

    ret = avcodec_send_frame(enc_ctx, frame);
    if (ret < 0)
    {
        log("Error sending a frame for encoding\n");
        return;
    }

    while (ret >= 0)
    {
        ret = avcodec_receive_packet(enc_ctx, pkt);
        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
        {
            return;
        }
        else if (ret < 0)
        {
            log("Error during encoding\n");
            return;
        }

        // log("Write packet %li (size=%i)\n", pkt->pts, pkt->size);
        for (int i = 0; i < framesToWrite; i++)
        {
            fwrite(pkt->data, 1, pkt->size, outfile);
        }
        av_packet_unref(pkt);
    }
}

void VideoCapture::AddFrame(rgb24 *data) {
    if(!initialized) return;

    if(startTime == 0) {
        startTime = UnityEngine::Time::get_time();
        log("Video global time start is %f", startTime);
    }

    int framesToWrite = 1;

    // if (stabilizeFPS) {
    //     framesToWrite = std::max(0, int(TotalLength() / (1.0f / float(fps * 2))) - frameCounter);
    //     log("Frames to write: %i, equation is int(%f / (1 / %i)) - %i", framesToWrite, TotalLength(), fps, frameCounter);
    // }

    if(framesToWrite == 0) return;

    frameCounter += framesToWrite;

    int ret;

    /* make sure the frame data is writable */
    ret = av_frame_make_writable(frame);
    if (ret < 0)
    {
        log("Could not make the frame writable: %s", av_err2str(ret));
        return;
    }

    // if (!swsCtx)
    // {
    //     swsCtx = sws_getContext(c->width, c->height, AV_PIX_FMT_RGB24, c->width, c->height, AV_PIX_FMT_YUV420P, SWS_POINT, 0, 0, 0);
    // }
    // int inLinesize[1] = {3 * c->width};
    // sws_scale(swsCtx, (const uint8_t *const *)&data, inLinesize, 0, c->height, frame->data, frame->linesize);

    frame->pts = frameCounter;

    /* encode the image */
    Encode(c, frame, pkt, f, framesToWrite);
}

void VideoCapture::Finish()
{
    //DELAYED FRAMES
    // Encode(c, NULL, pkt, f);

    fclose(f);

    avcodec_free_context(&c);
    av_frame_free(&frame);
    av_packet_free(&pkt);

    initialized = false;
}

void VideoCapture::Init(int videoWidth, int videoHeight, int fpsrate, int videoBitrate, bool stabilizeFPS, std::string encodeSpeed, std::string filepath)
{
    log("Setting up video at path " + filepath);
    fps = fpsrate;
    width = videoWidth;
    height = videoHeight;
    bitrate = videoBitrate * 1000;
    filename = filepath.c_str();
    this->stabilizeFPS = stabilizeFPS;
    frameCounter = 0;

    int ret;

    codec = avcodec_find_encoder_by_name("libx264rgb");
    if (!codec)
    {
        log("Codec not found");
        return;
    }

    c = avcodec_alloc_context3(codec);
    if (!c)
    {
        log("Could not allocate video codec context\n");
        return;
    }

    pkt = av_packet_alloc();
    if (!pkt)
        return;

    c->bit_rate = bitrate * 1000;
    c->width = width;
    c->height = height;
    c->time_base = (AVRational){1, fps};
    c->framerate = (AVRational){fps, 1};

    c->gop_size = 10;
    c->max_b_frames = 1;
    c->pix_fmt = AV_PIX_FMT_RGB24;

    if (codec->id == AV_CODEC_ID_H264)
        av_opt_set(c->priv_data, "preset", encodeSpeed.c_str(), 0);

    ret = avcodec_open2(c, codec, NULL);
    if (ret < 0)
    {
        log("Could not open codec: %s\n", av_err2str(ret));
        return;
    }

    log("Successfully opened codec");

    f = fopen(filename, "wb");
    if (!f)
    {
        log("Could not open %s\n", filename);
        return;
    }

    frame = av_frame_alloc();
    if (!frame)
    {
        log("Could not allocate video frame\n");
        return;
    }
    frame->format = c->pix_fmt;
    frame->width = c->width;
    frame->height = c->height;

    ret = av_frame_get_buffer(frame, 0);
    if (ret < 0)
    {
        log("Could not allocate the video frame data\n");
        return;
    }

    initialized = true;
    log("Finished initializing video at path %s", filename);

    encodingThread = std::thread(&VideoCapture::encodeFrames, this);
}

void VideoCapture::encodeFrames()
{
    log("Starting encoding thread");

    while (initialized || !framebuffers.empty())
    {
        if (!framebuffers.empty())
        {
            std::unique_lock lock(framebuffer_mutex);
            std::list listCopy(framebuffers); // copy the list
            framebuffers.clear();
            lock.unlock();
            // Unlock and use the copy

            // Now we use the copied list and it should be ours only
            while (!listCopy.empty()) {
                // log("size is %i", framebuffers.size());
                auto it = listCopy.begin();
                auto frameData = (rgb24 *) *it;
                this->AddFrame(frameData);
                // free(*it);
                free(frameData);
                listCopy.pop_front();
            }
        }
    }
    log("Ending encoding thread");
}

void VideoCapture::queueFrame(void *frame) {
    std::unique_lock lock(framebuffer_mutex);
    framebuffers.push_back(frame);
}

VideoCapture::~VideoCapture()
{
    initialized = false; // should we force it to stop or force it to wait?

    if (encodingThread.joinable())
        encodingThread.join();
}```