浏览代码

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

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@4765 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 14 年前
父节点
当前提交
027ac83862
共有 3 个文件被更改,包括 31 次插入18 次删除
  1. +1
    -1
      examples/makemovie.c
  2. +1
    -1
      pipi/pipi.h
  3. +29
    -16
      pipi/sequence.c

+ 1
- 1
examples/makemovie.c 查看文件

@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
if (argc > 7)
bitrate = atoi(argv[7]);

seq = pipi_open_sequence(argv[1], width, height, fps,
seq = pipi_open_sequence(argv[1], width, height, 0 /* YUV */, fps,
par_num, par_den, bitrate);
if(!seq)
return EXIT_FAILURE;


+ 1
- 1
pipi/pipi.h 查看文件

@@ -241,7 +241,7 @@ __extern int pipi_free_histogram(pipi_histogram_t*);
__extern int pipi_render_histogram(pipi_image_t *, pipi_histogram_t*, int);

__extern pipi_sequence_t *pipi_open_sequence(char const *, int, int, int,
int, int, int);
int, int, int, int);
__extern int pipi_feed_sequence(pipi_sequence_t *, uint8_t const *, int, int);
__extern int pipi_close_sequence(pipi_sequence_t *);



+ 29
- 16
pipi/sequence.c 查看文件

@@ -49,13 +49,13 @@ typedef struct
AVFrame *frame;

struct SwsContext *sws_ctx;
int src_width, src_height;
int src_width, src_height, src_fmt;
}
ffmpeg_codec_t;
#endif

pipi_sequence_t *pipi_open_sequence(char const *file,
int width, int height, int fps,
int width, int height, int rgb, int fps,
int par_num, int par_den, int bitrate)
{
#if defined USE_FFMPEG
@@ -182,6 +182,8 @@ pipi_sequence_t *pipi_open_sequence(char const *file,
ff->buf_len = 64 * 1024 * 1024;
ff->buf = (uint8_t *)av_malloc(ff->buf_len);

ff->src_fmt = rgb ? PIX_FMT_RGB32 : PIX_FMT_YUV444P;

av_write_header(ff->fmt_ctx);

return seq;
@@ -219,7 +221,7 @@ int pipi_feed_sequence(pipi_sequence_t *seq, uint8_t const *buffer,

if (!ff->sws_ctx)
{
ff->sws_ctx = sws_getContext(width, height, PIX_FMT_YUV444P,
ff->sws_ctx = sws_getContext(width, height, ff->src_fmt,
ff->cod_ctx->width,
ff->cod_ctx->height,
ff->cod_ctx->pix_fmt, SWS_BICUBIC,
@@ -234,21 +236,30 @@ int pipi_feed_sequence(pipi_sequence_t *seq, uint8_t const *buffer,
return -1;

/* Convert interleaved YUV to planar YUV */
if (!seq->convert_buf)
seq->convert_buf = malloc(width * height * 3);
if (ff->src_fmt == PIX_FMT_YUV444P)
{
if (!seq->convert_buf)
seq->convert_buf = malloc(width * height * 3);

for (n = 0; n < width * height; n++)
{
seq->convert_buf[n] = buffer[4 * n];
seq->convert_buf[n + width * height] = buffer[4 * n + 1];
seq->convert_buf[n + 2 * width * height] = buffer[4 * n + 2];
}

for (n = 0; n < width * height; n++)
/* Feed the buffers to FFmpeg */
buflist[0] = seq->convert_buf;
buflist[1] = seq->convert_buf + 2 * width * height;
buflist[2] = seq->convert_buf + width * height;
pitchlist[0] = pitchlist[1] = pitchlist[2] = width;
}
else
{
seq->convert_buf[n] = buffer[4 * n];
seq->convert_buf[n + width * height] = buffer[4 * n + 1];
seq->convert_buf[n + 2 * width * height] = buffer[4 * n + 2];
buflist[0] = buffer;
pitchlist[0] = 4 * width;
}

/* Feed the buffers to FFmpeg */
buflist[0] = seq->convert_buf;
buflist[1] = seq->convert_buf + 2 * width * height;
buflist[2] = seq->convert_buf + width * height;
pitchlist[0] = pitchlist[1] = pitchlist[2] = width;
sws_scale(ff->sws_ctx, buflist, pitchlist, 0, height,
ff->frame->data, ff->frame->linesize);

@@ -279,11 +290,13 @@ int pipi_close_sequence(pipi_sequence_t *seq)
#if defined USE_FFMPEG
ffmpeg_codec_t *ff = (ffmpeg_codec_t *)seq->codec_priv;

if (ff->fmt_ctx)
/* Finish the sequence */
if (ff->buf)
{
av_write_trailer(ff->fmt_ctx);
}

/* Close everything */
if (ff->buf)
{
av_free(ff->buf);
@@ -311,7 +324,7 @@ int pipi_close_sequence(pipi_sequence_t *seq)
av_freep(&ff->fmt_ctx->streams[0]);
ff->stream = NULL;

if (!(ff->fmt_ctx->flags & AVFMT_NOFILE))
if (!(ff->fmt_ctx->flags & AVFMT_NOFILE) && ff->fmt_ctx->pb)
url_fclose(ff->fmt_ctx->pb);

av_free(ff->fmt_ctx);


正在加载...
取消
保存