Ticket #62: ExtractAddLS.patch
File ExtractAddLS.patch, 3.6 KB (added by eeehey, 9 years ago) |
---|
-
ExtractAddLS.c
276 276 int tIdTarget = 6; 277 277 NalUnitHeader nalu; 278 278 int numStartCodeZeros; 279 int nalIs SpsPpsEob;279 int nalIsVpsSpsPpsEob; 280 280 int nalIsVpsSpsPpsEos; 281 281 int removeNal; 282 282 int layerIdListTarget[8]; … … 288 288 if (argc < 5 || argc > 10) 289 289 { 290 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"); 291 fprintf(stderr, " If only one layer ID 0 is given, base layer extration process is performed\n"); 292 fprintf(stderr, " If only one non-zero layer ID is given, independent non-base layer rewriting\n"); 293 fprintf(stderr, " process is performed\n"); 293 294 fprintf(stderr, " If more than one layer ID is given, sub-bitstream extraction process for\n"); 294 295 fprintf(stderr, " additional layer sets is performed (Layer ID list should exactly match\n"); 295 296 fprintf(stderr, " an additional layer set defined in VPS)\n"); … … 320 321 for (i = 4, layerIdx = 0; i < argc; i++, layerIdx++) 321 322 { 322 323 layerIdListTarget[layerIdx] = atoi(argv[i]); 323 if (layerIdListTarget[layerIdx] < 1|| layerIdListTarget[layerIdx] > 7)324 if (layerIdListTarget[layerIdx] < 0 || layerIdListTarget[layerIdx] > 7) 324 325 { 325 326 fprintf(stderr, "Invalid layer ID (must be in range 1-7)\n"); 326 327 exit(1); … … 344 345 345 346 if (numLayerIds == 1) 346 347 { 347 /* independent non-base layer rewriting process*/348 /* base layer or independent non-base layer bitstream extraction */ 348 349 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 350 /* temporary keep VPS so the extracted/rewriting bitstream can be decoded by HM */ 351 nalIsVpsSpsPpsEob = (nalu.nalUnitType == NAL_UNIT_VPS || nalu.nalUnitType == NAL_UNIT_SPS || nalu.nalUnitType == NAL_UNIT_PPS || nalu.nalUnitType == NAL_UNIT_EOB); 352 removeNal = (!nalIsVpsSpsPpsEob && (nalu.nuhLayerId != assignedBaseLayerId)) 353 || (nalIsVpsSpsPpsEob && (nalu.nuhLayerId != 0)) 354 || ((nalu.nuhTemporalIdPlus1 - 1) > tIdTarget); 356 355 nalu.nuhLayerId = 0; 357 356 } 358 357 else /* numLayerIds > 1 */ … … 402 401 403 402 i = 0; 404 403 405 if (numLayerIds >1 && nalu.nalUnitType == NAL_UNIT_VPS)404 if (numLayerIds == 1 && nalu.nalUnitType == NAL_UNIT_VPS) 406 405 { 406 char nalByte = fgetc(inFile); 407 nalByte = nalByte | (0x0C); // set vps_max_layers_minus1 bits(5-4) to 0 for HM decoder 408 nalByte = nalByte & ~(0x03); // set vps_max_layers_minus1 bits(3-0) to 0 for HM decoder 409 fputc(nalByte, outFile); 410 i++; 411 nalByte = fgetc(inFile); 412 nalByte = nalByte & ~(0xF0); 413 fputc(nalByte, outFile); 414 i++; 415 } 416 else if (numLayerIds > 1 && nalu.nalUnitType == NAL_UNIT_VPS) 417 { 407 418 /* sub-bitstream extraction process for additional layer sets */ 408 419 int nalByte = fgetc(inFile); 409 420 nalByte = nalByte & ~(0x04); /* vps_base_layer_available_flag in each VPS is set equal to 0 */