ultravideo / kvazaar

An open-source HEVC encoder
BSD 3-Clause "New" or "Revised" License
831 stars 178 forks source link

Assertion failed: (y_offset + height <= orig_image->height) #227

Closed knopp closed 5 years ago

knopp commented 5 years ago

function kvz_image_make_subimage, file image.c, line 156

Happens with video that has dimension of 400x226

in encoder_state_encode,

const int height = MIN(sub_state->tile->frame->height_in_lcu * LCU_WIDTH, main_state->tile->frame->height - offset_y) 

is 332, later passed to kvz_image_make_subimage which checks it against main_state->tile->frame->source->height, which is 226

if I change width/height calculations to use frame->source->width/height, it seems to work fine

Arizer commented 5 years ago

Hi and thanks for the report.

I can not reproduce this. What are the exact options you are using?

knopp commented 5 years ago

Not sure if it helps, but here's dump from kzv_config

cfg kvz_config  
qp  int32_t 16
intra_period    int32_t 1
vps_period  int32_t 0
width   int32_t 400
height  int32_t 226
framerate   double  25
framerate_num   int32_t 1
framerate_denom int32_t 1
deblock_enable  int32_t 1
sao_type    kvz_sao KVZ_SAO_OFF
rdoq_enable int32_t 0
signhide_enable int32_t 0
smp_enable  int32_t 0
amp_enable  int32_t 0
rdo int32_t 0
full_intra_search   int32_t 0
trskip_enable   int32_t 0
tr_depth_intra  int32_t 0
ime_algorithm   kvz_ime_algorithm   KVZ_IME_HEXBS
fme_level   int32_t 0
source_scan_type    int8_t  '\0'
bipred  int32_t 0
deblock_beta    int32_t 0
deblock_tc  int32_t 0
vui kvz_config::(anonymous struct)  
sar_width   int32_t 0
sar_height  int32_t 0
overscan    int8_t  '\0'
videoformat int8_t  '\x05'
fullrange   int8_t  '\0'
colorprim   int8_t  '\x02'
transfer    int8_t  '\x02'
colormatrix int8_t  '\x02'
chroma_loc  int32_t 0
aud_enable  int32_t 0
ref_frames  int32_t 1
cqmfile char *  NULL    0x0000000000000000
*cqmfile    char    
tiles_width_count   int32_t 1
tiles_height_count  int32_t 1
tiles_width_split   int32_t *   NULL    0x0000000000000000
*tiles_width_split  int32_t 
tiles_height_split  int32_t *   NULL    0x0000000000000000
*tiles_height_split int32_t 
wpp int 1
owf int 2
slice_count int32_t 1
slice_addresses_in_ts   int32_t *   NULL    0x0000000000000000
*slice_addresses_in_ts  int32_t 
threads int32_t 0
cpuid   int32_t 1
pu_depth_inter  kvz_config::(anonymous struct)  
pu_depth_intra  kvz_config::(anonymous struct)  
add_encoder_info    int32_t 1
gop_len int8_t  '\x04'
gop_lowdelay    int8_t  '\x01'
gop kvz_gop_config [32] 
target_bitrate  int32_t 0
mv_rdo  int8_t  '\0'
calc_psnr   int8_t  '\x01'
mv_constraint   kvz_mv_constraint   KVZ_MV_CONSTRAIN_NONE
hash    kvz_hash    KVZ_HASH_CHECKSUM
cu_split_termination    kvz_cu_split_termination    KVZ_CU_SPLIT_TERMINATION_ZERO
crypto_features kvz_crypto_features KVZ_CRYPTO_OFF
optional_key    uint8_t *   NULL    0x0000000000000000
me_early_termination    kvz_me_early_termination    KVZ_ME_EARLY_TERMINATION_SENSITIVE
intra_rdo_et    int32_t 0
lossless    int32_t 0
tmvp_enable int32_t 1
rdoq_skip   int32_t 0
input_format    kvz_input_format    KVZ_FORMAT_P420
input_bitdepth  int32_t 8
gop_lp_definition   kvz_config::(anonymous struct)  
implicit_rdpcm  int32_t 0
roi kvz_config::(anonymous struct)  
slices  unsigned int    0
erp_aqp int32_t 0
level   uint8_t '>'
force_level uint8_t '\x01'
high_tier   uint8_t '\0'
max_bitrate uint32_t    240000000
me_max_steps    uint32_t    4294967295
fast_residual_cost_limit    int8_t  '\x1c'
set_qp_in_cu    int8_t  '\0'
open_gop    int8_t  '\x01'
scaling_list    int8_t  '\0'
max_merge   uint8_t '\x05'

Stack trace to assertion:

#3  0x00007fff7761a20d in __assert_rtn ()
#4  0x0000000105763a3e in kvz_image_make_subimage at /opt/mp-dep/x64-debug/build/kvazaar/src/image.c:156
#5  0x000000010575376a in encoder_state_encode at /opt/mp-dep/x64-debug/build/kvazaar/src/encoderstate.c:883
#6  0x00000001057549ed in encoder_state_worker_encode_children at /opt/mp-dep/x64-debug/build/kvazaar/src/encoderstate.c:837
#7  0x0000000105753ab5 in encoder_state_encode at /opt/mp-dep/x64-debug/build/kvazaar/src/encoderstate.c:947
#8  0x0000000105752f56 in kvz_encode_one_frame at /opt/mp-dep/x64-debug/build/kvazaar/src/encoderstate.c:1290
#9  0x000000010576d6a2 in kvazaar_encode at /opt/mp-dep/x64-debug/build/kvazaar/src/kvazaar.c:253
#10 0x000000010576d246 in kvazaar_field_encoding_adapter at /opt/mp-dep/x64-debug/build/kvazaar/src/kvazaar.c:304
Arizer commented 5 years ago

Thanks. It would be good to know what you wrote to the command line to start Kvazaar.

Still can not reproduce. Are you using a recent version of Kvazaar? Have you made modifications to the code?

knopp commented 5 years ago

I'm using the API directly, I'm not using the command line. This happens with latest master, no modification. If I find some time I might try to put together a test case.

Arizer commented 5 years ago

Ok, so are you by any chance missing 'padding' in the image allocation? HEVC requires the width and height to be multiples of 8. For some reason this is not handled automatically in the Kvazaar lib but in the code that is using the API. (Code to set padding values can be found in get_padding() function in encmain.c).

src/encmain.c:135-137

    frame_in = args->api->picture_alloc_csp(csp,
                                            args->opts->config->width  + args->padding_x,
                                            args->opts->config->height + args->padding_y);
knopp commented 5 years ago

I didn't realize HEVC requires video dimensions divisible by 8. In that case this probably works as expected, I think this issue can be closed.