Changeset 4704
- Timestamp:
- Nov 3, 2010, 10:31:38 PM (10 years ago)
- Location:
- libpipi/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/examples/dumpmovie.c
r4703 r4704 38 38 uint8_t *dst[4], *data = NULL; 39 39 char *parser; 40 int stream, pitch[4], i, k = 0; 40 int stream, pitch[4], i, k = 0, nframes = -1; 41 double skip_seconds = 0.0; 41 42 42 if (argc < 2)43 if (argc < 2) 43 44 return EXIT_FAILURE; 45 46 if (argc > 2) 47 skip_seconds = atof(argv[2]); 48 if (argc > 3) 49 nframes = atoi(argv[3]); 44 50 45 51 /* Ensure our linear YUV values do not get gamma-corrected */ … … 73 79 return EXIT_FAILURE; 74 80 81 skip_seconds /= av_q2d(fmt->streams[stream]->time_base); 82 av_seek_frame(fmt, stream, (int)(skip_seconds + 0.5), SEEK_SET); 83 //avformat_seek_file(fmt, stream, skip_bytes, skip_bytes, 84 // skip_bytes, AVSEEK_FLAG_BYTE); 85 75 86 frame = avcodec_alloc_frame(); 76 87 77 for (;;)88 for (k = 0; k < nframes || nframes == -1; /* k incremented below */) 78 89 { 79 90 int finished, ret, x, y; … … 113 124 } 114 125 115 sws_scale(sws, (uint8_t const **)frame->data, frame->linesize, 0,116 ctx->height, dst, pitch);117 118 p = pipi_get_pixels(image, PIPI_PIXELS_RGBA_U8);119 data = (uint8_t *)p->pixels;120 121 for (y = 0; y < ctx->height; y++)122 {123 int off = y * ctx->width;124 125 for (x = 0; x < ctx->width; x++, off++)126 {127 /* Reorder components to store YUVA */128 data[4 * off] = dst[0][off];129 data[4 * off + 1] = dst[2][off];130 data[4 * off + 2] = dst[1][off];131 data[4 * off + 3] = 0xff;132 }133 }134 135 126 { 136 127 char buf[1024]; 137 sprintf(buf, fmtstr, k ++);128 sprintf(buf, fmtstr, k); 138 129 printf("saving in %s\n", buf); 130 131 sws_scale(sws, (uint8_t const **)frame->data, frame->linesize, 0, 132 ctx->height, dst, pitch); 133 134 p = pipi_get_pixels(image, PIPI_PIXELS_RGBA_U8); 135 data = (uint8_t *)p->pixels; 136 137 for (y = 0; y < ctx->height; y++) 138 { 139 int off = y * ctx->width; 140 141 for (x = 0; x < ctx->width; x++, off++) 142 { 143 /* Reorder components to store YUVA */ 144 data[4 * off] = dst[0][off]; 145 data[4 * off + 1] = dst[2][off]; 146 data[4 * off + 2] = dst[1][off]; 147 data[4 * off + 3] = 0xff; 148 } 149 } 150 139 151 pipi_save(image, buf); 140 152 } 141 153 142 154 av_free_packet(&packet); 155 156 k++; 143 157 } 144 158 -
libpipi/trunk/pipi/pipi_internals.h
r3627 r4704 86 86 { 87 87 int w, h, fps; 88 uint8_t *convert_buf; 88 89 89 90 void *codec_priv; -
libpipi/trunk/pipi/sequence.c
r4700 r4704 70 70 seq->h = height; 71 71 seq->fps = fps; 72 seq->convert_buf = NULL; 72 73 73 74 ff = malloc(sizeof(ffmpeg_codec_t)); … … 201 202 #if defined USE_FFMPEG 202 203 AVPacket packet; 204 uint8_t const *buflist[3]; 205 int pitchlist[3]; 203 206 size_t bytes; 204 int pitch;207 int n; 205 208 206 209 ffmpeg_codec_t *ff = (ffmpeg_codec_t *)seq->codec_priv; … … 216 219 217 220 if (!ff->sws_ctx) 218 ff->sws_ctx = sws_getContext(width, height, PIX_FMT_RGB32, 219 ff->cod_ctx->width, 220 ff->cod_ctx->height, 221 ff->cod_ctx->pix_fmt, SWS_BICUBIC, 222 NULL, NULL, NULL); 221 { 222 ff->sws_ctx = sws_getContext(width, height, PIX_FMT_YUV444P, 223 ff->cod_ctx->width, 224 ff->cod_ctx->height, 225 ff->cod_ctx->pix_fmt, SWS_BICUBIC, 226 NULL, NULL, NULL); 227 if (seq->convert_buf) 228 { 229 free(seq->convert_buf); 230 seq->convert_buf = NULL; 231 } 232 } 223 233 if (!ff->sws_ctx) 224 234 return -1; 225 235 226 pitch = width * 4; 227 sws_scale(ff->sws_ctx, &buffer, &pitch, 0, height, 236 /* 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; 252 sws_scale(ff->sws_ctx, buflist, pitchlist, 0, height, 228 253 ff->frame->data, ff->frame->linesize); 229 254
Note: See TracChangeset
for help on using the changeset viewer.