Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char **argv)
- {
- avcodec_register_all();
- if (argc != 2)
- return 1;
- try {
- AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
- if (!codec)
- throw std::runtime_error{ "no H264 decoder" };
- AVCodecContext_uptr avctx_uptr{ avcodec_alloc_context3(codec) };
- AVCodecContext *avctx = avctx_uptr.get();
- if (!avctx_uptr)
- throw std::runtime_error{ "error allocating H264 context" };
- if (avcodec_open2(avctx, codec, nullptr) < 0)
- throw std::runtime_error{ "error initializing H264 context" };
- AVCodecParserContext_uptr avparser_uptr{ av_parser_init(AV_CODEC_ID_H264) };
- AVCodecParserContext *avparser = avparser_uptr.get();
- if (!avparser_uptr)
- throw std::runtime_error{ "error initializing H264 parser" };
- const MemoryMappedFile file{ argv[1], MemoryMappedFile::READ_TAG };
- const uint8_t *data = static_cast<const uint8_t *>(file.read_ptr());
- size_t size = file.size();
- size_t offset = 0;
- int n = 0;
- while (size) {
- uint8_t *outbuf;
- int outbuf_size;
- int len = av_parser_parse2(avparser,
- avctx,
- &outbuf,
- &outbuf_size,
- data,
- size,
- AV_NOPTS_VALUE,
- AV_NOPTS_VALUE,
- 0);
- data += len;
- size -= len;
- if (outbuf_size) {
- std::cout << n++ << ',' << offset << ',' << outbuf_size << '\n';
- offset += outbuf_size;
- }
- }
- } catch (const std::exception &e) {
- std::cerr << e.what() << '\n';
- return 2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement