6 int main(int argc
, char **argv
) {
9 out
= fopen(argv
[1], "w");
15 struct bitstream
*str
= vs_new_encode(VS_H264
);
18 if (vs_start(str
, &val
))
21 struct h264_seqparm
*seqparm
= calloc(sizeof *seqparm
, 1);
22 struct h264_picparm
*picparm
= calloc(sizeof *picparm
, 1);
23 struct h264_slice
*slice
= calloc(sizeof *slice
, 1);
24 seqparm
->frame_mbs_only_flag
= 0;
25 seqparm
->direct_8x8_inference_flag
= 0;
26 picparm
->num_slice_groups_minus1
= 0;
27 picparm
->constrained_intra_pred_flag
= 0;
28 picparm
->transform_8x8_mode_flag
= 1;
29 picparm
->entropy_coding_mode_flag
= 1;
30 slice
->seqparm
= seqparm
;
31 slice
->picparm
= picparm
;
33 slice
->pic_width_in_mbs
= 8;
34 slice
->pic_size_in_mbs
= slice
->pic_width_in_mbs
* 24;
35 slice
->first_mb_in_slice
= 0;
36 slice
->nal_unit_type
= 1;
37 slice
->slice_type
= H264_SLICE_TYPE_P
;
38 slice
->mbaff_frame_flag
= 0;
39 slice
->field_pic_flag
= 1;
40 slice
->cabac_init_idc
= 2;
41 slice
->chroma_array_type
= 1;
42 slice
->num_ref_idx_l0_active_minus1
= 31;
43 slice
->num_ref_idx_l1_active_minus1
= 31;
44 slice
->bit_depth_luma_minus8
= 0;
45 slice
->bit_depth_chroma_minus8
= 0;
46 slice
->mbs
= calloc(sizeof *slice
->mbs
, slice
->pic_size_in_mbs
);
48 for (i
= 0; i
< 96; i
++) {
49 slice
->mbs
[i
].mb_field_decoding_flag
= i
>> 2 & 1;
50 slice
->mbs
[i
].coded_block_pattern
= i
* 3 % 48;
51 slice
->mbs
[i
].transform_size_8x8_flag
= i
& 1;
52 slice
->mbs
[i
].mb_qp_delta
= (i
%5) - 2;
54 slice
->mbs
[i
].mb_type
= 0;
56 slice
->mbs
[i
].mb_type
= 1 + (i
- 16);
57 } else if (i
>= 44 && slice
->slice_type
== H264_SLICE_TYPE_P
) {
59 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_P_SKIP
;
62 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_P_L0_16X16
+ x
;
64 for (j
= 0; j
< 4; j
++)
65 slice
->mbs
[i
].ref_idx
[0][j
] = 15 + (i
& 7);
66 for (j
= 0; j
< 16; j
++) {
67 slice
->mbs
[i
].mvd
[0][j
][0] = -((i
& 7) + 3);
68 slice
->mbs
[i
].mvd
[0][j
][1] = (i
&3);
71 for (j
= 0; j
< 4; j
++)
72 slice
->mbs
[i
].ref_idx
[0][j
] = 4 + (j
>> 1);
73 for (j
= 0; j
< 16; j
++) {
74 slice
->mbs
[i
].mvd
[0][j
][0] = 12 + (j
>> 3);
75 slice
->mbs
[i
].mvd
[0][j
][1] = -(j
>> 3);
78 for (j
= 0; j
< 4; j
++)
79 slice
->mbs
[i
].ref_idx
[0][j
] = 2 + (j
& 1);
80 for (j
= 0; j
< 16; j
++) {
81 slice
->mbs
[i
].mvd
[0][j
][0] = 6 + (j
>>2 & 1);
82 slice
->mbs
[i
].mvd
[0][j
][1] = -(j
>>2 & 1);
86 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_P_8X8
;
87 slice
->mbs
[i
].transform_size_8x8_flag
= 0;
88 for (j
= 0; j
< 4; j
++) {
89 slice
->mbs
[i
].sub_mb_type
[j
] = j
;
90 slice
->mbs
[i
].ref_idx
[0][j
] = j
+1;
91 int tt
[4] = { 0, 2, 1, 3};
92 for (k
= 0; k
< 4; k
++) {
93 int kk
= j
* 4 + (k
& j
[tt
]);
94 slice
->mbs
[i
].mvd
[0][j
*4+k
][0] = 16+kk
;
95 slice
->mbs
[i
].mvd
[0][j
*4+k
][1] = kk
- 32;;
99 } else if (i
>= 44 && slice
->slice_type
== H264_SLICE_TYPE_B
) {
101 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_B_SKIP
;
104 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_B_SKIP
;
107 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_B_SKIP
;
110 slice
->mbs
[i
].mb_type
= H264_MB_TYPE_I_PCM
;
112 if (slice
->mbs
[i
].mb_type
== H264_MB_TYPE_I_NXN
|| slice
->mbs
[i
].mb_type
== H264_MB_TYPE_SI
) {
113 for (j
= 0; j
< 16; j
++) {
114 slice
->mbs
[i
].prev_intra4x4_pred_mode_flag
[j
] = j
& 1;
115 slice
->mbs
[i
].rem_intra4x4_pred_mode
[j
] = j
>> 1;
117 for (j
= 0; j
< 4; j
++) {
118 slice
->mbs
[i
].prev_intra8x8_pred_mode_flag
[j
] = j
& 1;
119 slice
->mbs
[i
].rem_intra8x8_pred_mode
[j
] = j
>> 1;
122 if (slice
->mbs
[i
].mb_type
< H264_MB_TYPE_P_BASE
) {
123 slice
->mbs
[i
].intra_chroma_pred_mode
= i
>> 2 & 3;
125 if (slice
->mbs
[i
].mb_type
== H264_MB_TYPE_P_SKIP
|| slice
->mbs
[i
].mb_type
== H264_MB_TYPE_B_SKIP
) {
126 slice
->mbs
[i
].mb_field_decoding_flag
= 0;
127 slice
->mbs
[i
].coded_block_pattern
= 0;
128 slice
->mbs
[i
].transform_size_8x8_flag
= 0;
129 slice
->mbs
[i
].mb_qp_delta
= 0;
130 slice
->mbs
[i
].intra_chroma_pred_mode
= 0;
131 } else if (slice
->mbs
[i
].mb_type
== H264_MB_TYPE_I_PCM
) {
132 slice
->mbs
[i
].coded_block_pattern
= 0x2f;
133 slice
->mbs
[i
].transform_size_8x8_flag
= 0;
134 slice
->mbs
[i
].mb_qp_delta
= 0;
135 slice
->mbs
[i
].intra_chroma_pred_mode
= 0;
136 for (j
= 0; j
< 256; j
++) {
138 slice
->mbs
[i
].pcm_sample_chroma
[j
] = j
;
140 slice
->mbs
[i
].pcm_sample_luma
[j
] = j
;
143 if (h264_is_intra_16x16_mb_type(slice
->mbs
[i
].mb_type
)) {
144 int mbt
= slice
->mbs
[i
].mb_type
;
145 int infer_cbp
= (((mbt
- H264_MB_TYPE_I_16X16_0_0_0
) >> 2) % 3) << 4;
146 if (mbt
>= H264_MB_TYPE_I_16X16_0_0_1
)
148 slice
->mbs
[i
].coded_block_pattern
= infer_cbp
;
149 slice
->mbs
[i
].transform_size_8x8_flag
= 0;
150 for (j
= 0; j
< 16; j
++) {
151 slice
->mbs
[i
].block_luma_dc
[0][j
] = 0x100 + j
;
152 if (slice
->mbs
[i
].coded_block_pattern
>> (j
>> 2) & 1) {
153 for (k
= 0; k
< 15; k
++) {
155 slice
->mbs
[i
].block_luma_ac
[0][j
][k
] = j
* 16 + k
+ 1;
161 if (!slice
->mbs
[i
].coded_block_pattern
)
162 slice
->mbs
[i
].mb_qp_delta
= 0;
163 for (j
= 0; j
< 16; j
++) {
164 if (slice
->mbs
[i
].coded_block_pattern
>> (j
>> 2) & 1) {
165 for (k
= 0; k
< 16; k
++) {
167 slice
->mbs
[i
].block_luma_4x4
[0][j
][k
] = j
* 16 + k
;
168 slice
->mbs
[i
].block_luma_8x8
[0][j
>>2][(j
&3)*16+k
] = j
*16 + k
;
174 if (slice
->mbs
[i
].coded_block_pattern
& 0x30) {
175 for (k
= 0; k
< 4; k
++) {
176 slice
->mbs
[i
].block_chroma_dc
[i
&1][k
] = -0x10 + k
;
179 if (slice
->mbs
[i
].coded_block_pattern
& 0x20) {
180 for (j
= 0; j
< 4; j
++) {
181 for (k
= 0; k
< 15; k
++) {
183 slice
->mbs
[i
].block_chroma_ac
[i
>>1&1][j
][k
] = k
- 0x1000 + j
* 0x100;
188 if (!slice
->mbaff_frame_flag
)
189 slice
->mbs
[i
].mb_field_decoding_flag
= slice
->field_pic_flag
;
191 slice
->last_mb_in_slice
= i
- 1;
193 if (h264_slice_data(str
, slice
)) return 1;
196 fwrite(str
->bytes
, str
->bytesnum
, 1, out
);
198 struct bitstream
*nstr
= vs_new_decode(VS_H264
, str
->bytes
, str
->bytesnum
);
199 if (vs_start(nstr
, &val
))
202 fprintf (stderr
, "Fail 1\n");
205 if (h264_slice_data(nstr
, slice
)) {
206 h264_print_slice_data(slice
);
209 h264_print_slice_data(slice
);
211 fprintf (stderr
, "All ok!\n");