Changeset 1005 in SHVCSoftware for branches/SHM-dev/source/App/utils
- Timestamp:
- 26 Jan 2015, 17:11:15 (10 years ago)
- Location:
- branches/SHM-dev/source/App/utils/ExtractAddLS
- Files:
-
- 1 deleted
- 1 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/App/utils/ExtractAddLS/ExtractAddLS.c
r1004 r1005 34 34 #include <stdlib.h> 35 35 #include <stdio.h> 36 #include <string.h> 36 37 37 38 38 39 enum NalUnitType 39 40 { 40 NAL_UNIT_CODED_SLICE_TRAIL_N = 0, // 041 NAL_UNIT_CODED_SLICE_TRAIL_R, // 142 43 NAL_UNIT_CODED_SLICE_TSA_N, // 244 NAL_UNIT_CODED_SLICE_TSA_R, // 345 46 NAL_UNIT_CODED_SLICE_STSA_N, // 447 NAL_UNIT_CODED_SLICE_STSA_R, // 548 49 NAL_UNIT_CODED_SLICE_RADL_N, // 650 NAL_UNIT_CODED_SLICE_RADL_R, // 751 52 NAL_UNIT_CODED_SLICE_RASL_N, // 853 NAL_UNIT_CODED_SLICE_RASL_R, // 941 NAL_UNIT_CODED_SLICE_TRAIL_N = 0, 42 NAL_UNIT_CODED_SLICE_TRAIL_R, 43 44 NAL_UNIT_CODED_SLICE_TSA_N, 45 NAL_UNIT_CODED_SLICE_TSA_R, 46 47 NAL_UNIT_CODED_SLICE_STSA_N, 48 NAL_UNIT_CODED_SLICE_STSA_R, 49 50 NAL_UNIT_CODED_SLICE_RADL_N, 51 NAL_UNIT_CODED_SLICE_RADL_R, 52 53 NAL_UNIT_CODED_SLICE_RASL_N, 54 NAL_UNIT_CODED_SLICE_RASL_R, 54 55 55 56 NAL_UNIT_RESERVED_VCL_N10, … … 60 61 NAL_UNIT_RESERVED_VCL_R15, 61 62 62 NAL_UNIT_CODED_SLICE_BLA_W_LP, // 1663 NAL_UNIT_CODED_SLICE_BLA_W_RADL, // 1764 NAL_UNIT_CODED_SLICE_BLA_N_LP, // 1865 NAL_UNIT_CODED_SLICE_IDR_W_RADL, // 1966 NAL_UNIT_CODED_SLICE_IDR_N_LP, // 2067 NAL_UNIT_CODED_SLICE_CRA, // 2163 NAL_UNIT_CODED_SLICE_BLA_W_LP, 64 NAL_UNIT_CODED_SLICE_BLA_W_RADL, 65 NAL_UNIT_CODED_SLICE_BLA_N_LP, 66 NAL_UNIT_CODED_SLICE_IDR_W_RADL, 67 NAL_UNIT_CODED_SLICE_IDR_N_LP, 68 NAL_UNIT_CODED_SLICE_CRA, 68 69 NAL_UNIT_RESERVED_IRAP_VCL22, 69 70 NAL_UNIT_RESERVED_IRAP_VCL23, … … 78 79 NAL_UNIT_RESERVED_VCL31, 79 80 80 NAL_UNIT_VPS, // 3281 NAL_UNIT_SPS, // 3382 NAL_UNIT_PPS, // 3483 NAL_UNIT_ACCESS_UNIT_DELIMITER, // 3584 NAL_UNIT_EOS, // 3685 NAL_UNIT_EOB, // 3786 NAL_UNIT_FILLER_DATA, // 3887 NAL_UNIT_PREFIX_SEI, // 3988 NAL_UNIT_SUFFIX_SEI, // 4081 NAL_UNIT_VPS, 82 NAL_UNIT_SPS, 83 NAL_UNIT_PPS, 84 NAL_UNIT_ACCESS_UNIT_DELIMITER, 85 NAL_UNIT_EOS, 86 NAL_UNIT_EOB, 87 NAL_UNIT_FILLER_DATA, 88 NAL_UNIT_PREFIX_SEI, 89 NAL_UNIT_SUFFIX_SEI, 89 90 NAL_UNIT_RESERVED_NVCL41, 90 91 NAL_UNIT_RESERVED_NVCL42, … … 113 114 }; 114 115 116 char *nalUnitNames[] = 117 { 118 "NAL_UNIT_CODED_SLICE_TRAIL_N", 119 "NAL_UNIT_CODED_SLICE_TRAIL_R", 120 121 "NAL_UNIT_CODED_SLICE_TSA_N", 122 "NAL_UNIT_CODED_SLICE_TSA_R", 123 124 "NAL_UNIT_CODED_SLICE_STSA_N", 125 "NAL_UNIT_CODED_SLICE_STSA_R", 126 127 "NAL_UNIT_CODED_SLICE_RADL_N", 128 "NAL_UNIT_CODED_SLICE_RADL_R", 129 130 "NAL_UNIT_CODED_SLICE_RASL_N", 131 "NAL_UNIT_CODED_SLICE_RASL_R", 132 133 "NAL_UNIT_RESERVED_VCL_N10", 134 "NAL_UNIT_RESERVED_VCL_R11", 135 "NAL_UNIT_RESERVED_VCL_N12", 136 "NAL_UNIT_RESERVED_VCL_R13", 137 "NAL_UNIT_RESERVED_VCL_N14", 138 "NAL_UNIT_RESERVED_VCL_R15", 139 140 "NAL_UNIT_CODED_SLICE_BLA_W_LP", 141 "NAL_UNIT_CODED_SLICE_BLA_W_RADL", 142 "NAL_UNIT_CODED_SLICE_BLA_N_LP", 143 "NAL_UNIT_CODED_SLICE_IDR_W_RADL", 144 "NAL_UNIT_CODED_SLICE_IDR_N_LP", 145 "NAL_UNIT_CODED_SLICE_CRA", 146 "NAL_UNIT_RESERVED_IRAP_VCL22", 147 "NAL_UNIT_RESERVED_IRAP_VCL23", 148 149 "NAL_UNIT_RESERVED_VCL24", 150 "NAL_UNIT_RESERVED_VCL25", 151 "NAL_UNIT_RESERVED_VCL26", 152 "NAL_UNIT_RESERVED_VCL27", 153 "NAL_UNIT_RESERVED_VCL28", 154 "NAL_UNIT_RESERVED_VCL29", 155 "NAL_UNIT_RESERVED_VCL30", 156 "NAL_UNIT_RESERVED_VCL31", 157 158 "NAL_UNIT_VPS", 159 "NAL_UNIT_SPS", 160 "NAL_UNIT_PPS", 161 "NAL_UNIT_ACCESS_UNIT_DELIMITER", 162 "NAL_UNIT_EOS", 163 "NAL_UNIT_EOB", 164 "NAL_UNIT_FILLER_DATA", 165 "NAL_UNIT_PREFIX_SEI", 166 "NAL_UNIT_SUFFIX_SEI", 167 "NAL_UNIT_RESERVED_NVCL41", 168 "NAL_UNIT_RESERVED_NVCL42", 169 "NAL_UNIT_RESERVED_NVCL43", 170 "NAL_UNIT_RESERVED_NVCL44", 171 "NAL_UNIT_RESERVED_NVCL45", 172 "NAL_UNIT_RESERVED_NVCL46", 173 "NAL_UNIT_RESERVED_NVCL47", 174 "NAL_UNIT_UNSPECIFIED_48", 175 "NAL_UNIT_UNSPECIFIED_49", 176 "NAL_UNIT_UNSPECIFIED_50", 177 "NAL_UNIT_UNSPECIFIED_51", 178 "NAL_UNIT_UNSPECIFIED_52", 179 "NAL_UNIT_UNSPECIFIED_53", 180 "NAL_UNIT_UNSPECIFIED_54", 181 "NAL_UNIT_UNSPECIFIED_55", 182 "NAL_UNIT_UNSPECIFIED_56", 183 "NAL_UNIT_UNSPECIFIED_57", 184 "NAL_UNIT_UNSPECIFIED_58", 185 "NAL_UNIT_UNSPECIFIED_59", 186 "NAL_UNIT_UNSPECIFIED_60", 187 "NAL_UNIT_UNSPECIFIED_61", 188 "NAL_UNIT_UNSPECIFIED_62", 189 "NAL_UNIT_UNSPECIFIED_63" 190 }; 191 115 192 typedef struct NalUnitHeader_s 116 193 { … … 126 203 int currByte; 127 204 128 while (1)205 for (;;) 129 206 { 130 207 currByte = fgetc(inFile); … … 201 278 int numStartCodeZeros; 202 279 int nalIsSpsPpsEob; 280 int nalIsVpsSpsPpsEos; 203 281 int removeNal; 204 205 if (argc < 4 || argc > 5) 206 { 207 fprintf(stderr, "Usage: BLRewrite <infile> <outfile> <assigned base layer ID> [<max temporal ID>]\n"); 282 int layerIdListTarget[8]; 283 int i; 284 int layerIdx; 285 int numLayerIds; 286 char nalName[32]; 287 288 if (argc < 5 || argc > 10) 289 { 290 fprintf(stderr, "\n Usage: ExtractAddLS <infile> <outfile> <max temporal ID> <list of layer IDs> \n\n"); 291 fprintf(stderr, " If only one layer ID is given, independent non-base layer rewriting process\n"); 292 fprintf(stderr, " is performed\n"); 293 fprintf(stderr, " If more than one layer ID is given, sub-bitstream extraction process for\n"); 294 fprintf(stderr, " additional layer sets is performed (Layer ID list should exactly match\n"); 295 fprintf(stderr, " an additional layer set defined in VPS)\n"); 208 296 exit(1); 209 297 } … … 223 311 } 224 312 225 assignedBaseLayerId= atoi(argv[3]);226 if ( assignedBaseLayerId < 1 || assignedBaseLayerId > 7)227 { 228 fprintf(stderr, "Invalid assigned base layer ID (must be in range 1-7)\n");313 tIdTarget = atoi(argv[3]); 314 if (tIdTarget < 0 || tIdTarget > 6) 315 { 316 fprintf(stderr, "Invalid maximum temporal ID (must be in range 0-6)\n"); 229 317 exit(1); 230 318 } 231 319 232 if (argc == 5)233 { 234 tIdTarget = atoi(argv[4]);235 if ( tIdTarget < 0 || tIdTarget > 6)236 { 237 fprintf(stderr, "Invalid maximum temporal ID (must be in range 0-6)\n");320 for (i = 4, layerIdx = 0; i < argc; i++, layerIdx++) 321 { 322 layerIdListTarget[layerIdx] = atoi(argv[i]); 323 if (layerIdListTarget[layerIdx] < 1 || layerIdListTarget[layerIdx] > 7) 324 { 325 fprintf(stderr, "Invalid layer ID (must be in range 1-7)\n"); 238 326 exit(1); 239 327 } 240 328 } 241 329 242 while (1) 330 numLayerIds = layerIdx; 331 assignedBaseLayerId = layerIdListTarget[0]; 332 333 /* Iterate through all NAL units */ 334 for (;;) 243 335 { 244 336 if (!findStartCodePrefix(inFile, &numStartCodeZeros)) … … 251 343 } 252 344 253 printf("NAL unit type: %i, NUH layer ID: %i, NUH Temporal ID: %i\n", nalu.nalUnitType, nalu.nuhLayerId, nalu.nuhTemporalIdPlus1 - 1); 254 255 nalIsSpsPpsEob = (nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOB); 256 257 removeNal = (!nalIsSpsPpsEob && (nalu.nuhLayerId != assignedBaseLayerId)) 258 || (nalIsSpsPpsEob && (nalu.nuhLayerId != 0) && (nalu.nuhLayerId != assignedBaseLayerId)) 259 || (nalu.nalUnitType == NAL_UNIT_VPS) 260 || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget); 345 if (numLayerIds == 1) 346 { 347 /* independent non-base layer rewriting process */ 348 349 nalIsSpsPpsEob = (nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOB); 350 351 removeNal = (!nalIsSpsPpsEob && (nalu.nuhLayerId != assignedBaseLayerId)) 352 || (nalIsSpsPpsEob && (nalu.nuhLayerId != 0) && (nalu.nuhLayerId != assignedBaseLayerId)) 353 || (nalu.nalUnitType == NAL_UNIT_VPS) 354 || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget); 355 356 nalu.nuhLayerId = 0; 357 } 358 else /* numLayerIds > 1 */ 359 { 360 /* sub-bitstream extraction process for additional layer sets */ 361 362 int isTargetLayer = 0; 363 364 for (i = 0; i < numLayerIds; i++) 365 { 366 if (layerIdListTarget[i] == nalu.nuhLayerId) 367 { 368 isTargetLayer = 1; 369 } 370 } 371 372 nalIsVpsSpsPpsEos = (nalu.nalUnitType == NAL_UNIT_VPS || nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOS); 373 374 removeNal = (!(nalIsVpsSpsPpsEos || nalu.nalUnitType == NAL_UNIT_EOB) && !isTargetLayer) 375 || (nalIsVpsSpsPpsEos && (nalu.nuhLayerId != 0) && !isTargetLayer) 376 || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget); 377 } 261 378 262 379 if (!removeNal) … … 268 385 long i; 269 386 270 nalu.nuhLayerId = 0; 387 printf("Keep "); 388 271 389 writeStartCodePrefixAndNUH(outFile, numStartCodeZeros, &nalu); 272 390 … … 283 401 fseek(inFile, naluBytesStartPos, SEEK_SET); 284 402 285 for (i = 0; i < numNaluBytes; i++) 403 i = 0; 404 405 if (numLayerIds > 1 && nalu.nalUnitType == NAL_UNIT_VPS) 406 { 407 /* sub-bitstream extraction process for additional layer sets */ 408 int nalByte = fgetc(inFile); 409 nalByte = nalByte & ~(0x04); /* vps_base_layer_available_flag in each VPS is set equal to 0 */ 410 fputc(nalByte, outFile); 411 i++; 412 } 413 414 for (; i < numNaluBytes; i++) 286 415 { 287 416 fputc(fgetc(inFile), outFile); 288 417 } 289 418 } 419 else 420 { 421 printf("- "); 422 } 423 424 strcpy(nalName, nalUnitNames[nalu.nalUnitType]); 425 for (i = strlen(nalName); i < 31; i++) 426 { 427 nalName[i] = ' '; 428 } 429 nalName[31] = '\0'; 430 431 printf("%s layer ID: %i temporal ID: %i\n", nalName, nalu.nuhLayerId, nalu.nuhTemporalIdPlus1 - 1); 290 432 } 291 433 -
branches/SHM-dev/source/App/utils/ExtractAddLS/ReadMe.txt
r778 r1005 1 1 2 This is a simple tool that extracts an independent non-base layer from a multi-layer bitstream, converts it to a base-layer bistream and writes it to a file. The tool is invoked as follows.2 This a tool that either: 3 3 4 BLRewrite <infile> <outfile> <layer ID of the extracted layer>4 1. Extracts an independent non-base layer from a multi-layer bitstream, converts it to a base-layer bistream and writes it to a file. The extraction processs is defined in chapter F.10.2 of the HEVC version 2 specification. 5 5 6 The tool is based on the contribution JCTVC-Q0078 / JCTVC-R0042. Sub-bitstream extraction process done by the tool can be summarized as follows. 6 or 7 7 8 - NAL units with nal_unit_type not equal to SPS_NUT, PPS_NUT, EOS_NUT and EOB_NUT and with nuh_layer_id not equal to the assignedBaseLayerId are removed from outBitstream. 9 - NAL units with nal_unit_type equal to SPS_NUT, PPS_NUT, EOS_NUT or EOB_NUT with nuh_layer_id not equal to 0 are removed from outBitstream. 10 - For each NAL unit, the following applies: 11 When nuh_layer_id is equal to assignedBaseLayerId, nuh_layer_id is set equal to 0. 8 2. Extracts an additional layer set sub-bitstream from multi-layer bitstream and writes it to a file. The extraction processs is defined in chapter F.10.3 of the HEVC version 2 specification. 12 9 13 The resulting bitstream can be decoded with an HEVC/H.265 v1 compliant decoder as long as the extracted independent layer conform with v1 specification text. The tool removes VPS from the output bitstream so an HEVC/H.265 decoder should not expect it to be present. 10 11 The tool is invoked as follows: 12 13 ExtractAddLS <infile> <outfile> <Max temporal ID> <layer IDs of the extracted layers> 14 15 The process that is invoked is decided based on the number of IDs that are given in the layer ID list. If only one layer ID is given, independent non-base layer rewriting process is invoked. If more than one layer ID is given, sub-bitstream extraction for additional layer sets is invoked. 16 17 The result of independent non-base layer rewriting process can be decoded with an HEVC/H.265 v1 compliant decoder as long as the extracted independent layer conform with v1 specification text. The tool removes VPS from the output bitstream during rewriting so an HEVC/H.265 decoder should not expect it to be present. 14 18 15 19
Note: See TracChangeset for help on using the changeset viewer.