Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Error initializing a QSV frame pool av_hwframe_ctx_init

    28 août 2017, par vominhtien961476

    I'm trying to use h264_qsv for decode AVpacket. My problem is that the qsv_init() fail at the av_hwframe_ctx_init (res = -40). Searching for many similar threads but sill not find a solution for this. I'm working with ffmpeg-3.3.3 and for sure it supports h264_qsv (by checking with cmd command). Below is my piece of code:

            AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
            if (!pCodec){
                return RS_NOT_OK;
            }
            AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec);
            if (!pCodecCtx){
                return RS_NOT_OK;
            }
            InputStream* ist = new InputStream();
            ist->hwaccel_id = HWACCEL_QSV;
            ist->hwaccel_device = "qsv";
            ist->dec = pCodec;
            ist->dec_ctx = pCodecCtx;
            ist->active_hwaccel_id = HWACCEL_QSV;
            ist->hwaccel_pix_fmt = AV_PIX_FMT_QSV;
            pCodecCtx->coded_width = 1280;// _width;
            pCodecCtx->coded_height = 720;// _height;
            pCodecCtx->opaque = ist;
            pCodecCtx->sw_pix_fmt = AV_PIX_FMT_QSV;
            if (qsv_init(pCodecCtx) < 0)
            {
                sprintf(strErr, "Error in function qsv_init()");
                commonGlobal->WriteRuntimeLogs(strErr);
                return RS_NOT_OK;
            }
            pCodecCtx->get_buffer2 = ist->hwaccel_get_buffer;
            pCodecCtx->get_format = get_format;
            pCodecCtx->thread_safe_callbacks = 1;
    

    The using qsv_init code:

    int qsv_init(AVCodecContext *s)
    {
        InputStream *ist = (InputStream *)s->opaque;
        AVHWFramesContext *frames_ctx;
        AVQSVFramesContext *frames_hwctx;
        int ret;
    
        if (!hw_device_ctx) {
            ret = qsv_device_init(ist);
            if (ret < 0)
                return ret;
        }
    
        av_buffer_unref(&ist->hw_frames_ctx);
        ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);
        if (!ist->hw_frames_ctx)
            return AVERROR(ENOMEM);
    
        frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data;
        frames_hwctx = (AVQSVFramesContext *)frames_ctx->hwctx;
    
        frames_ctx->width = FFALIGN(s->coded_width, 32);
        frames_ctx->height = FFALIGN(s->coded_height, 32);
        frames_ctx->format = AV_PIX_FMT_QSV;
        frames_ctx->sw_format = s->sw_pix_fmt;
        frames_ctx->initial_pool_size = 64;
        frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
    
        ret = av_hwframe_ctx_init(ist->hw_frames_ctx);
        if (ret < 0) {
            av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n");
            return ret;
        }
    
        ist->hwaccel_get_buffer = qsv_get_buffer;
        ist->hwaccel_uninit = qsv_uninit;
    
        return 0;
    }           
    
  • ffmpeg How to reduce the processing speed of ffmpeg

    28 août 2017, par rinofcan

    I have a video with fps=30, But when I run the command, I see the following:

    frame=32  fps=62  q=-1.0  Lsize=N/A  time=00:00:01.27  bitrate=N/A
    

    That's the processing speed i.e. 62 frames processed per second.

    But I want to reduce it to fps = 40 or fps = 50.

    What I have to do

  • The conversion between FFmpeg's avframe and OpenCV's mat ?

    28 août 2017, par md612

    I made the conversion between FFmpeg's avframe and OpenCV's mat. But the following code doesn't convert the avframe to mat and mat to avframe correctly. The first part converts avframe to mat format and the second part converts mat to avframe format.

    Here is my source code:

    AVFrame* ProcessFrame(AVFrame *frame, int stream_index)
    {
     //first part
        AVStream *in_stream = ifmt_ctx->streams[stream_index];
        AVCodecContext *pCodecCtx = in_stream->codec;
    
        AVFrame  *pFrameRGB = NULL;
    
        struct SwsContext * img_convert_ctx = NULL;
        if(img_convert_ctx == NULL){
            img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
                                             pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
                                             AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
        }
        pFrameRGB = av_frame_alloc();
        int size = avpicture_get_size(AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height);
    
        uint8_t  *out_bufferRGB = (uint8_t *)av_malloc(size);
    
        avpicture_fill((AVPicture *)pFrameRGB, out_bufferRGB, AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height);
    
        sws_scale(img_convert_ctx, frame->data, frame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
    
        Mat imageFrame = Mat(pCodecCtx->height, pCodecCtx->width, CV_8UC3);
    
        memcpy(imageFrame.data, out_bufferRGB, size);
        delete[] out_bufferRGB;
    
       ///////////////////////////////////////////////////////////
       //second part starts
    
        avpicture_fill((AVPicture *)pFrameRGB, imageFrame.data,AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height);
    
        struct SwsContext * convert_ctx = NULL;
        if(convert_ctx == NULL){
            convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
                                             AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height,
                                             pCodecCtx->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);
        }
    
        AVFrame *srcFrame = av_frame_alloc();
        size = avpicture_get_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
    
        uint8_t  *out_buffer = (uint8_t *)av_malloc(size);
    
        avpicture_fill((AVPicture *)srcFrame, out_buffer, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
    
        sws_scale(convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, srcFrame->data, srcFrame->linesize);
    
        delete[] out_buffer;
        av_free(pFrameRGB);
    
        srcFrame->width = frame->width;
        srcFrame->height = frame->height;
        srcFrame->format = frame->format;
    
        av_frame_copy_props(srcFrame, frame);
    
        return srcFrame;
    }
    
  • how to convert h264 to flv with ffmpeg(using code not bin) [on hold]

    28 août 2017, par Alan Xie

    I want to convert h264 to flv with ffmpeg. I copied the file from FFmepg remuxing example,and try to convert h264 to flv with it.It runs with no exception,but the output seems error.It just keep staying in the first frame.How to solve this problem?

  • Bento4 MP4Dash fails with audio ?

    27 août 2017, par CMOS

    I am running Bento4 Mp4Dash to convert my fragmented video files into MPEG-DASH streaming videos. However I seem to get this error

    ERROR: unsupported input file, more than one "traf" box in fragment

    but only if I have audio enabled. I have found that if I run -an in FFMPEG (to ignore the audio tracks) my MP4Dash command runs just fine, any ideas as to why this would happen?