A method for encoding input data including one or more frames, the method comprising: generating a residual block based on a difference between a first block of data for multiple pixels in a first frame and a second block of data for multiple pixels in the first or a second frame derived from information in the input data; generating a first block of coefficients based on a transform and quantization performed on the residual block, each coefficient, x[i], of the first block of coefficients having a respective position index, i, which corresponds to a respective position in a one-dimensional scanning order of the coefficients; generating a transformed second block of data based on a transform performed on the second block of data; quantizing the transformed second block of data to obtain a quantized transformed second block of data; generating reference information based on the the quantized transformed second block of data, the reference information comprising reference block prediction coefficients r[i], the position index, i, associated with each reference block prediction coefficient r[i] determined by scanning the reference block prediction coefficients in an order which is the same as that used to generate the respective coefficients of the first block of coefficients; and for at least one coefficient, x[i], of the first block of coefficients: determining a context index, j, based on the reference information and the position index i; wherein the context index, j, is determined by: j = 4 i + min log 2 numPredSig + 1, 3; or j = 4 i + min log 2 r i + 1, 3; wherein numPredSig represents the number of non zero reference block prediction coefficients, and r[i] is the value of the reference block prediction coefficient at the corresponding position index [i]; determining an entropy code value representing x[i] based on the determined context index, j; wherein the same transform and quantization is performed on the second block of data that was applied to the residual block. generating a residual block based on a difference between a first block of data for multiple pixels in a first frame and a second block of data for multiple pixels in the first or a second frame derived from information in the input data; generating a first block of coefficients based on a transform and quantization performed on the residual block, each coefficient, x[i], of the first block of coefficients having a respective position index, i, which corresponds to a respective position in a one-dimensional scanning order of the coefficients; generating a transformed second block of data based on a transform performed on the second block of data; quantizing the transformed second block of data to obtain a quantized transformed second block of data; generating reference information based on the the quantized transformed second block of data, the reference information comprising reference block prediction coefficients r[i], the position index, i, associated with each reference block prediction coefficient r[i] determined by scanning the reference block prediction coefficients in an order which is the same as that used to generate the respective coefficients of the first block of coefficients; and for at least one coefficient, x[i], of the first block of coefficients: determining a context index, j, based on the reference information and the position index i; wherein the context index, j, is determined by: j = 4 i + min log 2 numPredSig + 1, 3; or j = 4 i + min log 2 r i + 1, 3; wherein numPredSig represents the number of non zero reference block prediction coefficients, and r[i] is the value of the reference block prediction coefficient at the corresponding position index [i]; determining an entropy code value representing x[i] based on the determined context index, j; prediction coefficients, and r[i] is the value of the reference block prediction coefficient at the corresponding position index [i]; determining an entropy code value representing x[i] based on the determined context index, j; wherein the same transform and quantization is performed on the second block of data that was applied to the residual block.