Merge commit 'a7fcd4122b19b0f934020f4e261d0c44c4c32e11'
* commit 'a7fcd4122b19b0f934020f4e261d0c44c4c32e11': output example: store the scaling context in the stream context Conflicts: doc/examples/muxing.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
@ -59,6 +59,8 @@ typedef struct OutputStream {
|
|||||||
AVFrame *tmp_frame;
|
AVFrame *tmp_frame;
|
||||||
|
|
||||||
float t, tincr, tincr2;
|
float t, tincr, tincr2;
|
||||||
|
|
||||||
|
struct SwsContext *sws_ctx;
|
||||||
} OutputStream;
|
} OutputStream;
|
||||||
|
|
||||||
static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt)
|
static void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt)
|
||||||
@ -413,25 +415,25 @@ static void fill_yuv_image(AVFrame *pict, int frame_index,
|
|||||||
static void write_video_frame(AVFormatContext *oc, OutputStream *ost, int flush)
|
static void write_video_frame(AVFormatContext *oc, OutputStream *ost, int flush)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
static struct SwsContext *sws_ctx;
|
|
||||||
AVCodecContext *c = ost->st->codec;
|
AVCodecContext *c = ost->st->codec;
|
||||||
|
|
||||||
if (!flush) {
|
if (!flush) {
|
||||||
if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
|
if (c->pix_fmt != AV_PIX_FMT_YUV420P) {
|
||||||
/* as we only generate a YUV420P picture, we must convert it
|
/* as we only generate a YUV420P picture, we must convert it
|
||||||
* to the codec pixel format if needed */
|
* to the codec pixel format if needed */
|
||||||
if (!sws_ctx) {
|
if (!ost->sws_ctx) {
|
||||||
sws_ctx = sws_getContext(c->width, c->height, AV_PIX_FMT_YUV420P,
|
ost->sws_ctx = sws_getContext(c->width, c->height, AV_PIX_FMT_YUV420P,
|
||||||
c->width, c->height, c->pix_fmt,
|
c->width, c->height,
|
||||||
|
c->pix_fmt,
|
||||||
SCALE_FLAGS, NULL, NULL, NULL);
|
SCALE_FLAGS, NULL, NULL, NULL);
|
||||||
if (!sws_ctx) {
|
if (!ost->sws_ctx) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not initialize the conversion context\n");
|
"Could not initialize the conversion context\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fill_yuv_image(ost->tmp_frame, frame_count, c->width, c->height);
|
fill_yuv_image(ost->tmp_frame, frame_count, c->width, c->height);
|
||||||
sws_scale(sws_ctx,
|
sws_scale(ost->sws_ctx,
|
||||||
(const uint8_t * const *)ost->tmp_frame->data, ost->tmp_frame->linesize,
|
(const uint8_t * const *)ost->tmp_frame->data, ost->tmp_frame->linesize,
|
||||||
0, c->height, ost->frame->data, ost->frame->linesize);
|
0, c->height, ost->frame->data, ost->frame->linesize);
|
||||||
} else {
|
} else {
|
||||||
@ -485,6 +487,7 @@ static void close_stream(AVFormatContext *oc, OutputStream *ost)
|
|||||||
avcodec_close(ost->st->codec);
|
avcodec_close(ost->st->codec);
|
||||||
av_frame_free(&ost->frame);
|
av_frame_free(&ost->frame);
|
||||||
av_frame_free(&ost->tmp_frame);
|
av_frame_free(&ost->tmp_frame);
|
||||||
|
sws_freeContext(ost->sws_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
|
Reference in New Issue
Block a user