problems while encoding with ffvhuff codec

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

problems while encoding with ffvhuff codec

Vincent Torri

Hey,

I want to write a tool that encode the content of a window (like xvidcap,
but crossplatform). I want to encode in lossless, using the ffvhuff codec.

First, I was told that there is no problem for such encoded data to be in
an avi. So, basically, I do the following:

1) I create a format with guess_format ("avi", NULL, NULL);
2) I create an AVFormatContext and an AVStream
3) I get the AVCodecContext from the AVStream (I name it c)
4) I set c->codec_id to CODEC_ID_FFVHUFF and c->codec_type to CODEC_TYPE_VIDEO
5) I set the parameters of the codec

The complete code is there (see enthrall_ffmpeg_init() function):

http://www.maths.univ-evry.fr/pages_perso/vtorri/files/ffmpeg.c

Now, when I encode, I get the following output errors:

Output #0, avi, to 'toto.avi':
     Stream #0.0: Video: ffvhuff, yuv420p, 150x100, q=2-31, 150 kb/s, 25.00
tb(c)
size : 150 100
Starting recording...
[ffvhuff @ 0x62a0a0]error, non monotone timestamps -368934881474191031 >= -368934881474191031
Error while writing video frame
[ffvhuff @ 0x62a0a0]error, non monotone timestamps -368934881474191031 >= -368934881474191031
Error while writing video frame

etc...

Does someone see the problem ?

I don't know if it's useful, but I'm on linux (ubuntu) 64 bits and i
compiled ffmpeg from svn 1 hour ago.

thank you

Vincent Torri
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: problems while encoding with ffvhuff codec

Luca Abeni
Vincent Torri wrote:
[...]

> http://www.maths.univ-evry.fr/pages_perso/vtorri/files/ffmpeg.c
>
> Now, when I encode, I get the following output errors:
>
> Output #0, avi, to 'toto.avi':
>      Stream #0.0: Video: ffvhuff, yuv420p, 150x100, q=2-31, 150 kb/s, 25.00
> tb(c)
> size : 150 100
> Starting recording...
> [ffvhuff @ 0x62a0a0]error, non monotone timestamps -368934881474191031 >= -368934881474191031
> Error while writing video frame
> [ffvhuff @ 0x62a0a0]error, non monotone timestamps -368934881474191031 >= -368934881474191031
> Error while writing video frame
>
> etc...
>
> Does someone see the problem ?

Judging from the error message, you are probably passing wrong timestamp
values to av_write_frame().

Try protecting
     pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, ef->video_st->time_base);
with an
     if (c->coded_frame->pts != AV_NOPTS_VALUE)
in your code.


                                Luca
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: problems while encoding with ffvhuff codec

Vincent Torri


On Tue, 22 Jul 2008, Luca Abeni wrote:

> Vincent Torri wrote:
> [...]
>> http://www.maths.univ-evry.fr/pages_perso/vtorri/files/ffmpeg.c
>>
>> Now, when I encode, I get the following output errors:
>>
>> Output #0, avi, to 'toto.avi':
>>      Stream #0.0: Video: ffvhuff, yuv420p, 150x100, q=2-31, 150 kb/s, 25.00
>> tb(c)
>> size : 150 100
>> Starting recording...
>> [ffvhuff @ 0x62a0a0]error, non monotone timestamps -368934881474191031 >= -368934881474191031
>> Error while writing video frame
>> [ffvhuff @ 0x62a0a0]error, non monotone timestamps -368934881474191031 >= -368934881474191031
>> Error while writing video frame
>>
>> etc...
>>
>> Does someone see the problem ?
>
> Judging from the error message, you are probably passing wrong timestamp
> values to av_write_frame().
>
> Try protecting
>     pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, ef->video_st->time_base);
> with an
>     if (c->coded_frame->pts != AV_NOPTS_VALUE)
> in your code.

haa, it seems to work very well ! Thank you very much !

Vincent Torri
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: problems while encoding with ffvhuff codec

Vincent Torri
In reply to this post by Luca Abeni


On Tue, 22 Jul 2008, Luca Abeni wrote:

> Try protecting
>     pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, ef->video_st->time_base);
> with an
>     if (c->coded_frame->pts != AV_NOPTS_VALUE)
> in your code.

Btw, i took that code from output_example.c which is in the top level dir
of ffmpeg. There is no shuch guard before av_rescale_q(). Maybe someone
should add it

Vincent
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: problems while encoding with ffvhuff codec

Luca Abeni
Vincent Torri wrote:

>
> On Tue, 22 Jul 2008, Luca Abeni wrote:
>
>> Try protecting
>>     pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, ef->video_st->time_base);
>> with an
>>     if (c->coded_frame->pts != AV_NOPTS_VALUE)
>> in your code.
>
> Btw, i took that code from output_example.c which is in the top level dir
> of ffmpeg. There is no shuch guard before av_rescale_q(). Maybe someone
> should add it

Yes; output_example.c looks wrong; thanks for noticing. I'll submit a fix.


                        Thanks,
                                Luca
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

av_open_input_file keeps failing

Jarek M
Hello. I've wrote a simple test program to decode an mp3 file; test program is based on a
tutorial by dranger. I've tried two different ffmpeg APIs - ffmpeg-r13712-lstatic-win32
and a svn checkout, compiled using msys/mingw AND Visual C++ 2008.

In all cases, the function av_open_input_file keeps returning -2
and the program exits.

Any hints how to resolve this matter?

I'm working on a simple audio player and thought about using ffmpeg
as a decoder. Source code below. Code is pretty simple, the program must be passed a
filename (including path) of the mp3 file to decode.

Kind Regards
Jaerek


#include <stdio.h>
#include <stdlib.h>
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

//#include <ffmpeg/cmdutils.h>
}

void
audio_decode(const char *outfilename, const char *filename);


//----------------
//#define INBUF_SIZE 216000
#define INBUF_SIZE 4096
static const int BUFFER_SIZE = AVCODEC_MAX_AUDIO_FRAME_SIZE * 15;

int audio_decode_frame(AVCodecContext *aCodecCtx, AVPacket & pkt, uint8_t *audio_buf, int buf_size);
void audio_decode(const char *outfilename, const char *infilename);


void
audio_decode(const char *outfilename, const char *infilename)
{


    AVCodecContext *_avCodecCtxPtr= NULL;
        AVFormatContext* _avFormatCtxPtr = NULL;

        AVPacket _avPacket;
        AVCodec *_avCodecPtr = NULL;
        AVFrame *_avFramePtr = NULL;


        FILE *outfile=NULL;

    int out_size, outbuf_size;
    unsigned int _audioStreamIdx;
        uint8_t *samples;
    int retValue = 0;

// The New Order- JM
        samples = new uint8_t[BUFFER_SIZE];
        outbuf_size = BUFFER_SIZE;

        retValue = av_open_input_file(&_avFormatCtxPtr, infilename, NULL, 0, NULL);
         if ( retValue != 0)
         {
                fprintf(stderr, "could not open %s\t - av_open_input_file() return code: %i\n", infilename, retValue);
                 //print_error(infilename, retValue);
        exit(1);
        }
       
        dump_format(_avFormatCtxPtr, 0, infilename, 0);


   for (_audioStreamIdx = 0; _audioStreamIdx < _avFormatCtxPtr->nb_streams; _audioStreamIdx++)
        {
                _avCodecCtxPtr = _avFormatCtxPtr->streams[_audioStreamIdx]->codec;
                if (_avCodecCtxPtr->codec_type == CODEC_TYPE_AUDIO)
                        break;
        }

   if (NULL == _avCodecCtxPtr ){
        fprintf(stderr, "no CodecCtx found\n");
        exit(1);
   }

   _avCodecPtr = avcodec_find_decoder(_avCodecCtxPtr->codec_id);
   if (NULL == _avCodecPtr ){
        fprintf(stderr, "unsuppoerted codec!!!!\n");
        exit(1);
   }

   retValue = avcodec_open(_avCodecCtxPtr, _avCodecPtr);
        if ( retValue < 0) {
        fprintf(stderr, "could not open codec\n");
        exit(1);
    }

        _avFramePtr = avcodec_alloc_frame();
   if (NULL == _avFramePtr ){
        fprintf(stderr, "no frame allocated\n");
        exit(1);
   }
        outfile = fopen(outfilename, "wab");
     if (!outfile) {
         av_freep(_avCodecCtxPtr);
                 exit(1);
     }

   while(av_read_frame(_avFormatCtxPtr, &_avPacket) >= 0) {

        out_size = audio_decode_frame(_avCodecCtxPtr, _avPacket, samples, outbuf_size);
        if( -1 == out_size )
        {
                exit(1);
        }

        if (out_size > 0) {
                 // if a frame has been decoded, output it
         fwrite(samples, 1, out_size, outfile);
     }

   }

   
        // End New Order

    fclose(outfile);
    free(samples);

    avcodec_close(_avCodecCtxPtr);
    av_free(_avCodecCtxPtr);
        av_free(_avFramePtr);
        av_close_input_file(_avFormatCtxPtr);
}


int audio_decode_frame(AVCodecContext *aCodecCtx, AVPacket & pkt, uint8_t *audio_buf,
                       int buf_size) {

  //static AVPacket pkt;
  static uint8_t *audio_pkt_data = NULL;
  static int audio_pkt_size = 0;

  int len1, data_size;

  for(;;) {
    while(audio_pkt_size > 0) {
      data_size = buf_size;
      len1 = avcodec_decode_audio2(aCodecCtx, (int16_t *)audio_buf, &data_size,
                                  audio_pkt_data, audio_pkt_size);
      if(len1 < 0) {
        /* if error, skip frame */
        audio_pkt_size = 0;
        break;
      }
      audio_pkt_data += len1;
      audio_pkt_size -= len1;
      if(data_size <= 0) {
        /* No data yet, get more frames */
        continue;
      }
      /* We have data, return it and come back for more later */
      return data_size;
    } /* end while */
  //  if(pkt.data)
  //    av_free_packet(&pkt);

        /*
        if(quit) {
      return -1;
    }

    if(packet_queue_get(&audioq, &pkt, 1) < 0) {
      return -1;
    }
        */
    audio_pkt_data = pkt.data;
    audio_pkt_size = pkt.size;
  }/* end for */
}

int main(int argc, char *argv[])
{
  avcodec_init();
        avcodec_register_all();    
        if(NULL == argv[1]){
                fprintf(stderr,"no file to decode\n");
                exit(1);
        }
        audio_decode("output.pcm",argv[1]);
        return 0;

}
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: av_open_input_file keeps failing

avcoder
Please use av_register_all() instead of avcodec_register_all()

On Sun, Jul 27, 2008 at 11:36 PM, Jarek M <[hidden email]> wrote:

> Hello. I've wrote a simple test program to decode an mp3 file; test program
> is based on a
> tutorial by dranger. I've tried two different ffmpeg APIs -
> ffmpeg-r13712-lstatic-win32
> and a svn checkout, compiled using msys/mingw AND Visual C++ 2008.
>
> In all cases, the function av_open_input_file keeps returning -2
> and the program exits.
>
> Any hints how to resolve this matter?
>
> I'm working on a simple audio player and thought about using ffmpeg
> as a decoder. Source code below. Code is pretty simple, the program must be
> passed a
> filename (including path) of the mp3 file to decode.
>
> Kind Regards
> Jaerek
>
>
> #include <stdio.h>
> #include <stdlib.h>
> extern "C"
> {
> #include <libavcodec/avcodec.h>
> #include <libavformat/avformat.h>
>
> //#include <ffmpeg/cmdutils.h>
> }
>
> void
> audio_decode(const char *outfilename, const char *filename);
>
>
> //----------------
> //#define INBUF_SIZE 216000
> #define INBUF_SIZE 4096
> static const int BUFFER_SIZE = AVCODEC_MAX_AUDIO_FRAME_SIZE * 15;
>
> int audio_decode_frame(AVCodecContext *aCodecCtx, AVPacket & pkt, uint8_t
> *audio_buf, int buf_size);
> void audio_decode(const char *outfilename, const char *infilename);
>
>
> void
> audio_decode(const char *outfilename, const char *infilename)
> {
>
>
>    AVCodecContext *_avCodecCtxPtr= NULL;
>        AVFormatContext* _avFormatCtxPtr = NULL;
>
>        AVPacket _avPacket;
>        AVCodec *_avCodecPtr = NULL;
>        AVFrame *_avFramePtr = NULL;
>
>
>        FILE *outfile=NULL;
>
>    int out_size, outbuf_size;
>    unsigned int _audioStreamIdx;
>        uint8_t *samples;
>    int retValue = 0;
>
> // The New Order- JM
>        samples = new uint8_t[BUFFER_SIZE];
>        outbuf_size = BUFFER_SIZE;
>
>        retValue = av_open_input_file(&_avFormatCtxPtr, infilename, NULL, 0,
> NULL);
>         if ( retValue != 0)
>         {
>                fprintf(stderr, "could not open %s\t - av_open_input_file()
> return code: %i\n", infilename, retValue);
>                 //print_error(infilename, retValue);
>        exit(1);
>        }
>
>        dump_format(_avFormatCtxPtr, 0, infilename, 0);
>
>
>   for (_audioStreamIdx = 0; _audioStreamIdx < _avFormatCtxPtr->nb_streams;
> _audioStreamIdx++)
>        {
>                _avCodecCtxPtr =
> _avFormatCtxPtr->streams[_audioStreamIdx]->codec;
>                if (_avCodecCtxPtr->codec_type == CODEC_TYPE_AUDIO)
>                        break;
>        }
>
>   if (NULL == _avCodecCtxPtr ){
>        fprintf(stderr, "no CodecCtx found\n");
>        exit(1);
>   }
>
>   _avCodecPtr = avcodec_find_decoder(_avCodecCtxPtr->codec_id);
>   if (NULL == _avCodecPtr ){
>        fprintf(stderr, "unsuppoerted codec!!!!\n");
>        exit(1);
>   }
>
>   retValue = avcodec_open(_avCodecCtxPtr, _avCodecPtr);
>        if ( retValue < 0) {
>        fprintf(stderr, "could not open codec\n");
>        exit(1);
>    }
>
>        _avFramePtr = avcodec_alloc_frame();
>   if (NULL == _avFramePtr ){
>        fprintf(stderr, "no frame allocated\n");
>        exit(1);
>   }
>        outfile = fopen(outfilename, "wab");
>     if (!outfile) {
>         av_freep(_avCodecCtxPtr);
>                 exit(1);
>     }
>
>   while(av_read_frame(_avFormatCtxPtr, &_avPacket) >= 0) {
>
>        out_size = audio_decode_frame(_avCodecCtxPtr, _avPacket, samples,
> outbuf_size);
>        if( -1 == out_size )
>        {
>                exit(1);
>        }
>
>        if (out_size > 0) {
>                 // if a frame has been decoded, output it
>         fwrite(samples, 1, out_size, outfile);
>     }
>
>   }
>
>
>        // End New Order
>
>    fclose(outfile);
>    free(samples);
>
>    avcodec_close(_avCodecCtxPtr);
>    av_free(_avCodecCtxPtr);
>        av_free(_avFramePtr);
>        av_close_input_file(_avFormatCtxPtr);
> }
>
>
> int audio_decode_frame(AVCodecContext *aCodecCtx, AVPacket & pkt, uint8_t
> *audio_buf,
>                       int buf_size) {
>
>  //static AVPacket pkt;
>  static uint8_t *audio_pkt_data = NULL;
>  static int audio_pkt_size = 0;
>
>  int len1, data_size;
>
>  for(;;) {
>    while(audio_pkt_size > 0) {
>      data_size = buf_size;
>      len1 = avcodec_decode_audio2(aCodecCtx, (int16_t *)audio_buf,
> &data_size,
>                                  audio_pkt_data, audio_pkt_size);
>      if(len1 < 0) {
>        /* if error, skip frame */
>        audio_pkt_size = 0;
>        break;
>      }
>      audio_pkt_data += len1;
>      audio_pkt_size -= len1;
>      if(data_size <= 0) {
>        /* No data yet, get more frames */
>        continue;
>      }
>      /* We have data, return it and come back for more later */
>      return data_size;
>    } /* end while */
>  //  if(pkt.data)
>  //    av_free_packet(&pkt);
>
>        /*
>        if(quit) {
>      return -1;
>    }
>
>    if(packet_queue_get(&audioq, &pkt, 1) < 0) {
>      return -1;
>    }
>        */
>    audio_pkt_data = pkt.data;
>    audio_pkt_size = pkt.size;
>  }/* end for */
> }
>
> int main(int argc, char *argv[])
> {
>        avcodec_init();
>        avcodec_register_all();
>        if(NULL == argv[1]){
>                fprintf(stderr,"no file to decode\n");
>                exit(1);
>        }
>        audio_decode("output.pcm",argv[1]);
>        return 0;
>
> }
>
>
_______________________________________________
libav-user mailing list
[hidden email]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user