diff options
author | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2007-12-18 13:52:07 +0000 |
---|---|---|
committer | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2007-12-18 13:52:07 +0000 |
commit | 0c39c38b1456d4a59c4982db74facaa1722edc18 (patch) | |
tree | 2a8c45b49bc75b25a1971bf01772e6e0b9a5d850 /libavcodec | |
parent | 86404ffba2d8795d44cffbbeee3b3c7c2cc6afcc (diff) | |
download | ffmpeg-0c39c38b1456d4a59c4982db74facaa1722edc18.tar.gz |
add bitrate helper to choose all dnxhd variants
Originally committed as revision 11260 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/dnxhddata.c | 43 | ||||
-rw-r--r-- | libavcodec/dnxhddata.h | 3 | ||||
-rw-r--r-- | libavcodec/dnxhdenc.c | 23 |
3 files changed, 40 insertions, 29 deletions
diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c index f926a0b97f..fa6d13fa4a 100644 --- a/libavcodec/dnxhddata.c +++ b/libavcodec/dnxhddata.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "avcodec.h" #include "dnxhddata.h" static const uint8_t dnxhd_1237_luma_weight[] = { @@ -361,49 +362,57 @@ const CIDEntry ff_dnxhd_cid_table[] = { dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, - dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run }, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 115, 120, 145, 240, 290 } }, { 1238, 1920, 1080, 0, 917504, 917504, 4, 8, dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight, dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, - dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, + dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run, + { 175, 185, 220, 365, 440 } }, { 1241, 1920, 1080, 1, 917504, 458752, 6, 10, dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight, dnxhd_1241_dc_codes, dnxhd_1241_dc_bits, dnxhd_1241_ac_codes, dnxhd_1241_ac_bits, dnxhd_1241_ac_level, dnxhd_1241_ac_run_flag, dnxhd_1241_ac_index_flag, - dnxhd_1241_run_codes, dnxhd_1241_run_bits, dnxhd_1241_run }, + dnxhd_1241_run_codes, dnxhd_1241_run_bits, dnxhd_1241_run, + { 185, 220 } }, { 1242, 1920, 1080, 1, 606208, 303104, 4, 8, dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight, dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, - dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run }, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 120, 145 } }, { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, dnxhd_1243_luma_weight, dnxhd_1243_chroma_weight, dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, - dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, + dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run, + { 185, 220 } }, { 1251, 1280, 720, 0, 458752, 458752, 4, 8, dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight, dnxhd_1251_dc_codes, dnxhd_1251_dc_bits, dnxhd_1251_ac_codes, dnxhd_1251_ac_bits, dnxhd_1251_ac_level, dnxhd_1251_ac_run_flag, dnxhd_1251_ac_index_flag, - dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run }, + dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run, + { 90, 110, 175, 220 } }, { 1252, 1280, 720, 0, 303104, 303104, 4, 8, dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight, dnxhd_1252_dc_codes, dnxhd_1252_dc_bits, dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_level, dnxhd_1252_ac_run_flag, dnxhd_1252_ac_index_flag, - dnxhd_1252_run_codes, dnxhd_1252_run_bits, dnxhd_1252_run }, + dnxhd_1252_run_codes, dnxhd_1252_run_bits, dnxhd_1252_run, + { 60, 75, 115, 145 } }, { 1253, 1920, 1080, 0, 188416, 188416, 4, 8, dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, - dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run }, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 36, 45, 75, 90 } }, }; int ff_dnxhd_get_cid_table(int cid) @@ -414,3 +423,21 @@ int ff_dnxhd_get_cid_table(int cid) return i; return -1; } + +int ff_dnxhd_find_cid(AVCodecContext *avctx) +{ + int i, j; + int mbs = avctx->bit_rate/1000000; + for (i = 0; i < sizeof(ff_dnxhd_cid_table)/sizeof(CIDEntry); i++) { + const CIDEntry *cid = &ff_dnxhd_cid_table[i]; + if (cid->width == avctx->width && cid->height == avctx->height && + cid->interlaced == !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT) && + cid->bit_depth == 8) { // until 10 bit is supported + for (j = 0; j < sizeof(cid->bit_rates); j++) { + if (cid->bit_rates[j] == mbs) + return cid->cid; + } + } + } + return 0; +} diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h index c402390224..1bd028e085 100644 --- a/libavcodec/dnxhddata.h +++ b/libavcodec/dnxhddata.h @@ -23,6 +23,7 @@ #define FFMPEG_DNXHDDATA_H #include <stdint.h> +#include "avcodec.h" typedef struct { int cid; @@ -39,10 +40,12 @@ typedef struct { const uint8_t *ac_run_flag, *ac_index_flag; const uint16_t *run_codes; const uint8_t *run_bits, *run; + int bit_rates[5]; ///< Helpher to choose variants, rounded to nearest 5Mb/s } CIDEntry; extern const CIDEntry ff_dnxhd_cid_table[]; int ff_dnxhd_get_cid_table(int cid); +int ff_dnxhd_find_cid(AVCodecContext *avctx); #endif /* FFMPEG_DNXHDDATA_H */ diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index 619e7680c7..9ca842e1d7 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -171,31 +171,12 @@ static int dnxhd_encode_init(AVCodecContext *avctx) DNXHDEncContext *ctx = avctx->priv_data; int i, index; - if (avctx->width == 1920 && avctx->height == 1080) { - if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) { - if (avctx->bit_rate == 120000000) - ctx->cid = 1242; - else if (avctx->bit_rate == 185000000) - ctx->cid = 1243; - } else { - if (avctx->bit_rate == 120000000) - ctx->cid = 1237; - else if (avctx->bit_rate == 185000000) - ctx->cid = 1238; - else if (avctx->bit_rate == 36000000) - ctx->cid = 1253; - } - } else if (avctx->width == 1280 && avctx->height == 720 && - !(avctx->flags & CODEC_FLAG_INTERLACED_DCT)) { - if (avctx->bit_rate == 90000000) - ctx->cid = 1251; - else if (avctx->bit_rate == 60000000) - ctx->cid = 1252; - } + ctx->cid = ff_dnxhd_find_cid(avctx); if (!ctx->cid || avctx->pix_fmt != PIX_FMT_YUV422P) { av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\n"); return -1; } + av_log(avctx, AV_LOG_DEBUG, "cid %d\n", ctx->cid); index = ff_dnxhd_get_cid_table(ctx->cid); ctx->cid_table = &ff_dnxhd_cid_table[index]; |