Created
August 12, 2017 07:16
-
-
Save yohhoy/8dddb1ed682156ccbb2b8edad2163b33 to your computer and use it in GitHub Desktop.
convert HEIC file to H.265 bitstream(Annex.B)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* heic2hevc.cpp -- convert HEIC file to H.265 bitstream(Annex.B) | |
* Copyright(c) 2017 yohhoy | |
* | |
* depends https://github.com/nokiatech/heif | |
*/ | |
#include <iostream> | |
#include "hevcimagefilereader.hpp" | |
int extract(const char* srcfile, const char* dstfile) | |
{ | |
std::cout << "convert " << srcfile << " to " << dstfile << std::endl; | |
HevcImageFileReader reader; | |
reader.initialize(srcfile); | |
const auto& props = reader.getFileProperties(); | |
const uint32_t contextId = props.rootLevelMetaBoxProperties.contextId; | |
HevcImageFileReader::IdVector ids; | |
reader.getItemListByType(contextId, "master", ids); | |
const uint32_t itemId = ids[0]; | |
std::cout << "itemId=" << itemId << std::endl; | |
HevcImageFileReader::ParameterSetMap paramset; | |
reader.getDecoderParameterSets(contextId, itemId, paramset); | |
HevcImageFileReader::DataVector bitstream; | |
reader.getItemDataWithDecoderParameters(contextId, itemId, bitstream); | |
std::ofstream ofs(dstfile, std::ios::binary); | |
for (const auto& key : {"VPS", "SPS", "PPS"}) { | |
const auto& nalu = paramset[key]; | |
std::cout << key << " len=" << nalu.size() << std::endl; | |
ofs.write((const char *)nalu.data(), nalu.size()); | |
} | |
std::cout << "bitstream=" << bitstream.size() << std::endl; | |
ofs.write((const char *)bitstream.data(), bitstream.size()); | |
return 0; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
if (argc < 3) { | |
std::cout | |
<< "Usage: heic2hevc <input.heic> <output.265>" << std::endl; | |
return 0; | |
} | |
return extract(argv[1], argv[2]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
move to https://github.com/yohhoy/heic2hevc