* Fixes and improvements, vintage decoders compatibility
* (c) 2013, 2014 Rl, Aetey Global Technologies AB
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
/*
* TODO:
* - optimize: color space conversion (move conversion to libswscale), ...
* MAYBE:
...
...
@@ -34,30 +36,29 @@ OTHER DEALINGS IN THE SOFTWARE.
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/lfg.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "libavutil/lfg.h"
#include "elbg.h"
#include "internal.h"
#include "libavutil/avassert.h"
#define CVID_HEADER_SIZE 10
#define STRIP_HEADER_SIZE 12
#define CHUNK_HEADER_SIZE 4
#define MB_SIZE 4 //4x4 MBs
#define MB_AREA (MB_SIZE*MB_SIZE)
#define MB_AREA (MB_SIZE * MB_SIZE)
#define VECTOR_MAX 6 //six or four entries per vector depending on format
#define CODEBOOK_MAX 256 //size of a codebook
#define VECTOR_MAX 6 // six or four entries per vector depending on format
#define CODEBOOK_MAX 256 //size of a codebook
#define MAX_STRIPS 32 //Note: having fewer choices regarding the number of strips speeds up encoding (obviously)
#define MIN_STRIPS 1 //Note: having more strips speeds up encoding the frame (this is less obvious)
#define MAX_STRIPS 32 //Note: having fewer choices regarding the number of strips speeds up encoding (obviously)
#define MIN_STRIPS 1 // Note: having more strips speeds up encoding the frame (this is less obvious)
// MAX_STRIPS limits the maximum quality you can reach
// when you want high quality on high resolutions,
// MIN_STRIPS limits the minimum efficiently encodable bit rate
...
...
@@ -84,17 +85,17 @@ typedef enum {
}mb_encoding;
typedefstruct{
intv1_vector;//index into v1 codebook
intv1_error;//error when using V1 encoding
intv4_vector[4];//indices into v4 codebook
intv4_error;//error when using V4 encoding
intskip_error;//error when block is skipped (aka copied from last frame)
mb_encodingbest_encoding;//last result from calculate_mode_score()
intv1_vector;// index into v1 codebook
intv1_error;// error when using V1 encoding
intv4_vector[4];// indices into v4 codebook
intv4_error;// error when using V4 encoding
intskip_error;// error when block is skipped (aka copied from last frame)
mb_encodingbest_encoding;// last result from calculate_mode_score()
}mb_info;
typedefstruct{
intv1_codebook[CODEBOOK_MAX*VECTOR_MAX];
intv4_codebook[CODEBOOK_MAX*VECTOR_MAX];
intv1_codebook[CODEBOOK_MAX*VECTOR_MAX];
intv4_codebook[CODEBOOK_MAX*VECTOR_MAX];
intv1_size;
intv4_size;
CinepakModemode;
...
...
@@ -116,10 +117,10 @@ typedef struct {
uint64_tlambda;
int*codebook_input;
int*codebook_closest;
mb_info*mb;//MB RD state
intmin_strips;//the current limit
intmax_strips;//the current limit
// options
mb_info*mb;// MB RD state
intmin_strips;// the current limit
intmax_strips;// the current limit
// options
intmax_extra_cb_iterations;
intskip_empty_cb;
intmin_min_strips;
...
...
@@ -130,11 +131,16 @@ typedef struct {
#define OFFSET(x) offsetof(CinepakEncContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
staticconstAVOptionoptions[]={
{"max_extra_cb_iterations","Max extra codebook recalculation passes, more is better and slower",OFFSET(max_extra_cb_iterations),AV_OPT_TYPE_INT,{.i64=2},0,INT_MAX,VE},
{"max_strips","Limit strips/frame, vintage compatible is 1..3, otherwise the more the better",OFFSET(max_max_strips),AV_OPT_TYPE_INT,{.i64=3},MIN_STRIPS,MAX_STRIPS,VE},
{"min_strips","Enforce min strips/frame, more is worse and faster, must be <= max_strips",OFFSET(min_min_strips),AV_OPT_TYPE_INT,{.i64=MIN_STRIPS},MIN_STRIPS,MAX_STRIPS,VE},
{"strip_number_adaptivity","How fast the strip number adapts, more is slightly better, much slower",OFFSET(strip_number_delta_range),AV_OPT_TYPE_INT,{.i64=0},0,MAX_STRIPS-MIN_STRIPS,VE},
{"max_extra_cb_iterations","Max extra codebook recalculation passes, more is better and slower",