Changeset 4765 for libpipi


Ignore:
Timestamp:
Feb 8, 2011, 11:09:53 PM (10 years ago)
Author:
Sam Hocevar
Message:

Allow to choose between RGB and YUV in pipi_open_sequence().

Location:
libpipi/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/examples/makemovie.c

    r4694 r4765  
    5959        bitrate = atoi(argv[7]);
    6060
    61     seq = pipi_open_sequence(argv[1], width, height, fps,
     61    seq = pipi_open_sequence(argv[1], width, height, 0 /* YUV */, fps,
    6262                             par_num, par_den, bitrate);
    6363    if(!seq)
  • libpipi/trunk/pipi/pipi.h

    r4697 r4765  
    242242
    243243__extern pipi_sequence_t *pipi_open_sequence(char const *, int, int, int,
    244                                              int, int, int);
     244                                             int, int, int, int);
    245245__extern int pipi_feed_sequence(pipi_sequence_t *, uint8_t const *, int, int);
    246246__extern int pipi_close_sequence(pipi_sequence_t *);
  • libpipi/trunk/pipi/sequence.c

    r4704 r4765  
    5050
    5151    struct SwsContext *sws_ctx;
    52     int src_width, src_height;
     52    int src_width, src_height, src_fmt;
    5353}
    5454ffmpeg_codec_t;
     
    5656
    5757pipi_sequence_t *pipi_open_sequence(char const *file,
    58                                     int width, int height, int fps,
     58                                    int width, int height, int rgb, int fps,
    5959                                    int par_num, int par_den, int bitrate)
    6060{
     
    183183    ff->buf = (uint8_t *)av_malloc(ff->buf_len);
    184184
     185    ff->src_fmt = rgb ? PIX_FMT_RGB32 : PIX_FMT_YUV444P;
     186
    185187    av_write_header(ff->fmt_ctx);
    186188
     
    220222    if (!ff->sws_ctx)
    221223    {
    222         ff->sws_ctx = sws_getContext(width, height, PIX_FMT_YUV444P,
     224        ff->sws_ctx = sws_getContext(width, height, ff->src_fmt,
    223225                                     ff->cod_ctx->width,
    224226                                     ff->cod_ctx->height,
     
    235237
    236238    /* Convert interleaved YUV to planar YUV */
    237     if (!seq->convert_buf)
    238         seq->convert_buf = malloc(width * height * 3);
    239 
    240     for (n = 0; n < width * height; n++)
    241     {
    242         seq->convert_buf[n] = buffer[4 * n];
    243         seq->convert_buf[n + width * height] = buffer[4 * n + 1];
    244         seq->convert_buf[n + 2 * width * height] = buffer[4 * n + 2];
    245     }
    246 
    247     /* Feed the buffers to FFmpeg */
    248     buflist[0] = seq->convert_buf;
    249     buflist[1] = seq->convert_buf + 2 * width * height;
    250     buflist[2] = seq->convert_buf + width * height;
    251     pitchlist[0] = pitchlist[1] = pitchlist[2] = width;
     239    if (ff->src_fmt == PIX_FMT_YUV444P)
     240    {
     241        if (!seq->convert_buf)
     242            seq->convert_buf = malloc(width * height * 3);
     243
     244        for (n = 0; n < width * height; n++)
     245        {
     246            seq->convert_buf[n] = buffer[4 * n];
     247            seq->convert_buf[n + width * height] = buffer[4 * n + 1];
     248            seq->convert_buf[n + 2 * width * height] = buffer[4 * n + 2];
     249        }
     250
     251        /* Feed the buffers to FFmpeg */
     252        buflist[0] = seq->convert_buf;
     253        buflist[1] = seq->convert_buf + 2 * width * height;
     254        buflist[2] = seq->convert_buf + width * height;
     255        pitchlist[0] = pitchlist[1] = pitchlist[2] = width;
     256    }
     257    else
     258    {
     259        buflist[0] = buffer;
     260        pitchlist[0] = 4 * width;
     261    }
     262
    252263    sws_scale(ff->sws_ctx, buflist, pitchlist, 0, height,
    253264              ff->frame->data, ff->frame->linesize);
     
    280291    ffmpeg_codec_t *ff = (ffmpeg_codec_t *)seq->codec_priv;
    281292
    282     if (ff->fmt_ctx)
     293    /* Finish the sequence */
     294    if (ff->buf)
    283295    {
    284296        av_write_trailer(ff->fmt_ctx);
    285297    }
    286298
     299    /* Close everything */
    287300    if (ff->buf)
    288301    {
     
    312325        ff->stream = NULL;
    313326
    314         if (!(ff->fmt_ctx->flags & AVFMT_NOFILE))
     327        if (!(ff->fmt_ctx->flags & AVFMT_NOFILE) && ff->fmt_ctx->pb)
    315328            url_fclose(ff->fmt_ctx->pb);
    316329
Note: See TracChangeset for help on using the changeset viewer.