[Libav-user] Documentation

George Sharara george.sharara at ttx.co.uk
Wed Jul 27 11:24:47 CEST 2011


I'm assuming that the problem might be in my code now, because after a painstaking day and a half I finally managed to get everything compiling on my system
I replaced the zeranoe builds with my own and I'm still getting the same problem av_get_pix_fmt_name entry point cannot be found in avutil-51.dll.
I have included my code below and would be grateful if you pointed out what I am doing wrong.

Regards

George

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>

using namespace std;

#include <windows.h>
#include <stdio.h>
#include <string.h>

extern "C" {
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}

void saveFrame (AVFrame *p, int width, int height, int iFrame)
{
    int y = 0;
    string filename = "myfile.ppm";
    FILE *pFile = fopen(filename.c_str(), "w+");

    if (pFile == NULL)
    {
        message("saveData::could not open file");
        handle_error();
    }

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

    for(y=0; y < height; y++)
    {
        fwrite(p->data[0] + y * p->linesize[0], 1, width*3, pFile);
    }
    fclose(pFile);
}


int main(int argc, char** argv)
{
    AVFormatContext *pFormatCtx;
    AVFrame *pFrame;
    int videoStream = -1;
    string filename = NULL;

    av_register_all();
    message("av_register_all -> Initialised");

    if (argc >= 2)
    {
        filename = argv[1];
    }
    else
    {
        message("warning: Filename not specified!");
        filename = "C:\\Users\\george\\Videos\\the.lincoln.lawyer.cd1.avi";
    }


    if (av_open_input_file(&pFormatCtx, filename.c_str(), NULL, 0, NULL) != 0)
    {
        message("could not open the file");
        handle_error();
    }

    // Retrieve stream information
    if(av_find_stream_info(pFormatCtx)<0)
    {
        message("Couldn't find stream information");
        handle_error();
    }


    // Dump information about file onto standard error
    dump_format(pFormatCtx, 0, argv[1], 0);

    uint_fast32_t i;
    AVCodecContext *pCodecCtx;

    // Find the first video stream
    videoStream=-1;
    for(i=0; i<pFormatCtx->nb_streams; i++)
    {
        if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
        {
            videoStream=i;
            break;
        }
    }

    if(videoStream==-1)
    {
        message("No video stream found");
        handle_error(); // Didn't find a video stream
    }

    // Get a pointer to the codec context for the video stream
    pFrame = avcodec_alloc_frame();
    pCodecCtx=pFormatCtx->streams[videoStream]->codec;


    AVCodec *pCodec;

    // Find the decoder for the video stream
    pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
    if(pCodec==NULL)
    {
        fprintf(stderr, "Unsupported codec!\n");
        handle_error(); // Codec not found
    }

    // Open codec
    if(avcodec_open(pCodecCtx, pCodec)<0)
        handle_error(); // Could not open codec


    AVFrame *pFrameRGB;

    // Allocate an AVFrame structure
    pFrameRGB = avcodec_alloc_frame();
    if(pFrameRGB==NULL)
        handle_error();

    uint8_t *buffer;
    int numBytes;
    // 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);

    int frameFinished;
    AVPacket packet;

    i=0;
    while(av_read_frame(pFormatCtx, &packet)>=0)
    {
        // Is this a packet from the video stream?
        if(packet.stream_index==videoStream)
        {
            // Decode video frame
            avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);

            // Did we get a video frame?
            if(frameFinished)
            {
                // Convert the image from its native format to RGB
                if (img_convert_ctx == NULL)
                {
                    img_convert_ctx = sws_getCachedContext(img_convert_ctx, pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
                                                           pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC,
                                                           NULL, NULL, NULL);

                    if (img_convert_ctx == NULL)
                    {
                        message("Could no create Software Scale Context");
                        handle_error();
                    }
                }

                sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
                // Save the frame to disk
                if(++i<=5)
                    saveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);
            }
        }

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


    //finito
    return 0;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

-----Original Message-----
From: libav-user-bounces at ffmpeg.org [mailto:libav-user-bounces at ffmpeg.org] On Behalf Of Matthew Einhorn
Sent: 26 July 2011 20:55
To: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
Subject: Re: [Libav-user] Documentation

FYI, you're more likely to get help from the zeranoe user forum on his website because this problem isn't likely ffmpeg related but related to the dll that zeranoe builds or your use thereof.

Note, I'm using the same dlls with the same git number and I can call the av_get_pix_fmt_name function without any issues. Also, you should include your example code, otherwise it's hard to know what's going wrong.

Matt

On Tue, Jul 26, 2011 at 7:49 AM, George Sharara <george.sharara at ttx.co.uk> wrote:
> Hi
>
>
>
> As far as open source projects go, I have to say FFMPEG is in the 
> running for the worst documented project I have ever come across. For 
> a project as large and complicated as it is, one would expect a good 
> level of developer documentation.
>
> Merely listing method signatures does not serve as documentation.
> Furthermore, you don't even have a sample code on your OWN site. I 
> have had to hop from site to site looking for sample code, and where I 
> have found it, in never compiles (WHY? Because none of it is up to 
> date). It seems many methods have been deprecated recently but no 
> information exists on how to implement the new functions.
>
>
>
> PROBLEM: I have written a simple program which just opens a file and 
> grabs a frame and saves it to file.  I downloaded the latest builds 
> from Zeranoe.com
>
> ffmpeg-git-9c2651a-win32-dev,  ffmpeg-git-9c2651a-win32-shared. I've 
> linked the appropriate libraries, but I get the message:
>
>
>
> The procedure entry point av_get_pix_fmt_name could not be located in 
> the dll avutil-51.dll
>
>
>
> My code does not explicitly call the function at all.
>
> <libavutil/avutil.h>, <libavcodec/avcodec.h>, 
> <libavformat/avformat.h>, <libswscale/swscale.h>,
>
> I am using these header and the corresponding lib files.
>
>
>
> Windows 7
>
> MinGW 4.5.2
>
>
>
> Disgruntled
>
>
>
> George Sharara
>
>
>
>
>
> This message has been scanned for malware by Websense. 
> www.websense.com
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


More information about the Libav-user mailing list