mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-17 21:14:47 +00:00
ed2391d341
This commit implements a standard, compliant, version 3 and version 4 FFv1 encoder, entirely in Vulkan. The encoder is written in standard GLSL and requires a Vulkan 1.3 supporting GPU with the BDA extension. The encoder can use any amount of slices, but nominally, should use 32x32 slices (1024 in total) to maximize parallelism. All features are supported, as well as all pixel formats. This includes: - Rice - Range coding with a custom quantization table - PCM encoding CRC calculation is also massively parallelized on the GPU. Encoding of unaligned dimensions on subsampled data requires version 4, or requires oversizing the image to 64-pixel alignment and cropping out the padding via container flags. Performance-wise, this makes 1080p real-time screen capture possible at 60fps on even modest GPUs.
75 lines
2.2 KiB
Plaintext
75 lines
2.2 KiB
Plaintext
/*
|
|
* FFv1 codec
|
|
*
|
|
* Copyright (c) 2024 Lynne <dev@lynne.ee>
|
|
*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
struct SliceContext {
|
|
RangeCoder c;
|
|
|
|
#ifdef GOLOMB
|
|
PutBitContext pb; /* 8*8 bytes */
|
|
#endif
|
|
|
|
ivec2 slice_dim;
|
|
ivec2 slice_pos;
|
|
ivec2 slice_rct_coef;
|
|
|
|
uint hdr_len; // only used for golomb
|
|
int slice_coding_mode;
|
|
};
|
|
|
|
/* -1, { -1, 0 } */
|
|
int predict(int L, ivec2 top)
|
|
{
|
|
return mid_pred(L, L + top[1] - top[0], top[1]);
|
|
}
|
|
|
|
/* { -2, -1 }, { -1, 0, 1 }, 0 */
|
|
int get_context(VTYPE2 cur_l, VTYPE3 top_l, TYPE top2, uint8_t quant_table_idx)
|
|
{
|
|
const int LT = top_l[0]; /* -1 */
|
|
const int T = top_l[1]; /* 0 */
|
|
const int RT = top_l[2]; /* 1 */
|
|
const int L = cur_l[1]; /* -1 */
|
|
|
|
int base = quant_table[quant_table_idx][0][(L - LT) & MAX_QUANT_TABLE_MASK] +
|
|
quant_table[quant_table_idx][1][(LT - T) & MAX_QUANT_TABLE_MASK] +
|
|
quant_table[quant_table_idx][2][(T - RT) & MAX_QUANT_TABLE_MASK];
|
|
|
|
if ((quant_table[quant_table_idx][3][127] == 0) &&
|
|
(quant_table[quant_table_idx][4][127] == 0))
|
|
return base;
|
|
|
|
const int TT = top2; /* -2 */
|
|
const int LL = cur_l[0]; /* -2 */
|
|
return base +
|
|
quant_table[quant_table_idx][3][(LL - L) & MAX_QUANT_TABLE_MASK] +
|
|
quant_table[quant_table_idx][4][(TT - T) & MAX_QUANT_TABLE_MASK];
|
|
}
|
|
|
|
const uint32_t log2_run[41] = {
|
|
0, 0, 0, 0, 1, 1, 1, 1,
|
|
2, 2, 2, 2, 3, 3, 3, 3,
|
|
4, 4, 5, 5, 6, 6, 7, 7,
|
|
8, 9, 10, 11, 12, 13, 14, 15,
|
|
16, 17, 18, 19, 20, 21, 22, 23,
|
|
24,
|
|
};
|