You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mpegvideo_enc: Use function ptr for encode_picture_header
This gets rid of a switch and (in case of FMT_H263) several ifs. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -23,8 +23,9 @@
|
|||||||
#include "mpegvideo.h"
|
#include "mpegvideo.h"
|
||||||
#include "mpegvideoenc.h"
|
#include "mpegvideoenc.h"
|
||||||
|
|
||||||
void ff_flv_encode_picture_header(MpegEncContext *s)
|
int ff_flv_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
int format;
|
int format;
|
||||||
|
|
||||||
align_put_bits(&s->pb);
|
align_put_bits(&s->pb);
|
||||||
@@ -61,6 +62,8 @@ void ff_flv_encode_picture_header(MpegEncContext *s)
|
|||||||
put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
|
put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
|
||||||
put_bits(&s->pb, 5, s->qscale); /* Quantizer */
|
put_bits(&s->pb, 5, s->qscale); /* Quantizer */
|
||||||
put_bits(&s->pb, 1, 0); /* ExtraInformation */
|
put_bits(&s->pb, 1, 0); /* ExtraInformation */
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level,
|
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level,
|
||||||
|
@@ -21,10 +21,11 @@
|
|||||||
#ifndef AVCODEC_FLVENC_H
|
#ifndef AVCODEC_FLVENC_H
|
||||||
#define AVCODEC_FLVENC_H
|
#define AVCODEC_FLVENC_H
|
||||||
|
|
||||||
#include "mpegvideo.h"
|
|
||||||
#include "put_bits.h"
|
#include "put_bits.h"
|
||||||
|
|
||||||
void ff_flv_encode_picture_header(MpegEncContext *s);
|
typedef struct MPVMainEncContext MPVMainEncContext;
|
||||||
|
|
||||||
|
int ff_flv_encode_picture_header(MPVMainEncContext *const m);
|
||||||
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run,
|
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run,
|
||||||
int last);
|
int last);
|
||||||
|
|
||||||
|
@@ -66,9 +66,10 @@ typedef struct H261EncContext {
|
|||||||
} format;
|
} format;
|
||||||
} H261EncContext;
|
} H261EncContext;
|
||||||
|
|
||||||
void ff_h261_encode_picture_header(MpegEncContext *s)
|
static int h261_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
H261EncContext *const h = (H261EncContext *)s;
|
H261EncContext *const h = (H261EncContext *)m;
|
||||||
|
MpegEncContext *const s = &h->s.s;
|
||||||
int temp_ref;
|
int temp_ref;
|
||||||
|
|
||||||
align_put_bits(&s->pb);
|
align_put_bits(&s->pb);
|
||||||
@@ -94,6 +95,8 @@ void ff_h261_encode_picture_header(MpegEncContext *s)
|
|||||||
put_bits(&s->pb, 1, 0); /* no PEI */
|
put_bits(&s->pb, 1, 0); /* no PEI */
|
||||||
h->gob_number = h->format - 1;
|
h->gob_number = h->format - 1;
|
||||||
s->mb_skip_run = 0;
|
s->mb_skip_run = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -370,6 +373,7 @@ static av_cold int h261_encode_init(AVCodecContext *avctx)
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
s->private_ctx = &h->common;
|
s->private_ctx = &h->common;
|
||||||
|
h->s.encode_picture_header = h261_encode_picture_header;
|
||||||
|
|
||||||
s->min_qcoeff = -127;
|
s->min_qcoeff = -127;
|
||||||
s->max_qcoeff = 127;
|
s->max_qcoeff = 127;
|
||||||
|
@@ -33,6 +33,5 @@
|
|||||||
void ff_h261_reorder_mb_index(MpegEncContext *s);
|
void ff_h261_reorder_mb_index(MpegEncContext *s);
|
||||||
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
|
void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
|
||||||
int motion_x, int motion_y);
|
int motion_x, int motion_y);
|
||||||
void ff_h261_encode_picture_header(MpegEncContext *s);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -26,8 +26,7 @@
|
|||||||
|
|
||||||
const uint8_t (*ff_h263_get_mv_penalty(void))[MAX_DMV*2+1];
|
const uint8_t (*ff_h263_get_mv_penalty(void))[MAX_DMV*2+1];
|
||||||
|
|
||||||
void ff_h263_encode_init(MpegEncContext *s);
|
void ff_h263_encode_init(MPVMainEncContext *m);
|
||||||
void ff_h263_encode_picture_header(MpegEncContext *s);
|
|
||||||
void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line);
|
void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line);
|
||||||
void ff_h263_encode_mb(MpegEncContext *s,
|
void ff_h263_encode_mb(MpegEncContext *s,
|
||||||
int16_t block[6][64],
|
int16_t block[6][64],
|
||||||
|
@@ -221,8 +221,9 @@ av_const int ff_h263_aspect_to_info(AVRational aspect){
|
|||||||
return FF_ASPECT_EXTENDED;
|
return FF_ASPECT_EXTENDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_h263_encode_picture_header(MpegEncContext * s)
|
static int h263_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
|
int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
|
||||||
int best_clock_code=1;
|
int best_clock_code=1;
|
||||||
int best_divisor=60;
|
int best_divisor=60;
|
||||||
@@ -354,6 +355,8 @@ void ff_h263_encode_picture_header(MpegEncContext * s)
|
|||||||
|
|
||||||
put_bits(&s->pb, 1, 1);
|
put_bits(&s->pb, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -819,8 +822,10 @@ void ff_h263_update_mb(MpegEncContext *s)
|
|||||||
ff_h263_update_motion_val(s);
|
ff_h263_update_motion_val(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
av_cold void ff_h263_encode_init(MpegEncContext *s)
|
av_cold void ff_h263_encode_init(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
|
|
||||||
s->me.mv_penalty = ff_h263_get_mv_penalty(); // FIXME exact table for MSMPEG4 & H.263+
|
s->me.mv_penalty = ff_h263_get_mv_penalty(); // FIXME exact table for MSMPEG4 & H.263+
|
||||||
|
|
||||||
s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
|
s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
|
||||||
@@ -854,6 +859,7 @@ av_cold void ff_h263_encode_init(MpegEncContext *s)
|
|||||||
break;
|
break;
|
||||||
// Note for MPEG-4 & H.263 the dc-scale table will be set per frame as needed later
|
// Note for MPEG-4 & H.263 the dc-scale table will be set per frame as needed later
|
||||||
case AV_CODEC_ID_FLV1:
|
case AV_CODEC_ID_FLV1:
|
||||||
|
m->encode_picture_header = ff_flv_encode_picture_header;
|
||||||
if (s->h263_flv > 1) {
|
if (s->h263_flv > 1) {
|
||||||
s->min_qcoeff= -1023;
|
s->min_qcoeff= -1023;
|
||||||
s->max_qcoeff= 1023;
|
s->max_qcoeff= 1023;
|
||||||
@@ -866,6 +872,9 @@ av_cold void ff_h263_encode_init(MpegEncContext *s)
|
|||||||
s->min_qcoeff= -127;
|
s->min_qcoeff= -127;
|
||||||
s->max_qcoeff= 127;
|
s->max_qcoeff= 127;
|
||||||
}
|
}
|
||||||
|
// H.263, H.263+; will be overwritten for MSMPEG-4 later
|
||||||
|
if (!m->encode_picture_header)
|
||||||
|
m->encode_picture_header = h263_encode_picture_header;
|
||||||
|
|
||||||
ff_h263dsp_init(&s->h263dsp);
|
ff_h263dsp_init(&s->h263dsp);
|
||||||
}
|
}
|
||||||
|
@@ -104,13 +104,16 @@ static void mjpeg_encode_picture_header(MpegEncContext *s)
|
|||||||
s->thread_context[i]->esc_pos = 0;
|
s->thread_context[i]->esc_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
|
static int mjpeg_amv_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
MJPEGEncContext *const m = (MJPEGEncContext*)s;
|
MJPEGEncContext *const m2 = (MJPEGEncContext*)m;
|
||||||
av_assert2(s->mjpeg_ctx == &m->mjpeg);
|
MpegEncContext *const s = &m->s;
|
||||||
|
av_assert2(s->mjpeg_ctx == &m2->mjpeg);
|
||||||
/* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
|
/* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
|
||||||
if (!CONFIG_MJPEG_ENCODER || m->mjpeg.huffman != HUFFMAN_TABLE_OPTIMAL)
|
if (!CONFIG_MJPEG_ENCODER || m2->mjpeg.huffman != HUFFMAN_TABLE_OPTIMAL)
|
||||||
mjpeg_encode_picture_header(s);
|
mjpeg_encode_picture_header(s);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_MJPEG_ENCODER
|
#if CONFIG_MJPEG_ENCODER
|
||||||
@@ -309,6 +312,7 @@ static av_cold int mjpeg_encode_init(AVCodecContext *avctx)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
s->mjpeg_ctx = m;
|
s->mjpeg_ctx = m;
|
||||||
|
m2->mpeg.encode_picture_header = mjpeg_amv_encode_picture_header;
|
||||||
|
|
||||||
if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
|
if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
|
||||||
// Used to produce garbage with MJPEG.
|
// Used to produce garbage with MJPEG.
|
||||||
|
@@ -94,7 +94,6 @@ static inline void put_marker(PutBitContext *p, enum JpegMarker code)
|
|||||||
|
|
||||||
typedef struct MpegEncContext MpegEncContext;
|
typedef struct MpegEncContext MpegEncContext;
|
||||||
|
|
||||||
void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s);
|
|
||||||
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
|
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
|
||||||
int ff_mjpeg_encode_stuffing(MpegEncContext *s);
|
int ff_mjpeg_encode_stuffing(MpegEncContext *s);
|
||||||
|
|
||||||
|
@@ -333,7 +333,7 @@ void ff_mpeg1_encode_slice_header(MpegEncContext *s)
|
|||||||
put_bits(&s->pb, 1, 0);
|
put_bits(&s->pb, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_mpeg1_encode_picture_header(MPVMainEncContext *const m)
|
static int mpeg1_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
MPEG12EncContext *const mpeg12 = (MPEG12EncContext*)m;
|
MPEG12EncContext *const mpeg12 = (MPEG12EncContext*)m;
|
||||||
MpegEncContext *const s = &m->s;
|
MpegEncContext *const s = &m->s;
|
||||||
@@ -485,6 +485,8 @@ void ff_mpeg1_encode_picture_header(MPVMainEncContext *const m)
|
|||||||
|
|
||||||
s->mb_y = 0;
|
s->mb_y = 0;
|
||||||
ff_mpeg1_encode_slice_header(s);
|
ff_mpeg1_encode_slice_header(s);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void put_mb_modes(MpegEncContext *s, int n, int bits,
|
static inline void put_mb_modes(MpegEncContext *s, int n, int bits,
|
||||||
@@ -1108,6 +1110,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m->encode_picture_header = mpeg1_encode_picture_header;
|
||||||
|
|
||||||
s->me.mv_penalty = mv_penalty;
|
s->me.mv_penalty = mv_penalty;
|
||||||
s->fcode_tab = fcode_tab + MAX_MV;
|
s->fcode_tab = fcode_tab + MAX_MV;
|
||||||
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
|
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
|
||||||
|
@@ -24,10 +24,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "mpegvideoenc.h"
|
#include "mpegvideo.h"
|
||||||
#include "mpegvideodata.h"
|
#include "mpegvideodata.h"
|
||||||
|
|
||||||
void ff_mpeg1_encode_picture_header(MPVMainEncContext *m);
|
|
||||||
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],
|
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],
|
||||||
int motion_x, int motion_y);
|
int motion_x, int motion_y);
|
||||||
void ff_mpeg1_encode_slice_header(MpegEncContext *s);
|
void ff_mpeg1_encode_slice_header(MpegEncContext *s);
|
||||||
|
@@ -1062,7 +1062,7 @@ static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* write MPEG-4 VOP header */
|
/* write MPEG-4 VOP header */
|
||||||
int ff_mpeg4_encode_picture_header(MPVMainEncContext *const m)
|
static int mpeg4_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
Mpeg4EncContext *const m4 = mainctx_to_mpeg4(m);
|
Mpeg4EncContext *const m4 = mainctx_to_mpeg4(m);
|
||||||
MpegEncContext *const s = &m->s;
|
MpegEncContext *const s = &m->s;
|
||||||
@@ -1291,7 +1291,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
{
|
{
|
||||||
static AVOnce init_static_once = AV_ONCE_INIT;
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||||
Mpeg4EncContext *const m4 = avctx->priv_data;
|
Mpeg4EncContext *const m4 = avctx->priv_data;
|
||||||
MpegEncContext *const s = &m4->m.s;
|
MPVMainEncContext *const m = &m4->m;
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
|
if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
|
||||||
@@ -1299,6 +1300,8 @@ static av_cold int encode_init(AVCodecContext *avctx)
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m->encode_picture_header = mpeg4_encode_picture_header;
|
||||||
|
|
||||||
ff_qpeldsp_init(&s->qdsp);
|
ff_qpeldsp_init(&s->qdsp);
|
||||||
if ((ret = ff_mpv_encode_init(avctx)) < 0)
|
if ((ret = ff_mpv_encode_init(avctx)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -25,14 +25,14 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "mpegvideoenc.h"
|
|
||||||
#include "put_bits.h"
|
#include "put_bits.h"
|
||||||
|
|
||||||
|
typedef struct MpegEncContext MpegEncContext;
|
||||||
|
|
||||||
void ff_mpeg4_encode_mb(MpegEncContext *s,
|
void ff_mpeg4_encode_mb(MpegEncContext *s,
|
||||||
int16_t block[6][64],
|
int16_t block[6][64],
|
||||||
int motion_x, int motion_y);
|
int motion_x, int motion_y);
|
||||||
void ff_set_mpeg4_time(MpegEncContext *s);
|
void ff_set_mpeg4_time(MpegEncContext *s);
|
||||||
int ff_mpeg4_encode_picture_header(MPVMainEncContext *m);
|
|
||||||
|
|
||||||
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
|
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
|
||||||
void ff_mpeg4_stuffing(PutBitContext *pbc);
|
void ff_mpeg4_stuffing(PutBitContext *pbc);
|
||||||
|
@@ -66,7 +66,6 @@
|
|||||||
#include "qpeldsp.h"
|
#include "qpeldsp.h"
|
||||||
#include "faandct.h"
|
#include "faandct.h"
|
||||||
#include "aandcttab.h"
|
#include "aandcttab.h"
|
||||||
#include "flvenc.h"
|
|
||||||
#include "mpeg4video.h"
|
#include "mpeg4video.h"
|
||||||
#include "mpeg4videodata.h"
|
#include "mpeg4videodata.h"
|
||||||
#include "mpeg4videoenc.h"
|
#include "mpeg4videoenc.h"
|
||||||
@@ -809,12 +808,17 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
|||||||
avctx->delay = 0;
|
avctx->delay = 0;
|
||||||
s->low_delay = 1;
|
s->low_delay = 1;
|
||||||
break;
|
break;
|
||||||
|
#if CONFIG_RV10_ENCODER
|
||||||
case AV_CODEC_ID_RV10:
|
case AV_CODEC_ID_RV10:
|
||||||
|
m->encode_picture_header = ff_rv10_encode_picture_header;
|
||||||
s->out_format = FMT_H263;
|
s->out_format = FMT_H263;
|
||||||
avctx->delay = 0;
|
avctx->delay = 0;
|
||||||
s->low_delay = 1;
|
s->low_delay = 1;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#if CONFIG_RV20_ENCODER
|
||||||
case AV_CODEC_ID_RV20:
|
case AV_CODEC_ID_RV20:
|
||||||
|
m->encode_picture_header = ff_rv20_encode_picture_header;
|
||||||
s->out_format = FMT_H263;
|
s->out_format = FMT_H263;
|
||||||
avctx->delay = 0;
|
avctx->delay = 0;
|
||||||
s->low_delay = 1;
|
s->low_delay = 1;
|
||||||
@@ -824,6 +828,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
|||||||
s->loop_filter = 1;
|
s->loop_filter = 1;
|
||||||
s->unrestricted_mv = 0;
|
s->unrestricted_mv = 0;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case AV_CODEC_ID_MPEG4:
|
case AV_CODEC_ID_MPEG4:
|
||||||
s->out_format = FMT_H263;
|
s->out_format = FMT_H263;
|
||||||
s->h263_pred = 1;
|
s->h263_pred = 1;
|
||||||
@@ -996,10 +1001,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
|
if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
|
||||||
ff_h263_encode_init(s);
|
ff_h263_encode_init(m);
|
||||||
#if CONFIG_MSMPEG4ENC
|
#if CONFIG_MSMPEG4ENC
|
||||||
if (s->msmpeg4_version != MSMP4_UNUSED)
|
if (s->msmpeg4_version != MSMP4_UNUSED)
|
||||||
ff_msmpeg4_encode_init(s);
|
ff_msmpeg4_encode_init(m);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3888,50 +3893,9 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
|
|||||||
|
|
||||||
s->mb_x = s->mb_y = 0;
|
s->mb_x = s->mb_y = 0;
|
||||||
s->last_bits= put_bits_count(&s->pb);
|
s->last_bits= put_bits_count(&s->pb);
|
||||||
switch(s->out_format) {
|
ret = m->encode_picture_header(m);
|
||||||
#if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER
|
if (ret < 0)
|
||||||
case FMT_MJPEG:
|
return ret;
|
||||||
ff_mjpeg_amv_encode_picture_header(s);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case FMT_SPEEDHQ:
|
|
||||||
if (CONFIG_SPEEDHQ_ENCODER)
|
|
||||||
ff_speedhq_encode_picture_header(s);
|
|
||||||
break;
|
|
||||||
case FMT_H261:
|
|
||||||
if (CONFIG_H261_ENCODER)
|
|
||||||
ff_h261_encode_picture_header(s);
|
|
||||||
break;
|
|
||||||
case FMT_H263:
|
|
||||||
if (CONFIG_WMV2_ENCODER && s->codec_id == AV_CODEC_ID_WMV2)
|
|
||||||
ff_wmv2_encode_picture_header(s);
|
|
||||||
#if CONFIG_MSMPEG4ENC
|
|
||||||
else if (s->msmpeg4_version != MSMP4_UNUSED)
|
|
||||||
ff_msmpeg4_encode_picture_header(s);
|
|
||||||
#endif
|
|
||||||
else if (CONFIG_MPEG4_ENCODER && s->h263_pred) {
|
|
||||||
ret = ff_mpeg4_encode_picture_header(m);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
} else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) {
|
|
||||||
ret = ff_rv10_encode_picture_header(s);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else if (CONFIG_RV20_ENCODER && s->codec_id == AV_CODEC_ID_RV20)
|
|
||||||
ff_rv20_encode_picture_header(s);
|
|
||||||
else if (CONFIG_FLV_ENCODER && s->codec_id == AV_CODEC_ID_FLV1)
|
|
||||||
ff_flv_encode_picture_header(s);
|
|
||||||
else if (CONFIG_H263_ENCODER)
|
|
||||||
ff_h263_encode_picture_header(s);
|
|
||||||
break;
|
|
||||||
case FMT_MPEG1:
|
|
||||||
if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
|
|
||||||
ff_mpeg1_encode_picture_header(m);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
av_assert0(0);
|
|
||||||
}
|
|
||||||
bits= put_bits_count(&s->pb);
|
bits= put_bits_count(&s->pb);
|
||||||
m->header_bits = bits - s->last_bits;
|
m->header_bits = bits - s->last_bits;
|
||||||
|
|
||||||
|
@@ -74,6 +74,8 @@ typedef struct MPVMainEncContext {
|
|||||||
int frame_skip_cmp;
|
int frame_skip_cmp;
|
||||||
me_cmp_func frame_skip_cmp_fn;
|
me_cmp_func frame_skip_cmp_fn;
|
||||||
|
|
||||||
|
int (*encode_picture_header)(struct MPVMainEncContext *m);
|
||||||
|
|
||||||
/* bit rate control */
|
/* bit rate control */
|
||||||
int64_t total_bits;
|
int64_t total_bits;
|
||||||
int frame_bits; ///< bits used for the current frame
|
int frame_bits; ///< bits used for the current frame
|
||||||
|
@@ -135,20 +135,6 @@ static av_cold void msmpeg4_encode_init_static(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
|
|
||||||
{
|
|
||||||
static AVOnce init_static_once = AV_ONCE_INIT;
|
|
||||||
|
|
||||||
ff_msmpeg4_common_init(s);
|
|
||||||
if (s->msmpeg4_version >= MSMP4_WMV1) {
|
|
||||||
s->min_qcoeff = -255;
|
|
||||||
s->max_qcoeff = 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* init various encoding tables */
|
|
||||||
ff_thread_once(&init_static_once, msmpeg4_encode_init_static);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void find_best_tables(MSMPEG4EncContext *ms)
|
static void find_best_tables(MSMPEG4EncContext *ms)
|
||||||
{
|
{
|
||||||
MpegEncContext *const s = &ms->m.s;
|
MpegEncContext *const s = &ms->m.s;
|
||||||
@@ -215,9 +201,10 @@ static void find_best_tables(MSMPEG4EncContext *ms)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* write MSMPEG4 compatible frame header */
|
/* write MSMPEG4 compatible frame header */
|
||||||
void ff_msmpeg4_encode_picture_header(MpegEncContext * s)
|
static int msmpeg4_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s;
|
MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)m;
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
|
|
||||||
find_best_tables(ms);
|
find_best_tables(ms);
|
||||||
|
|
||||||
@@ -275,6 +262,8 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s)
|
|||||||
|
|
||||||
s->esc3_level_length= 0;
|
s->esc3_level_length= 0;
|
||||||
s->esc3_run_length= 0;
|
s->esc3_run_length= 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
|
void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
|
||||||
@@ -674,6 +663,25 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
av_cold void ff_msmpeg4_encode_init(MPVMainEncContext *const m)
|
||||||
|
{
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||||
|
|
||||||
|
ff_msmpeg4_common_init(s);
|
||||||
|
|
||||||
|
if (s->msmpeg4_version <= MSMP4_WMV1)
|
||||||
|
m->encode_picture_header = msmpeg4_encode_picture_header;
|
||||||
|
|
||||||
|
if (s->msmpeg4_version >= MSMP4_WMV1) {
|
||||||
|
s->min_qcoeff = -255;
|
||||||
|
s->max_qcoeff = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* init various encoding tables */
|
||||||
|
ff_thread_once(&init_static_once, msmpeg4_encode_init_static);
|
||||||
|
}
|
||||||
|
|
||||||
const FFCodec ff_msmpeg4v2_encoder = {
|
const FFCodec ff_msmpeg4v2_encoder = {
|
||||||
.p.name = "msmpeg4v2",
|
.p.name = "msmpeg4v2",
|
||||||
CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 2"),
|
CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 2"),
|
||||||
|
@@ -33,8 +33,7 @@ typedef struct MSMPEG4EncContext {
|
|||||||
unsigned ac_stats[2][2][MAX_LEVEL + 1][MAX_RUN + 1][2];
|
unsigned ac_stats[2][2][MAX_LEVEL + 1][MAX_RUN + 1][2];
|
||||||
} MSMPEG4EncContext;
|
} MSMPEG4EncContext;
|
||||||
|
|
||||||
void ff_msmpeg4_encode_init(MpegEncContext *s);
|
void ff_msmpeg4_encode_init(MPVMainEncContext *m);
|
||||||
void ff_msmpeg4_encode_picture_header(MpegEncContext *s);
|
|
||||||
void ff_msmpeg4_encode_ext_header(MpegEncContext *s);
|
void ff_msmpeg4_encode_ext_header(MpegEncContext *s);
|
||||||
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
|
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
|
||||||
int motion_x, int motion_y);
|
int motion_x, int motion_y);
|
||||||
|
@@ -31,8 +31,9 @@
|
|||||||
#include "put_bits.h"
|
#include "put_bits.h"
|
||||||
#include "rv10enc.h"
|
#include "rv10enc.h"
|
||||||
|
|
||||||
int ff_rv10_encode_picture_header(MpegEncContext *s)
|
int ff_rv10_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
int full_frame= 0;
|
int full_frame= 0;
|
||||||
|
|
||||||
align_put_bits(&s->pb);
|
align_put_bits(&s->pb);
|
||||||
|
@@ -21,9 +21,9 @@
|
|||||||
#ifndef AVCODEC_RV10ENC_H
|
#ifndef AVCODEC_RV10ENC_H
|
||||||
#define AVCODEC_RV10ENC_H
|
#define AVCODEC_RV10ENC_H
|
||||||
|
|
||||||
#include "mpegvideo.h"
|
typedef struct MPVMainEncContext MPVMainEncContext;
|
||||||
|
|
||||||
int ff_rv10_encode_picture_header(MpegEncContext *s);
|
int ff_rv10_encode_picture_header(MPVMainEncContext *m);
|
||||||
void ff_rv20_encode_picture_header(MpegEncContext *s);
|
int ff_rv20_encode_picture_header(MPVMainEncContext *m);
|
||||||
|
|
||||||
#endif /* AVCODEC_RV10ENC_H */
|
#endif /* AVCODEC_RV10ENC_H */
|
||||||
|
@@ -34,7 +34,10 @@
|
|||||||
#include "put_bits.h"
|
#include "put_bits.h"
|
||||||
#include "rv10enc.h"
|
#include "rv10enc.h"
|
||||||
|
|
||||||
void ff_rv20_encode_picture_header(MpegEncContext *s) {
|
int ff_rv20_encode_picture_header(MPVMainEncContext *const m)
|
||||||
|
{
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
|
|
||||||
put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 1 ?
|
put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 1 ?
|
||||||
put_bits(&s->pb, 1, 0); /* unknown bit */
|
put_bits(&s->pb, 1, 0); /* unknown bit */
|
||||||
put_bits(&s->pb, 5, s->qscale);
|
put_bits(&s->pb, 5, s->qscale);
|
||||||
@@ -60,6 +63,7 @@ void ff_rv20_encode_picture_header(MpegEncContext *s) {
|
|||||||
s->y_dc_scale_table=
|
s->y_dc_scale_table=
|
||||||
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
|
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FFCodec ff_rv20_encoder = {
|
const FFCodec ff_rv20_encoder = {
|
||||||
|
@@ -95,9 +95,10 @@ static av_cold void speedhq_init_static_data(void)
|
|||||||
ff_speedhq_vlc_table, uni_speedhq_ac_vlc_len);
|
ff_speedhq_vlc_table, uni_speedhq_ac_vlc_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_speedhq_encode_picture_header(MpegEncContext *s)
|
static int speedhq_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
SpeedHQEncContext *ctx = (SpeedHQEncContext*)s;
|
SpeedHQEncContext *const ctx = (SpeedHQEncContext*)m;
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
|
|
||||||
put_bits_le(&s->pb, 8, 100 - s->qscale * 2); /* FIXME why doubled */
|
put_bits_le(&s->pb, 8, 100 - s->qscale * 2); /* FIXME why doubled */
|
||||||
put_bits_le(&s->pb, 24, 4); /* no second field */
|
put_bits_le(&s->pb, 24, 4); /* no second field */
|
||||||
@@ -105,6 +106,8 @@ void ff_speedhq_encode_picture_header(MpegEncContext *s)
|
|||||||
ctx->slice_start = 4;
|
ctx->slice_start = 4;
|
||||||
/* length of first slice, will be filled out later */
|
/* length of first slice, will be filled out later */
|
||||||
put_bits_le(&s->pb, 24, 0);
|
put_bits_le(&s->pb, 24, 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_speedhq_end_slice(MpegEncContext *s)
|
void ff_speedhq_end_slice(MpegEncContext *s)
|
||||||
@@ -230,7 +233,8 @@ void ff_speedhq_encode_mb(MpegEncContext *s, int16_t block[12][64])
|
|||||||
static av_cold int speedhq_encode_init(AVCodecContext *avctx)
|
static av_cold int speedhq_encode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
static AVOnce init_static_once = AV_ONCE_INIT;
|
static AVOnce init_static_once = AV_ONCE_INIT;
|
||||||
MpegEncContext *const s = avctx->priv_data;
|
MPVMainEncContext *const m = avctx->priv_data;
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (avctx->width > 65500 || avctx->height > 65500) {
|
if (avctx->width > 65500 || avctx->height > 65500) {
|
||||||
@@ -258,6 +262,8 @@ static av_cold int speedhq_encode_init(AVCodecContext *avctx)
|
|||||||
av_assert0(0);
|
av_assert0(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m->encode_picture_header = speedhq_encode_picture_header;
|
||||||
|
|
||||||
s->min_qcoeff = -2048;
|
s->min_qcoeff = -2048;
|
||||||
s->max_qcoeff = 2047;
|
s->max_qcoeff = 2047;
|
||||||
|
|
||||||
|
@@ -36,7 +36,6 @@
|
|||||||
void ff_speedhq_encode_close(MpegEncContext *s);
|
void ff_speedhq_encode_close(MpegEncContext *s);
|
||||||
void ff_speedhq_encode_mb(MpegEncContext *s, int16_t block[12][64]);
|
void ff_speedhq_encode_mb(MpegEncContext *s, int16_t block[12][64]);
|
||||||
|
|
||||||
void ff_speedhq_encode_picture_header(MpegEncContext *s);
|
|
||||||
void ff_speedhq_end_slice(MpegEncContext *s);
|
void ff_speedhq_end_slice(MpegEncContext *s);
|
||||||
|
|
||||||
static inline int ff_speedhq_mb_rows_in_slice(int slice_num, int mb_height)
|
static inline int ff_speedhq_mb_rows_in_slice(int slice_num, int mb_height)
|
||||||
|
@@ -73,9 +73,10 @@ static int encode_ext_header(WMV2EncContext *w)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_wmv2_encode_picture_header(MpegEncContext *s)
|
static int wmv2_encode_picture_header(MPVMainEncContext *const m)
|
||||||
{
|
{
|
||||||
WMV2EncContext *const w = (WMV2EncContext *) s;
|
WMV2EncContext *const w = (WMV2EncContext *) m;
|
||||||
|
MpegEncContext *const s = &m->s;
|
||||||
|
|
||||||
put_bits(&s->pb, 1, s->pict_type - 1);
|
put_bits(&s->pb, 1, s->pict_type - 1);
|
||||||
if (s->pict_type == AV_PICTURE_TYPE_I)
|
if (s->pict_type == AV_PICTURE_TYPE_I)
|
||||||
@@ -222,6 +223,7 @@ static av_cold int wmv2_encode_init(AVCodecContext *avctx)
|
|||||||
MpegEncContext *const s = &w->msmpeg4.m.s;
|
MpegEncContext *const s = &w->msmpeg4.m.s;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
w->msmpeg4.m.encode_picture_header = wmv2_encode_picture_header;
|
||||||
s->private_ctx = &w->common;
|
s->private_ctx = &w->common;
|
||||||
ret = ff_mpv_encode_init(avctx);
|
ret = ff_mpv_encode_init(avctx);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include "mpegvideo.h"
|
#include "mpegvideo.h"
|
||||||
|
|
||||||
int ff_wmv2_encode_picture_header(MpegEncContext * s);
|
|
||||||
void ff_wmv2_encode_mb(MpegEncContext * s, int16_t block[6][64],
|
void ff_wmv2_encode_mb(MpegEncContext * s, int16_t block[6][64],
|
||||||
int motion_x, int motion_y);
|
int motion_x, int motion_y);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user