3
* Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
5
* This file is part of libde265.
7
* libde265 is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* libde265 is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with libde265. If not, see <http://www.gnu.org/licenses/>.
22
#include "libde265/nal-parser.h"
23
#include "libde265/decctx.h"
28
video_parameter_set vps;
29
seq_parameter_set sps;
30
pic_parameter_set pps;
32
CABAC_encoder_bitstream writer;
35
void process_nal(NAL_unit* nal)
37
de265_error err = DE265_OK;
40
bitreader_init(&reader, nal->data(), nal->size());
43
nal_hdr.read(&reader);
44
writer.write_startcode();
45
nal_hdr.write(writer);
47
printf("NAL: 0x%x 0x%x - unit type:%s temporal id:%d\n",
48
nal->data()[0], nal->data()[1],
49
get_NAL_name(nal_hdr.nal_unit_type),
50
nal_hdr.nuh_temporal_id);
53
if (nal_hdr.nal_unit_type<32) {
54
//err = read_slice_NAL(reader, nal, nal_hdr);
56
else switch (nal_hdr.nal_unit_type) {
57
case NAL_UNIT_VPS_NUT:
58
vps.read(&errqueue, &reader);
60
vps.write(&errqueue, writer);
64
case NAL_UNIT_SPS_NUT:
65
sps.read(&errqueue, &reader);
67
sps.write(&errqueue, writer);
71
case NAL_UNIT_PPS_NUT:
72
//err = read_pps_NAL(reader);
75
case NAL_UNIT_PREFIX_SEI_NUT:
76
case NAL_UNIT_SUFFIX_SEI_NUT:
77
//err = read_sei_NAL(reader, nal_hdr.nal_unit_type==NAL_UNIT_SUFFIX_SEI_NUT);
80
case NAL_UNIT_EOS_NUT:
81
//ctx->FirstAfterEndOfSequenceNAL = true;
87
int main(int argc, char** argv)
89
NAL_Parser nal_parser;
91
FILE* fh = fopen(argv[1],"rb");
92
unsigned char buf[1024];
94
writer.write_bits(0,8); // because HM has an extra byte at the beginning
98
int n = fread(buf,1,1024,fh);
100
nal_parser.push_data(buf,n, 0);
103
if (nal_parser.get_NAL_queue_length()>0) {
104
NAL_unit* nal = nal_parser.pop_from_NAL_queue();
107
nal_parser.free_NAL_unit(nal);
113
fh = fopen("out.bin","wb");
114
fwrite(writer.data(), 1,writer.size(), fh);