Commit graph

687 commits

Author SHA1 Message Date
Ari Koivula 115872b300 Add total running time to output. 2014-04-11 12:42:37 +03:00
Marko Viitanen de1c0b7e8d Fixed intra RDO to include mode bitcost 2014-04-10 16:28:41 +03:00
Marko Viitanen a657cf84d9 Insert most probable (predicted) intra modes to RDO search 2014-04-10 15:59:36 +03:00
Marko Viitanen 05169d9476 Added more modes to RDO mode selection in intra search
Now 8 best modes for sizes 4x4 and 8x8 are added to RDO checking and 3 for other block sizes as before, only applies when --rd 2
2014-04-10 15:20:49 +03:00
Ari Koivula 5fa5e01e05 Merge branch 'intra-cleanup'
Conflicts:
	src/intra.c
	src/intra.h
	src/search.c
2014-04-10 13:51:14 +03:00
Ari Koivula 40c2fa4d46 Change intra reconstruction to use the same prediction function as search.
- This fixes a bug with intra search. It sometimes used filtered reference
  pixels for 4x4 blocks leading to inaccurate cost estimate.
2014-04-10 12:09:19 +03:00
Ari Koivula d5c3ad7a2b Move intra prediction generation to its own function. 2014-04-10 11:27:15 +03:00
Ari Koivula 088dd9ab96 Clean up intra mode search.
- This changes the bitstream a little bit, because it changes the order in
  which the modes are tried and when two modes have the same cost the first
  one is chosen.

- Dst buffer was removes as it was no longer used.
2014-04-10 10:25:57 +03:00
Marko Viitanen 43ae0a3b9a Implemented RDO cost calculation to Intra modes 2014-04-10 10:25:20 +03:00
Marko Viitanen c38ec1aa10 Added commandline option for RDO (--rd) 2014-04-09 12:29:15 +03:00
Marko Viitanen 6558c92020 Clean up get_coeff_cost()
Since contexts were moved to cabac struct, there's no need to store contexts one by one
2014-04-09 11:50:17 +03:00
Ari Koivula 92ac5025f9 Take intra mode based coeff scan mode into account for coeff bit cost.
- Previously only diagonal scan mode, the most common one, would be used.

- This improved bdrate by 0.1-0.5 % for p0 and 0-0.2 % for p60.
2014-04-09 10:44:44 +03:00
Ari Koivula c5dfcdf3aa Simplify scan mode selection.
- The scan mode selection for chroma was a bit complicated so I checked it
  and it was all unnecessary. The mode selection is the same as for luma.
2014-04-09 10:36:39 +03:00
Ari Koivula 3764688f84 Fix lambda initialization.
- Lambda was initialized before slice type was set in encoder_control.
2014-04-08 16:58:36 +03:00
Ari Koivula 0251bf5a1a Improve calculation of chroma coding cost for 4x4 blocks.
- Adds calculation of chroma coefficient cost for 4x4 blocks.

- Previously there was no cost. Now the cost is added to the first prediction
  block for NxN.

- This fix should improve bdrate by about 1%.
2014-04-08 12:43:26 +03:00
Ari Koivula 3c0977c7f3 Fix buffer overflow on copying of reference pixels.
- Valgrind noticed this.

- Shouldn't affect anything as the buffer overflowed to pixel buffers which
  were initialized later.
2014-04-04 17:28:56 +03:00
Ari Koivula 6e0bc655e2 Resolve unused variable warning.
- This unexpectedly changes bitstream, but as that makes no sense, it must be
  because some part of the program uses uninitialized memory.
2014-04-04 17:28:50 +03:00
Marko Viitanen e15a86268d Clean up tabs and whitespaces 2014-04-04 16:04:44 +03:00
Laurent Fasnacht 816ae13b1d Moved context information inside cabac_data.
This is required in order to be able to work on parallelism.
2014-04-04 14:28:50 +02:00
Laurent Fasnacht 8a14bd3b7b Remove cabac global variable 2014-04-04 14:26:40 +02:00
Laurent Fasnacht 946c815932 init_context directly has a QP parameter, instead of passing an encoder_control*
This makes context less tightly coupled with encoder.
2014-04-04 14:26:39 +02:00
Laurent Fasnacht 1e03cf8ac1 Add a function to free g_exp_table.
Even though g_exp_table has to be global (used in #define), it's better to avoid requiring other module to directly access it.
2014-04-04 14:26:39 +02:00
Marko Viitanen 7484dafd82 Fix for get_coeff_cost() scan mode selection
Small BD-rate improvement with this fix
2014-04-04 15:16:04 +03:00
Marko Viitanen c5ba5eb3c8 Use RDO in final_cost 2014-04-04 14:10:49 +03:00
Marko Viitanen b83559d3f3 Use RDO to check for transform skip mode 2014-04-04 13:09:42 +03:00
Marko Viitanen b09854d964 Implemented RDO function to calculate bits used for coefficient coding 2014-04-04 13:09:42 +03:00
Ari Koivula 61256fc31a Enable -Wall by default. 2014-04-04 13:02:08 +03:00
Ari Koivula 69ac9176a5 Disable warnings for extras/getopt.
- This isn't our code so we don't care about these warnings.
2014-04-04 13:02:08 +03:00
Ari Koivula 7239b59e94 Resolve constant conditional expression warning.
- Working towards issue #11.

- I felt that the macro was a little bit too clever in hiding the if-else
  statements so I removed that aspect, which also has the minor benefit of not
  requiring the starting if (0) statement.
2014-04-04 13:02:07 +03:00
Ari Koivula b19e4f3f2d Resolve possible uninitialized variable warnings.
- Working towards issue #11.

- Neither variable was actually used as uninitialized.
2014-04-04 13:02:06 +03:00
Ari Koivula 61ae195af7 Resolve warnings about assignments within conditions.
- Working towards issue #11.
2014-04-04 13:02:06 +03:00
Ari Koivula d44d1837bb Remove unreferenced parameters.
- Working towards issue #11.
2014-04-04 12:56:24 +03:00
Ari Koivula 46d33d3945 Resolve unsigned/signed mismatch warnings.
- Working towards issue #11.
2014-04-04 12:56:23 +03:00
Ari Koivula c142cbba21 Fix typo.
- Obvious typo. This g_bitdepth - 8 used to be g_bitincrement. Doesn't affect
  anything yet as we don't actually support bitdepth > 8 yet.
2014-04-04 12:56:22 +03:00
Laurent Fasnacht b371a8bb59 Use realloc correctly
Quote from MALLOC(3) manpage:

The realloc() function returns a pointer to the newly allocated memory, which is suitably aligned for  any  kind  of
variable and may be different from ptr, or NULL if the request fails.
2014-04-04 06:37:35 +02:00
Ari Koivula 0074cd1a98 Add extra parenthesis to suppress compiler warnings. 2014-04-03 15:38:18 +03:00
Ari Koivula 27a3329dfb Remove unreferenced_parameter macro.
- It was a silly hack to selectively silence compiler warnings from VS, but
  there is no point as it causes compiler warnings in GCC.
2014-04-03 15:38:17 +03:00
Ari Koivula f380e7d4b0 Check for malloc failure. 2014-04-03 15:38:17 +03:00
Ari Koivula 313466fdff Remove unused variables.
- Working towards issue #11.

- Either removed or redefined variables to not cause a warning.
2014-04-03 15:37:59 +03:00
Marko Viitanen 0da8071300 Changed final cost (and transform skip) error function from SAD to SSD 2014-04-02 14:51:39 +03:00
Marko Viitanen a14fb14e33 Added new commandline parameter --no-transform-skip 2014-04-02 14:49:48 +03:00
Marko Viitanen 21e02e2d7d Added 4x4 SATD (Hadamard)
Taken from HM 13.0
2014-04-02 11:12:42 +03:00
Marko Viitanen cfb21c0e4c Implemented transform skipping (for 4x4 blocks)
transform skip vs. normal transform selection criteria might need more work, currently both are calculated for each 4x4 block and SAD+coeff_SSE is compared.
2014-04-02 10:54:03 +03:00
Laurent Fasnacht ae5c573843 Global defines are now documented with references the specification when possible. Removes some redundancy. 2014-04-01 13:48:17 +02:00
Panu Sjövall c8f629495d Remove unnecessary buffer from bitstream.
- Writing encoded data to file is done in bitstream_put one byte at a time and nal_write only writes the packet headers
2014-03-25 11:46:56 +02:00
Ari Koivula 953aef0379 Move rest of LCU encoding inside the LCU loop.
- Move SAO search inside the LCU loop.

- Move CU coding inside the LCU loop.

- Move SAO frame reconstruction loop to sao module.
2014-03-21 12:41:44 +02:00
Ari Koivula 746eaa3671 Move deblocking code to filter module. 2014-03-21 11:57:12 +02:00
Ari Koivula 4d34377c42 Clean up deblocking code a bit.
- Change guards to use the same method of checking for coordinate alignment.

- Move variables to reduce their scope.
2014-03-21 10:50:47 +02:00
Ari Koivula 0f492c7680 Fix deblocking of transform boundaries.
This fixes issues with inter. Deblocking works now.
2014-03-21 10:42:41 +02:00
Ari Koivula c42b25054a Modify deblocking to be done per-LCU in the encoding loop.
- Intra works. There is still something wrong in inter.

- Avoid horizontal deblocking of the rightmost 4 pixels in the LCU.
  This is because vertical deblocking must be done for all pixels
  before horizontal, but vertical deblocking can't be done for those
  pixels before the next LCU is finished.

- Add separate deblocking of the rightmost pixels of the last LCU
  after the LCU edge has been deblocked.

- This is a pretty ugly hack but will have to do for now.
2014-03-20 18:14:43 +02:00
Ari Koivula bbd1202f90 Replace old LCU reference pixels initialization with new ones.
In the future we might even have just a const pointer to reference pixels.
2014-03-19 16:01:31 +02:00
Ari Koivula 7328fc2897 Add special handling for bottom right LCU pixel.
I didn't take into account that the reference pixel on the top-left of the
LCU gets over written if we just replace the top reference pixels for
current LCU with the bottom reference pixels after doing the search.
To handle this I copy the pixel that gets overwritten to the vertical
reference pixels.
2014-03-19 16:01:31 +02:00
Ari Koivula 57ce7e990b Add new reference pixel buffer management to encoding loop.
- This is necessary because after we add in-loop filters to be done per LCU,
  the reconstruction buffer will have the deblocked pixels. We only need the
  edge-pixels for intra prediction though so we just save those.

- Right now it only copies the pixels and passes them on to search, where
  the copied pixels are asserted to be the same ones we copy from
  reconstruction buffer.

- New yuv_t struct added for arrays of dynamic length. We might want to change
  other buffers to use it or something like it in the future.
2014-03-19 16:01:30 +02:00
Ari Koivula eacad83ff9 Fix encoder reconstruction output for non multiple of 8 sized input.
Output changed so that only pixels within the conformance window are output.
2014-03-19 13:24:01 +02:00
Ari Koivula 34e453c880 Clean up encode_one_frame.
There is a lot of duplicated code due to handling random access and trailing
pictures separately. I merged the code for these two branches so it would be
easier to modify.
2014-03-17 18:04:41 +02:00
Ari Koivula b1596eb76c Refactor coding of end_of_slice_segment_flag.
According to spec the end_of_slice_segment_flag is always coded, but in the
code it looked like it was not coded for the last LCU in picture. This was
due to the end_of_slice_segment_flag being coded inside cabac_flush, like it
is in HM. This is a bit silly so I moved it out of cabac_flush.
2014-03-17 18:04:41 +02:00
Ari Koivula 6a384112cc Remove old unnecessary functions from search module.
- As we move to per-LCU encoding only search_lcu will be necessary.

- Function search_best_mode is no longer used.
2014-03-17 18:04:41 +02:00
Marko Viitanen c7ee176480 Removed unused function search_best_mode() 2014-03-17 12:56:04 +02:00
Ari Koivula 9563b50a34 Refactor coefficient group scan mapping lists.
The relation between coefficients positions and coefficient group positions
was a big confusing due to the use of 16x16 diagonal coefficient mappings
also as coefficient group mappings.

- Moved all coefficient group mappings to their own const arrays and added
  a new array the select the correct coefficient group mapping. This removes
  special cases for 8x8 and 32x32 transform sizes.

- Removed all coefficient group mapping initialization from init_sig_last_scan.

- Removed 128x128 and 64x64 from regular coefficient group array as those
  transform sizes don't exist anymore in HEVC.
2014-03-14 16:56:49 +02:00
Ari Koivula 319174258b Increment version number and update usage information. 2014-03-12 18:06:41 +02:00
Ari Koivula 34d4e74cd6 Fix selection of bitcost for NxN mode intra CUs. 2014-03-12 18:05:42 +02:00
Marko Viitanen 17b9c9d0b7 Unified all uses of --input-res to use 'x' as delimiter
Addresses issue #20
2014-03-12 15:20:57 +02:00
Ari Koivula 462b75f0f3 Merge branch 'intra-NxN'
Conflicts:
	src/search.c
2014-03-12 15:08:39 +02:00
Ari Koivula e93ae54e70 Fix bug with selecting wrong coeff scan mode for 4x4 blocks. 2014-03-12 14:56:05 +02:00
Marko Viitanen e6985eeb08 Terminate search when any block is found with no coefficients to code 2014-03-12 14:14:42 +02:00
Marko Viitanen 362fc6c5a5 Reduced bit cost when skip mode is selected 2014-03-12 14:13:38 +02:00
Ari Koivula aa59605392 Set correct max depth for search work-tree copying.
The copy up and down functions had wrong max depth so they didn't work with
4x4 blocks.
2014-03-12 14:02:13 +02:00
Marko Viitanen b5756821dd Tuned cost calculations for "final cost"
By adding chroma cost and using 1.5x coeff cost instead of 0.5x, additional 3% (LP) and 1.8% (AI) drop in BD-rate noticed.
2014-03-12 10:35:56 +02:00
Ari Koivula 409b094acf Try and get NxN to work again.
- Moved NxN search to be done on the same level as other searches, as it's
  really not any different from 2Nx2N.
- Produces working bitstream but reconstruction is different.
2014-03-11 19:19:20 +02:00
Marko Viitanen 75dd1f48ef Bugfix: calculate "final cost" only when block is inter or intra 2014-03-11 17:09:08 +02:00
Marko Viitanen 3b59d7c3a3 Implemented "final cost" calculation for best CU on each depth in search
Take SAD between reconstruction and original and add cost from coding and cost for coding coefficients.
2014-03-11 15:01:50 +02:00
Marko Viitanen aa0fb6ccad Store intra coding bit costs to CU structure 2014-03-11 12:15:50 +02:00
Marko Viitanen bdf8166e5c Store inter coding bit costs to CU structure
To be used for calculating better coding cost later
2014-03-11 11:40:39 +02:00
Marko Viitanen d2d877933a bugfix: only fclose recout if it was opened 2014-03-11 09:09:43 +02:00
Marko Viitanen eaf4434ae9 Removed unused parameter cur_cu from inter_get_merge_cand() 2014-03-11 09:04:17 +02:00
Marko Viitanen f2e722fed8 Implemented early search termination when skip mode is used 2014-03-11 08:55:38 +02:00
Ari Koivula 1b2705a042 Add video dimensions to the filename of encoder reconstruction. 2014-03-10 18:10:50 +02:00
Ari Koivula 965d8c377a Make encoder reconstruction obey --debug. 2014-03-10 18:10:49 +02:00
Ari Koivula 7e507fd615 Add --input-res CLI parameter.
- Also set default width and height to 0 because it makes no sense to assume
  dimensions. It's kind of like defaulting to the most common altitude when
  the altimeter is broken.
- Add config_validate to have a place for checks on overall cfg state.
2014-03-10 16:09:33 +02:00
Ari Koivula a644848b36 Add --seek CLI parameter.
Related to issue #12.

Motivation for adding this is that the syntax for frame accurate seeking in
ffmpeg is a little cumbersome. Also it's kind of a standard feature I guess.
2014-03-10 15:14:56 +02:00
Marko Viitanen a935aa5d96 Untabified encmain.c and nal.c 2014-03-10 12:10:40 +02:00
Marko Viitanen a7dade5069 Tuned inter MV coding costs to achieve BD-rate reduction
Compared to version with no inter costs, around -2% BD-rate in LP configuration
2014-03-10 12:08:09 +02:00
Marko Viitanen 1bd79c719e Fixed MV candidate derivation in search 2014-03-10 10:16:30 +02:00
Marko Viitanen 9a4b0d2cc7 Added newline after printing of real video frame size 2014-03-10 10:16:30 +02:00
Marko Viitanen c7e4861dbf Added coding cost calculations to MV search 2014-03-10 10:16:30 +02:00
Ari Koivula 9dde96f25e Refactor search_cu_intra.
- Formatted.
- Renamed and consolidated variables.
- Removed unused x and y pos from intra_prediction function.
2014-03-07 16:25:25 +02:00
Ari Koivula 470f36ce34 Remove left-over commented out code. 2014-03-07 12:44:45 +02:00
Ari Koivula 5d9aa3409b Merge branch 'new-search-wip'
Conflicts:
	src/encoder.c
	src/intra.c
	src/intra.h
	src/search.c
2014-03-06 19:00:53 +02:00
Ari Koivula 47af5207c5 Remove dead code and fix white space. 2014-03-06 18:35:17 +02:00
Marko Viitanen 877e156cb8 Fixed the case where transform split is used (always on depth 0)
After this fix, inter coding should be working.
2014-03-06 14:52:58 +02:00
Marko Viitanen c9d35aeacf Removed unused block data setting functions from picture.c/.h 2014-03-05 17:22:36 +02:00
Marko Viitanen c3e47c6a8d Removed redundant coeff_y/u/v variables from CU 2014-03-05 17:18:03 +02:00
Marko Viitanen b00f4c8dbf Fixed transform offset value and set tr_depth to correct value when depth 0 2014-03-05 17:10:17 +02:00
Ari Koivula 1cf03cfb37 Add --no-rdoq parameter. 2014-03-05 17:02:21 +02:00
Ari Koivula ca51f660d5 Fix fluctuation of coefficients on identical frames when RDOQ is on.
Moves CABAC context initialization to take place before search. This fixes
an issue with RDOQ returning different coefficients for identical adjacent
frames.

- This actually probably worsens BD-rate a little for all frames except the
  first one because we were using last frames final CABAC context for every
  LCU and now we are using initialized CABAC contexts. The fix is to encode
  the LCU before we start compressing the next LCU so we can update CABAC
  contexts.
2014-03-05 17:02:13 +02:00
Ari Koivula 8f3d5045b0 Add --no-rdoq parameter. 2014-03-05 17:00:08 +02:00
Ari Koivula 139e00f064 Fix fluctuation of coefficients on identical frames when RDOQ is on.
Moves CABAC context initialization to take place before search. This fixes
an issue with RDOQ returning different coefficients for identical adjacent
frames.

- This actually probably worsens BD-rate a little for all frames except the
  first one because we were using last frames final CABAC context for every
  LCU and now we are using initialized CABAC contexts. The fix is to encode
  the LCU before we start compressing the next LCU so we can update CABAC
  contexts.
2014-03-05 17:00:08 +02:00
Marko Viitanen c5842e1769 More fixes to B0 mv candidate selection
After this fix, inter coding works in depth != 0
2014-03-05 12:53:35 +02:00
Marko Viitanen 278042aaac Fixed top-right CU copy to lcu structure 2014-03-04 16:32:31 +02:00
Marko Viitanen 91e83db3c6 Bugfix for inter_get_spatial_merge_candidates() b2 block checking
Wrong variable was used to check for x-border
2014-03-04 15:34:32 +02:00