Recherche avancée

Médias (1)

Mot : - Tags -/portrait

Autres articles (106)

  • 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

  • Problèmes fréquents

    10 mars 2010, par

    PHP et safe_mode activé
    Une des principales sources de problèmes relève de la configuration de PHP et notamment de l’activation du safe_mode
    La solution consiterait à soit désactiver le safe_mode soit placer le script dans un répertoire accessible par apache pour le site

  • Qu’est ce qu’un éditorial

    21 juin 2013, par

    Ecrivez votre de point de vue dans un article. Celui-ci sera rangé dans une rubrique prévue à cet effet.
    Un éditorial est un article de type texte uniquement. Il a pour objectif de ranger les points de vue dans une rubrique dédiée. Un seul éditorial est placé à la une en page d’accueil. Pour consulter les précédents, consultez la rubrique dédiée.
    Vous pouvez personnaliser le formulaire de création d’un éditorial.
    Formulaire de création d’un éditorial Dans le cas d’un document de type éditorial, les (...)

Sur d’autres sites (13414)

  • FFMpeg gpl (ffmpeg-4.2.1-win64-dev_and_shared) version give different decode result (cmd query vs code)

    31 mai 2021, par Aleksey Timoshchenko

    *all the source img I put on my google drive due to SO restrictions (just click on links provided in the text)

    


    The problem is that for .h264 I use two implementations (cmd query and code) (depends on the tasks) that give me different results and I don't see any reason for this.

    


    Before all I would like to give an explanation, I have .bmp bayer image, then I do debayering and compress it to .h264 (compress .h264) with the script

    


    ffmpeg -y -hide_banner -i orig_bayer.bmp -vf format=gray -f rawvideo pipe: | ffmpeg -hide_banner -y -framerate 30 -f rawvideo -pixel_format bayer_rggb8 -video_size 4096x3000 -i pipe: -c:v hevc_nvenc -qp 0 -pix_fmt yuv444p res.h264


    



    


    Then the first cmd query implementation of decoding (image result)

    


    ffmpeg -y -i res.h264 -vframes 1 -f image2 gpl_script_res.bmp -hide_banner


    



    


    The second implementation is code one and takes more lines (image result here)

    


    Init ffmpeg

    


    bool FFmpegDecoder::InitFFmpeg()
{
    m_pAVPkt = av_packet_alloc();
    m_pAVFrame = av_frame_alloc();
    m_pAVFrameRGB = av_frame_alloc();

    m_pAVFormatCtx = avformat_alloc_context();
    m_pIoCtx->initAVFormatContext(m_pAVFormatCtx);

    if (avformat_open_input(&m_pAVFormatCtx, "", nullptr, nullptr) != 0)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in avformat_open_input\n");
        return false;
    }

    if (avformat_find_stream_info(m_pAVFormatCtx, nullptr) < 0)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in avformat_find_stream_info\n");
        return false;
    }

    //av_dump_format(ctx_format, 0, "", false);
    for (int i = 0; i < (int)m_pAVFormatCtx->nb_streams; i++)
    {
        if (m_pAVFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
        {
            m_streamIdx = i;
            m_pAVStream = m_pAVFormatCtx->streams[i];
            break;
        }
    }
    if (m_pAVStream == nullptr)
    {
        printf("FFmpegDecoder::InitFFmpeg: failed to find video stream\n");
        return false;
    }

    m_pAVCodec = avcodec_find_decoder(m_pAVStream->codecpar->codec_id);
    if (!m_pAVCodec)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_find_decoder\n");
        return false;
    }

    m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec);
    if (!m_pAVCodecCtx)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_alloc_context3\n");
        return false;
    }

    if (avcodec_parameters_to_context(m_pAVCodecCtx, m_pAVStream->codecpar) < 0)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_parameters_to_context\n");
        return false;
    }

    if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, nullptr) < 0)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in avcodec_open2\n");
        return false;
    }

    m_pAVFrameRGB->format = AV_PIX_FMT_BGR24;
    m_pAVFrameRGB->width = m_pAVCodecCtx->width;
    m_pAVFrameRGB->height = m_pAVCodecCtx->height;
    if (av_frame_get_buffer(m_pAVFrameRGB, 32) != 0)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in av_frame_get_buffer\n");
        return false;
    }

    m_streamRotationDegrees = GetAVStreamRotation(m_pAVStream);
    m_estimatedFramesCount = 0;
    assert(m_pAVFormatCtx->nb_streams > 0);
    if (m_pAVFormatCtx->nb_streams > 0)
    {
        m_estimatedFramesCount = m_pAVFormatCtx->streams[0]->nb_frames;
    }

    return InitConvertColorSpace(); 
}

bool FFmpegDecoder::InitConvertColorSpace()
{
    // Init converter from YUV420p to BGR:
    m_pSwsCtxConvertImg = sws_getContext(m_pAVCodecCtx->width, m_pAVCodecCtx->height, m_pAVCodecCtx->pix_fmt, m_pAVCodecCtx->width, m_pAVCodecCtx->height, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL);
    if (!m_pSwsCtxConvertImg)
    {
        printf("FFmpegDecoder::InitFFmpeg: error in sws_getContext\n");
        return false;
    }
    return true;
}


    


    Decoding impl

    


    bool FFmpegDecoder::DecodeContinue(int firstFrameIdx, int maxNumFrames)&#xA;{&#xA;    if (firstFrameIdx == FIRST_FRAME_IDX_BEGINNING)&#xA;    {&#xA;        firstFrameIdx = 0;&#xA;    }&#xA;&#xA;    auto lastReportedFrameIdxTillNow = GetLastReportedFrameIdx();&#xA;&#xA;    if (GetLastDecodedFrameIdx() >= 0 &amp;&amp; firstFrameIdx &lt;= GetLastDecodedFrameIdx())&#xA;    {&#xA;        printf("FFmpegDecoder::DecodeContinue FAILED: firstFrameIdx (%d) already passed decoded (Last decoded idx: %d)\n", firstFrameIdx, GetLastDecodedFrameIdx());&#xA;        return false;&#xA;    }&#xA;&#xA;    bool bRes;&#xA;    int nRet = 0;&#xA;    bool bDecodeShouldEnd = false;&#xA;&#xA;    if (m_pAVPkt != nullptr)&#xA;    {&#xA;        while (nRet >= 0)&#xA;        {&#xA;            m_bCurrentAVPktSentToCodec = false;&#xA;            nRet = av_read_frame(m_pAVFormatCtx, m_pAVPkt);&#xA;            if (nRet &lt; 0)&#xA;            {&#xA;                break;&#xA;            }&#xA;            if (m_pAVPkt->stream_index == m_streamIdx)&#xA;            {&#xA;                bRes = DecodeCurrentAVPkt(firstFrameIdx, maxNumFrames, bDecodeShouldEnd);&#xA;                if (!bRes || m_bRequestedAbort)&#xA;                {&#xA;                    av_packet_unref(m_pAVPkt);&#xA;                    return false;&#xA;                }&#xA;&#xA;                if (bDecodeShouldEnd)&#xA;                {&#xA;                    av_packet_unref(m_pAVPkt);&#xA;                    return true;&#xA;                }&#xA;            }&#xA;&#xA;            av_packet_unref(m_pAVPkt);&#xA;        }&#xA;        m_bCurrentAVPktSentToCodec = false;&#xA;        m_pAVPkt = nullptr;&#xA;    }&#xA;&#xA;    // drain:&#xA;    bRes = DecodeCurrentAVPkt(firstFrameIdx, maxNumFrames, bDecodeShouldEnd);&#xA;    if (!bRes)&#xA;    {&#xA;        return false;&#xA;    }&#xA;&#xA;    if (lastReportedFrameIdxTillNow == GetLastReportedFrameIdx())&#xA;    {&#xA;        printf("FFmpegDecoder::DecodeContinue(firstFrameIdx==%d, maxNumFrames==%d) FAILED: no new frame was decoded\n", firstFrameIdx, maxNumFrames);&#xA;        return false;&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;&#xA;bool FFmpegDecoder::DecodeCurrentAVPkt(int firstFrameIdx, int maxNumFrames, bool &amp; bDecodeShouldEnd)&#xA;{&#xA;    bDecodeShouldEnd = false;&#xA;&#xA;    int ret = 0;&#xA;    if (m_bCurrentAVPktSentToCodec == false)&#xA;    {&#xA;        ret = avcodec_send_packet(m_pAVCodecCtx, m_pAVPkt);&#xA;        m_bCurrentAVPktSentToCodec = true;&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;        {&#xA;            printf("FFmpegDecoder::DecodeFrameImp: error EAGAIN/AVERROR_EOF in avcodec_send_packet\n");&#xA;            return false;&#xA;        }&#xA;        if (ret &lt; 0)&#xA;        {&#xA;            if (ret == AVERROR_INVALIDDATA)&#xA;            {&#xA;                printf("FFmpegDecoder::DecodeFrameImp: error (%d - AVERROR_INVALIDDATA) in avcodec_send_packet\n", ret);&#xA;            }&#xA;            else&#xA;            {&#xA;                printf("FFmpegDecoder::DecodeFrameImp: error (%d) in avcodec_send_packet\n", ret);&#xA;            }&#xA;            return false;&#xA;        }&#xA;    }&#xA;&#xA;    ret = 0;&#xA;    while (ret >= 0)&#xA;    {&#xA;        ret = avcodec_receive_frame(m_pAVCodecCtx, m_pAVFrame);&#xA;        if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;        {&#xA;            break;&#xA;        }&#xA;&#xA;        IncrementLastDecodedFrameIdx();&#xA;        if (GetLastDecodedFrameIdx() &lt; firstFrameIdx)&#xA;        {&#xA;            printf("FFmpegDecoder::DecodeCurrentAVPkt ignoring frame idx %d\n", GetLastDecodedFrameIdx());&#xA;            continue;   // we don&#x27;t need this frame&#xA;        }&#xA;&#xA;        AVFrame * theFrame = m_pAVFrame;    // default&#xA;&#xA;        for (int j = 0; j &lt; m_pAVFrame->nb_side_data; j&#x2B;&#x2B;)&#xA;        {&#xA;            AVFrameSideData *sd = m_pAVFrame->side_data[j];&#xA;            if (sd->type == AV_FRAME_DATA_DISPLAYMATRIX) {&#xA;                auto ddd = av_display_rotation_get((int32_t *)sd->data);&#xA;            }&#xA;        }&#xA;&#xA;        if (m_pSwsCtxConvertImg != nullptr)&#xA;        {&#xA;            {&#xA;                if (sws_scale(m_pSwsCtxConvertImg, theFrame->data, theFrame->linesize, 0, theFrame->height, m_pAVFrameRGB->data, m_pAVFrameRGB->linesize) == 0)&#xA;                {&#xA;                    printf("FFmpegDecoder::DecodeFrameImp: error in sws_scale\n");&#xA;                    return false;&#xA;                }&#xA;            }&#xA;            int numChannels = 3;&#xA;            FFmpegDecoderCallback::EPixelFormat pixFormat = FFmpegDecoderCallback::EPixelFormat::RGB;&#xA;            // Report frame to the client and update last reported frame idx:&#xA;            m_pCB->FFmpegDecoderCallback_HandleFrame(m_reqId, GetLastDecodedFrameIdx(), m_pAVFrameRGB->width, m_pAVFrameRGB->height, m_pAVFrameRGB->linesize[0], pixFormat, numChannels, m_pAVFrameRGB->data[0]);&#xA;            m_lastReportedFrameIdx = GetLastDecodedFrameIdx();  &#xA;        }&#xA;&#xA;        if (maxNumFrames != MAX_NUM_FRAMES_INFINITE &amp;&amp; GetLastDecodedFrameIdx() >= (firstFrameIdx &#x2B; maxNumFrames - 1))&#xA;        {&#xA;            bDecodeShouldEnd = true;&#xA;            return true;&#xA;        }&#xA;    }&#xA;    return true;&#xA;}&#xA;&#xA;/*virtual*/ void FFmpegOneDecoderCtx::FFmpegDecoderCallback_HandleFrame(int reqId, int frameIdx0based, int width, int height, int widthStepBytes, EPixelFormat pixFormat, int numChannels, void * pData) /*override*/&#xA;{&#xA;    // We don&#x27;t have metadata json => return the frame as is:&#xA;    m_pLastFrame->create(height, width, CV_8UC3);&#xA;    *m_pLastFrame = cv::Scalar(0, 0, 0);&#xA;    unsigned char * pSrc = reinterpret_cast<unsigned char="char">(pData);&#xA;    unsigned char *pDst = m_pLastFrame->data;&#xA;    auto dstStride = m_pLastFrame->step[0];&#xA;    for (int y = 0; y &lt; height; &#x2B;&#x2B;y)&#xA;    {&#xA;        memcpy(pDst &#x2B; y * dstStride, pSrc &#x2B; y * widthStepBytes, numChannels*width);&#xA;    }&#xA;}&#xA;</unsigned>

    &#xA;

    And eventually usage looks like this

    &#xA;

        //>>>Get Frame&#xA;    FFmpegMultiDecoder decoder;&#xA;    decoder.HandleRequest_GetFrame(nullptr, filename, 1, image);&#xA;    //&lt;&lt;&lt;&#xA;&#xA;    //>>> Collor conversion from BGR to RGB&#xA;    cv::cvtColor(image, image, cv::COLOR_BGR2RGB);&#xA;    //&lt;&lt;&lt;&#xA;    bool isOk = cv::imwrite(save_location, image);&#xA;

    &#xA;

    The problem is that if you try to open two final decompressed images

    &#xA;

      &#xA;
    1. one with code https://drive.google.com/file/d/1sfTnqvHKQ2DUy0uP8POZXDw2-u3oIRfZ/view?usp=sharing
    2. &#xA;

    3. one with cmd query https://drive.google.com/file/d/1cwsOltk3DVtK86eLeyhiYjNeEXj0msES/view?usp=sharing
    4. &#xA;

    &#xA;

    and try to flip from one image to other you'll see that image I got by cmd query a little bit brighter than that I got by code.

    &#xA;

    What is a possible problem here ?

    &#xA;

    If I missed smth feel free to ask.

    &#xA;

  • Anomalie #4159 : empêcher l’upgrade en 3.1 si le code n’est plus compatible avec la version PHP

    9 février 2021, par b b

    De plus, le loader gère ça très bien maintenant, donc ça me semble bon.

  • cannot resolve variable PIX_FMT_RGB24, ffmpeg source code install with the newest version [duplicate]

    10 août 2016, par NacyL

    This question already has an answer here :

    i installed the ffmpeg from source code according https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu, and write a test file to save ppm file from a video, but the code cannot reslove PIX_FMT_RGB24, i write the code as below :

    int main() {
       // Initalizing these to NULL prevents segfaults!
       AVFormatContext   *pFormatCtx = NULL;
       int               i, videoStream;
       AVCodecContext    *pCodecCtxOrig = NULL;
       AVCodecContext    *pCodecCtx = NULL;
       AVCodec           *pCodec = NULL;
       AVFrame           *pFrame = NULL;
       AVFrame           *pFrameRGB = NULL;
       AVPacket          packet;
       int               frameFinished;
       int               numBytes;
       uint8_t           *buffer = NULL;
       struct SwsContext *sws_ctx = NULL;

       const char* url = "/home/liulijuan/bin/test.mp4";

       // [1] Register all formats and codecs
       av_register_all();

       // [2] Open video file
       if(avformat_open_input(&amp;pFormatCtx, url, NULL, NULL)!=0)
           return -1; // Couldn't open file

       // [3] Retrieve stream information
       if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)
           return -1; // Couldn't find stream information

       // Dump information about file onto standard error
       av_dump_format(pFormatCtx, 0, url, 0);

       // Find the first video stream
       videoStream=-1;
       for(i=0; inb_streams; i++)
           if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
               videoStream=i;
               break;
           }
       if(videoStream==-1)
           return -1; // Didn't find a video stream

       // Get a pointer to the codec context for the video stream
       pCodecCtxOrig=pFormatCtx->streams[videoStream]->codec;
       // Find the decoder for the video stream
       pCodec=avcodec_find_decoder(pCodecCtxOrig->codec_id);
       if(pCodec==NULL) {
           fprintf(stderr, "Unsupported codec!\n");
           return -1; // Codec not found
       }
       // Copy context
       pCodecCtx = avcodec_alloc_context3(pCodec);
       if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {
           fprintf(stderr, "Couldn't copy codec context");
           return -1; // Error copying codec context
       }

       // Open codec
       if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0)
           return -1; // Could not open codec

       // Allocate video frame
       pFrame=av_frame_alloc();

       // Allocate an AVFrame structure
       pFrameRGB=av_frame_alloc();
       if(pFrameRGB==NULL)
           return -1;

       // Determine required buffer size and allocate buffer
       numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
                                   pCodecCtx->height);
       buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));

       // Assign appropriate parts of buffer to image planes in pFrameRGB
       // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
       // of AVPicture
       avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
                      pCodecCtx->width, pCodecCtx->height);

       // initialize SWS context for software scaling
       sws_ctx = sws_getContext(pCodecCtx->width,
                                pCodecCtx->height,
                                pCodecCtx->pix_fmt,
                                pCodecCtx->width,
                                pCodecCtx->height,
                                PIX_FMT_RGB24,
                                SWS_BILINEAR,
                                NULL,
                                NULL,
                                NULL
       );

       // [4] Read frames and save first five frames to disk
       i=0;
       while(av_read_frame(pFormatCtx, &amp;packet)>=0) {
           // Is this a packet from the video stream?
           if(packet.stream_index==videoStream) {
               // Decode video frame
               avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);

               // Did we get a video frame?
               if(frameFinished) {
                   // Convert the image from its native format to RGB
                   sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data,
                             pFrame->linesize, 0, pCodecCtx->height,
                             pFrameRGB->data, pFrameRGB->linesize);

                   // Save the frame to disk
                   if(++i&lt;=5)
                       SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,
                                 i);
               }
           }

           // Free the packet that was allocated by av_read_frame
           av_free_packet(&amp;packet);
       }

       // Free the RGB image
       av_free(buffer);
       av_frame_free(&amp;pFrameRGB);

       // Free the YUV frame
       av_frame_free(&amp;pFrame);

       // Close the codecs
       avcodec_close(pCodecCtx);
       avcodec_close(pCodecCtxOrig);

       // Close the video file
       avformat_close_input(&amp;pFormatCtx);

       return 0;
    }

    so i replace PIX_FMT_RGB24 with AV_PIX_FMT_RGB24, but i cannot open the saved ppm file, the save code as below :

    void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
       FILE *pFile;
       char szFilename[32];
       int  y;

       printf("start save frame ...\n");
       // Open file
       sprintf(szFilename, "/home/liulijuan/frame%d.ppm", iFrame);
       pFile=fopen(szFilename, "wb");
       if(pFile==NULL)
           return;

       printf("start write header ...\n");
       // Write header
       fprintf(pFile, "/P6\n%d %d\n255\n", width, height);

       // Write pixel data
       for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);

       // Close file
       fclose(pFile);
       printf("close file ...\n");
    }

    so, what’s wrong with this code ?