Recherche avancée

Médias (2)

Mot : - Tags -/plugins

Autres articles (100)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

Sur d’autres sites (8678)

  • Ffmpeg - how to call av_read_frame() when streamed data is not yet available ?

    16 janvier 2024, par CheekyChips

    I am streaming audio data and using the ffmpeg/libav libraries to process it in C++. I create a CustomIOContext and a read_packet function to provide the streamed data to ffmpeg, and I create an AVFormatContext using that CustomIOContext.

    


    I want to loop through all available data and extract packets using av_read_frame(), and then when there is not enough data left to create a packet I want to wait until I receive more data and then loop again through the new data. However, I can't figure out what to return in my read_packet function below to tell ffmpeg to wait until more data is available. Ffmpeg seems to require all data to be available now. When I have no data to return, ffmpeg seems to think it's the end of the file, when actually it just isn't ready yet. I have tried returning AVERROR(EAGAIN) but I still have problems. It seems like I get random decoder-specific error messages, because it thinks the input is invalid (when actually it is just not available yet), and then once I have the input and I try calling av_read_frame() again, it immediately returns a negative error code because it got into a bad state.

    


    What do I need to do to be able to loop through all the available data using av_read_frame(), and then pause and wait until more data arrives ? How do I keep ffmpeg happy ?

    


    // -------- Set up  --------
size_t ioContextBufferSize = 4096;
avioContextBuffer = avAllocateEmptyBuffer(ioContextBufferSize);
avioContext = avio_alloc_context(avioContextBuffer.ptr,
                         ioContextBufferSize,
                    0, // bWriteable (1=true,0=false)
                        &(opaque),
                        read_packet,
                        0, // Write callback function
                        0)}; // Seek function not provided

AVFormatContext* inContext = avformat_alloc_context();
inContext->pb = avioContext;
inContext->flags = AVFMT_FLAG_CUSTOM_IO;

avformat_open_input(&inContext, "", nullptr, nullptr);
inputPacket = av_packet_alloc();


    


    // -------- Loop and read data -------
// (the second time we reach this while loop, it never enters the loop :(
//
while ((ret = av_read_frame(inContext, inputPacket)) >= 0) {
  .. do stuff with inputPacket
}


    


    // -------- read_packet function -----
// copies data into ffmpeg's internal buffer. What do I return here???
//
static int read_packet(void* opaque, uint8_t* avioContextBuffer, int ioContextBufferSize) {
  OpaqueDataWrapper* streamedData = static_cast(opaque);

  size_t bytesToRead = std::min((size_t)ioContextBufferSize, streamedData->remainingBytes());

  if (!bytesToRead) {
    // We need to wait for more data to arrive! What do I return here to tell ffmpeg to wait a while? 
    if (streamedData->streamStillOpen()) {
      return AVERROR(EAGAIN);
    } else {
      return AVERROR_EOF;
    }
  }
  ... otherwise copy the next bit of data
}


    


  • Encoding raw nv12 frames with ffmpeg

    3 août 2012, par nirjhor

    I am trying to encode raw frames in nv12 format. Frame rate is 15. I am using avcodec to encode. My capture device has a callback function which is activated when a raw viewfinder frame is available. I am copying the raw viewfinder frame and making a AVFrame from the data. Then I supply the frame to avcodec_encode_video as described in the api sample but somehow I am not getting expected result. I am using posix thread. I keep the raw frames on a buffer. Then my encoder thread collects data from the buffer and encodes it. The speed of encoding is too slow (h264 and mpeg1 -tested). Is it a problem with my threading or something else ? I am at loss. The output is mysterious. The whole encoding process is a single function and single threaded but I find a bunch of frame encoded at a time. How exactly does the encoder function ?Here is the code snippet for encoding :

    while(cameraRunning)
    {
       pthread_mutex_lock(&lock_encoder);
       if(vr->buffer->getTotalData()>0)
       {
           i++;
           fprintf(stderr,"Encoding %d\n",i);
           AVFrame *picture;
           int y = 0,x;
           picture = avcodec_alloc_frame();
           av_image_alloc(picture->data, picture->linesize,c->width, c->height,c->pix_fmt, 1);
           uint8_t* buf_source = new uint8_t[vr->width*vr->height*3/2];
           uint8_t* data = vr->buffer->Read(vr->width*vr->height*3/2);
           memcpy(buf_source,data,vr->width*vr->height*3/2);
           //free(&vr->buffer->Buffer[vr->buffer->getRead()-1][0]);
           /*for (y = 0; y < vr->height*vr->width; y++)
           {
               picture->data[0][(y/vr->width) * picture->linesize[0] + (y%vr->width)] = buf_source[(y/vr->width)+(y%vr->width)]x + y + i * 7;
               if(yheight*vr->width/4)
               {
                   picture->data[1][(y/vr->width) * picture->linesize[1] + (y%vr->width)] = buf_source[vr->width*vr->height + 2 * ((y/vr->width)+(y%vr->width))]128 + y + i * 2;
                   picture->data[2][(y/vr->width) * picture->linesize[2] + (y%vr->width)] = buf_source[vr->width*vr->height +  2 * ((y/vr->width)+(y%vr->width)) + 1]64 + x + i * 5;
               }
           }

    */

           for(y=0;yheight;y++) {
                       for(x=0;xwidth;x++) {
                           picture->data[0][y * picture->linesize[0] + x] = x + y + i * 7;
                       }
                   }

                   /* Cb and Cr */
                   for(y=0;yheight/2;y++) {
                       for(x=0;xwidth/2;x++) {
                           picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
                           picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
                       }
                   }
           free(buf_source);
           fprintf(stderr,"Data ready\n");

           outbuf_size = 100000 + c->width*c->height*3/2;
           outbuf = (uint8_t*)malloc(outbuf_size);
           fprintf(stderr,"Preparation done!!!\n");
           out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
           had_output |= out_size;
           printf("encoding frame %3d (size=%5d)\n", i, out_size);
           fwrite(outbuf, 1, out_size, f);
           av_free(picture->data[0]);
           av_free(picture);

       }
       pthread_mutex_unlock(&lock_encoder);
    }
  • Live555 truncates encoded data of FFMpeg

    22 novembre 2019, par Harshil Makwana

    I am trying to stream H264 based data using Live555 over RTSP.

    I am capturing data using V4L2, and then encodes it using FFMPEG and then passing data to Live555’s DeviceSource file, in that I using H264VideoStreamFramer class,

    Below is my codec settings to configure AVCodecContext of encoder,

    codec = avcodec_find_encoder_by_name(CODEC_NAME);
    if (!codec) {
       cerr << "Codec " << codec_name << " not found\n";
       exit(1);
    }

    c = avcodec_alloc_context3(codec);
    if (!c) {
       cerr << "Could not allocate video codec context\n";
       exit(1);
    }

    pkt = av_packet_alloc();
    if (!pkt)
       exit(1);

    /* put sample parameters */
    c->bit_rate = 400000;
    /* resolution must be a multiple of two */
    c->width = PIC_HEIGHT;
    c->height = PIC_WIDTH;
    /* frames per second */
    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_YUV420P;
    c->rtp_payload_size = 30000;
    if (codec->id == AV_CODEC_ID_H264)
       av_opt_set(c->priv_data, "preset", "fast", 0);
    av_opt_set_int(c->priv_data, "slice-max-size", 30000, 0);
    /* open it */
    ret = avcodec_open2(c, codec, NULL);
    if (ret < 0) {
       cerr << "Could not open codec\n";
       exit(1);
    }

    And I am getting encoded data using avcodec_receive_packet() function. which will return AVPacket.

    And I am passing AVPacket’s data into DeviceSource file below is code snippet of my Live555 code :

    void DeviceSource::deliverFrame() {
       if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet

       u_int8_t* newFrameDataStart = (u_int8_t*) pkt->data;
       unsigned newFrameSize = pkt->size; //%%% TO BE WRITTEN %%%
       // Deliver the data here:
       if (newFrameSize > fMaxSize) { // Condition becomes true many times
           fFrameSize = fMaxSize;
           fNumTruncatedBytes = newFrameSize - fMaxSize;
       } else {
           fFrameSize = newFrameSize;
       }
       gettimeofday(&fPresentationTime, NULL); // If you have a more accurate time - e.g., from an encoder - then use that instead.
       // If the device is *not* a 'live source' (e.g., it comes instead from a file or buffer), then set "fDurationInMicroseconds" here.
       memmove(fTo, newFrameDataStart, fFrameSize);
    }

    But here, sometimes my packet’s size is getting more than fMaxSize value and as per LIVE555 logic it will truncate frame data, so that sometimes I am getting bad frames on my VLC,

    From Live555 forum, I get to know that encoder should not send packet whose size is more than fMaxSize value, so my question is :

    How to restrict encoder to limit size of packet ?

    Thanks in Advance,

    Harshil