mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/msvideo1enc: drop dependancy on sizeof(AVFrame)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
fca7943850
commit
c81234651f
@ -35,7 +35,6 @@
|
|||||||
*/
|
*/
|
||||||
typedef struct Msvideo1EncContext {
|
typedef struct Msvideo1EncContext {
|
||||||
AVCodecContext *avctx;
|
AVCodecContext *avctx;
|
||||||
AVFrame pic;
|
|
||||||
AVLFG rnd;
|
AVLFG rnd;
|
||||||
uint8_t *prev;
|
uint8_t *prev;
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
const AVFrame *pict, int *got_packet)
|
const AVFrame *pict, int *got_packet)
|
||||||
{
|
{
|
||||||
Msvideo1EncContext * const c = avctx->priv_data;
|
Msvideo1EncContext * const c = avctx->priv_data;
|
||||||
AVFrame * const p = &c->pic;
|
const AVFrame *p = pict;
|
||||||
uint16_t *src;
|
uint16_t *src;
|
||||||
uint8_t *prevptr;
|
uint8_t *prevptr;
|
||||||
uint8_t *dst, *buf;
|
uint8_t *dst, *buf;
|
||||||
@ -75,12 +74,12 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
int no_skips = 1;
|
int no_skips = 1;
|
||||||
int i, j, k, x, y, ret;
|
int i, j, k, x, y, ret;
|
||||||
int skips = 0;
|
int skips = 0;
|
||||||
|
int quality = 24;
|
||||||
|
|
||||||
if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0)
|
if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
dst= buf= pkt->data;
|
dst= buf= pkt->data;
|
||||||
|
|
||||||
*p = *pict;
|
|
||||||
if(!c->prev)
|
if(!c->prev)
|
||||||
c->prev = av_malloc(avctx->width * 3 * (avctx->height + 3));
|
c->prev = av_malloc(avctx->width * 3 * (avctx->height + 3));
|
||||||
prevptr = c->prev + avctx->width * 3 * (FFALIGN(avctx->height, 4) - 1);
|
prevptr = c->prev + avctx->width * 3 * (FFALIGN(avctx->height, 4) - 1);
|
||||||
@ -88,7 +87,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
if(c->keyint >= avctx->keyint_min)
|
if(c->keyint >= avctx->keyint_min)
|
||||||
keyframe = 1;
|
keyframe = 1;
|
||||||
|
|
||||||
p->quality = 24;
|
|
||||||
|
|
||||||
for(y = 0; y < avctx->height; y += 4){
|
for(y = 0; y < avctx->height; y += 4){
|
||||||
for(x = 0; x < avctx->width; x += 4){
|
for(x = 0; x < avctx->width; x += 4){
|
||||||
@ -114,7 +112,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
bestscore += t*t;
|
bestscore += t*t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bestscore /= p->quality;
|
bestscore /= quality;
|
||||||
}
|
}
|
||||||
// try to find optimal value to fill whole 4x4 block
|
// try to find optimal value to fill whole 4x4 block
|
||||||
score = 0;
|
score = 0;
|
||||||
@ -130,7 +128,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
score /= p->quality;
|
score /= quality;
|
||||||
score += 2;
|
score += 2;
|
||||||
if(score < bestscore){
|
if(score < bestscore){
|
||||||
bestscore = score;
|
bestscore = score;
|
||||||
@ -155,7 +153,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
score /= p->quality;
|
score /= quality;
|
||||||
score += 6;
|
score += 6;
|
||||||
if(score < bestscore){
|
if(score < bestscore){
|
||||||
bestscore = score;
|
bestscore = score;
|
||||||
@ -182,7 +180,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
score /= p->quality;
|
score /= quality;
|
||||||
score += 18;
|
score += 18;
|
||||||
if(score < bestscore){
|
if(score < bestscore){
|
||||||
bestscore = score;
|
bestscore = score;
|
||||||
@ -248,8 +246,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
c->keyint = 0;
|
c->keyint = 0;
|
||||||
else
|
else
|
||||||
c->keyint++;
|
c->keyint++;
|
||||||
p->pict_type= keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
|
|
||||||
p->key_frame= keyframe;
|
|
||||||
if (keyframe) pkt->flags |= AV_PKT_FLAG_KEY;
|
if (keyframe) pkt->flags |= AV_PKT_FLAG_KEY;
|
||||||
pkt->size = dst - buf;
|
pkt->size = dst - buf;
|
||||||
*got_packet = 1;
|
*got_packet = 1;
|
||||||
@ -274,8 +270,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
avcodec_get_frame_defaults(&c->pic);
|
|
||||||
avctx->coded_frame = (AVFrame*)&c->pic;
|
|
||||||
avctx->bits_per_coded_sample = 16;
|
avctx->bits_per_coded_sample = 16;
|
||||||
|
|
||||||
c->keyint = avctx->keyint_min;
|
c->keyint = avctx->keyint_min;
|
||||||
|
Loading…
Reference in New Issue
Block a user