2 * Copyright (c) 2003-2004, Fran�ois-Olivier Devaux
3 * Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
33 #ifndef DONT_HAVE_GETOPT
36 #include "compat/getopt.h"
38 #include "mj2_convert.h"
42 printf("HELP\n----\n\n");
43 printf("- the -h option displays this help information on screen\n\n");
46 printf("List of parameters for the coder JPEG 2000:\n");
49 printf("---------\n");
52 ("The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
54 ("COD and QCD never appear in the tile_header.\n");
57 ("- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
59 ("color image. You need enough disk space memory (twice the original) to encode \n");
61 ("the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n");
63 printf("By default:\n");
64 printf("------------\n");
66 printf(" * Lossless\n");
67 printf(" * 1 tile\n");
68 printf(" * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n");
69 printf(" * Size of code-block : 64 x 64\n");
70 printf(" * Number of resolutions: 6\n");
71 printf(" * No SOP marker in the codestream\n");
72 printf(" * No EPH marker in the codestream\n");
73 printf(" * No sub-sampling in x or y direction\n");
74 printf(" * No mode switch activated\n");
75 printf(" * Progression order: LRCP\n");
76 printf(" * No index file\n");
77 printf(" * No ROI upshifted\n");
78 printf(" * No offset of the origin of the image\n");
79 printf(" * No offset of the origin of the tiles\n");
80 printf(" * Reversible DWT 5-3\n");
82 printf("Parameters:\n");
83 printf("------------\n");
86 ("Required Parameters (except with -h):\n");
89 ("-i : source file (-i source.yuv) \n");
92 ("-o : destination file (-o dest.mj2) \n");
95 ("Optional Parameters:\n");
97 printf("-h : display the help information \n ");
99 printf("-r : different compression ratios for successive layers (-r 20,10,5)\n ");
100 printf(" - The rate specified for each quality level is the desired \n");
101 printf(" compression factor.\n");
102 printf(" Example: -r 20,10,1 means quality 1: compress 20x, \n");
103 printf(" quality 2: compress 10x and quality 3: compress lossless\n");
105 printf(" (options -r and -q cannot be used together)\n ");
108 printf("-q : different psnr for successive layers (-q 30,40,50) \n ");
110 printf(" (options -r and -q cannot be used together)\n ");
113 printf("-n : number of resolutions (-n 3) \n");
115 printf("-b : size of code block (-b 32,32) \n");
117 printf("-c : size of precinct (-c 128,128) \n");
119 printf("-t : size of tile (-t 512,512) \n");
122 ("-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n");
125 ("-s : subsampling factor (-s 2,2) [-s X,Y] \n");
126 printf(" Remark: subsampling bigger than 2 can produce error\n");
129 ("-SOP : write SOP marker before each packet \n");
132 ("-EPH : write EPH marker after each header packet \n");
135 ("-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
137 (" 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n");
139 (" Indicate multiple modes by adding their values. \n");
141 (" ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
144 ("-x : create an index file *.Idx (-x index_name.Idx) \n");
147 ("-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
149 (" for component c=%%d [%%d = 0,1,2]\n");
151 (" with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n");
154 ("-d : offset of the origin of the image (-d 150,300) \n");
157 ("-T : offset of the origin of the tiles (-T 100,75) \n");
159 printf("-I : use the irreversible DWT 9-7 (-I) \n");
161 printf("-W : image width, height and the dx and dy subsampling \n");
162 printf(" of the Cb and Cr components for YUV files \n");
163 printf(" (default is '352,288,2,2' for CIF format's 352x288 and 4:2:0)\n");
165 printf("-F : video frame rate (set to 25 by default)\n");
168 printf("IMPORTANT:\n");
169 printf("-----------\n");
171 printf("The index file has the structure below:\n");
172 printf("---------------------------------------\n");
174 printf("Image_height Image_width\n");
175 printf("progression order\n");
176 printf("Tiles_size_X Tiles_size_Y\n");
177 printf("Components_nb\n");
178 printf("Layers_nb\n");
179 printf("decomposition_levels\n");
180 printf("[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n");
181 printf(" [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n");
182 printf("Main_header_end_position\n");
183 printf("Codestream_size\n");
184 printf("Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n");
185 printf("Tile_1 '' '' '' '' '' ''\n");
187 printf("Tile_Nt '' '' '' '' '' ''\n");
188 printf("Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
190 printf("Tpacket_Np '' '' '' '' '' '' '' ''\n");
192 printf("MaxDisto\n");
194 printf("TotalDisto\n\n");
197 int give_progression(char progression[4])
199 if (progression[0] == 'L' && progression[1] == 'R'
200 && progression[2] == 'C' && progression[3] == 'P') {
203 if (progression[0] == 'R' && progression[1] == 'L'
204 && progression[2] == 'C' && progression[3] == 'P') {
207 if (progression[0] == 'R' && progression[1] == 'P'
208 && progression[2] == 'C' && progression[3] == 'L') {
211 if (progression[0] == 'P' && progression[1] == 'C'
212 && progression[2] == 'R' && progression[3] == 'L') {
215 if (progression[0] == 'C' && progression[1] == 'P'
216 && progression[2] == 'R' && progression[3] == 'L') {
227 double dwt_norms_97[4][10] = {
228 {1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
229 {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
230 {2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
231 {2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
237 for (l = 0; a > 1; l++) {
243 void encode_stepsize(int stepsize, int numbps, int *expn, int *mant)
246 p = floorlog2(stepsize) - 13;
247 n = 11 - floorlog2(stepsize);
248 *mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
252 void calc_explicit_stepsizes(j2k_tccp_t * tccp, int prec)
254 int numbands, bandno;
255 numbands = 3 * tccp->numresolutions - 2;
256 for (bandno = 0; bandno < numbands; bandno++) {
259 int resno, level, orient, gain;
260 resno = bandno == 0 ? 0 : (bandno - 1) / 3 + 1;
261 orient = bandno == 0 ? 0 : (bandno - 1) % 3 + 1;
262 level = tccp->numresolutions - 1 - resno;
264 tccp->qmfbid == 0 ? 0 : (orient ==
266 || orient == 2 ? 1 : 2));
267 if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
270 double norm = dwt_norms_97[orient][level];
271 stepsize = (1 << (gain + 1)) / norm;
273 encode_stepsize((int) floor(stepsize * 8192.0), prec + gain,
274 &tccp->stepsizes[bandno].expn,
275 &tccp->stepsizes[bandno].mant);
279 int main(int argc, char **argv)
281 int NumResolution, numD_min; /* NumResolution : number of resolution */
282 int Tile_arg; /* Tile_arg = 0 (not in argument) ou = 1 (in argument) */
283 int CSty; /* CSty : coding style */
284 int Prog_order; /* progression order (default LRCP) */
286 int numpocs, numpocs_tile; /* Number of progression order change (POC) default 0 */
287 int prcw_init[J2K_MAXRLVLS]; /* Initialisation Precinct width */
288 int prch_init[J2K_MAXRLVLS]; /* Initialisation Precinct height */
289 //int prcw_init, prch_init; /* Initialisation precincts' size */
290 int cblockw_init, cblockh_init; /* Initialisation codeblocks' size */
291 int mode, value; /* Mode switch (cblk_style) */
292 int subsampling_dx, subsampling_dy; /* subsampling value for dx and dy */
293 int ROI_compno, ROI_shift; /* region of interrest */
294 int Dim[2]; /* portion of the image coded */
295 int TX0, TY0; /* tile off-set */
297 j2k_cp_t cp, cp_init; /* cp_init is used to initialise in multiple tiles */
298 j2k_tcp_t *tcp, *tcp_init; /* tcp_init is used to initialise in multiple tile */
299 j2k_poc_t POC[32]; /* POC : used in case of Progression order change */
308 int res_spec = 0; /* For various precinct sizes specification */
310 int w; /* Width of YUV file */
311 int h; /* Height of YUV file */
312 int CbCr_subsampling_dx; /* Sample rate of YUV 4:4:4 4:2:2 or 4:2:0 */
313 int CbCr_subsampling_dy; /* Sample rate of YUV 4:4:4 4:2:2 or 4:2:0 */
314 int output_image_type = -1;
315 int frame_rate; /* Video Frame Rate */
316 int numcomps; /* In YUV files, numcomps always considered as 3 */
317 int prec; /* In YUV files, precision always considered as 8 */
335 ROI_compno = -1; /* no ROI */
344 cp.fixed_quality = 0; //add fixed_quality
345 w = 352; // CIF default value
346 h = 288; // CIF default value
347 CbCr_subsampling_dx = 2; // CIF default value
348 CbCr_subsampling_dy = 2; // CIF default value
353 cp_init.tcps = (j2k_tcp_t *) malloc(sizeof(j2k_tcp_t)); /* initialisation if only one tile */
354 tcp_init = &cp_init.tcps[0];
355 tcp_init->numlayers = 0;
357 cp.intermed_file = 0; // Don't store each tile in a file during processing
360 int c = getopt(argc, argv,
361 "i:o:r:q:f:t:n:c:b:x:p:s:d:h:P:S:E:M:R:T:C:I:W:F:");
365 case 'i': /* IN fill */
378 if ((S1 == 'y' && S2 == 'u' && S3 == 'v')
379 || (S1 == 'Y' && S2 == 'U' && S3 == 'V')) {
384 "!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n",
388 /* ----------------------------------------------------- */
389 case 'o': /* OUT fill */
403 if ((S1 == 'm' && S2 == 'j' && S3 == '2')
404 || (S1 == 'M' && S2 == 'J' && S3 == '2'))
405 cp.JPEG2000_format = 2;
408 "Unknown output format image *.%c%c%c [only *.mj2]!! \n",
416 /* ----------------------------------------------------- */
417 case 'r': /* rates rates/distorsion */
419 while (sscanf(s, "%d", &tcp_init->rates[tcp_init->numlayers])
421 tcp_init->numlayers++;
422 while (*s && *s != ',') {
432 /* ----------------------------------------------------- */
433 case 'q': /* add fixed_quality */
436 (s, "%f", &tcp_init->distoratio[tcp_init->numlayers]) == 1) {
437 tcp_init->numlayers++;
438 while (*s && *s != ',') {
445 cp.fixed_quality = 1;
449 /* ----------------------------------------------------- */
450 case 'f': /* mod fixed_quality (before : -q) */
452 sscanf(s, "%d", &tcp_init->numlayers);
454 if (tcp_init->numlayers > 9)
457 (int *) malloc(tcp_init->numlayers * NumResolution * 3 *
460 for (i = 0; i < tcp_init->numlayers; i++) {
461 tcp_init->rates[i] = 1;
462 sscanf(s, "%d,", &cp.matrice[i * NumResolution * 3]);
464 if (cp.matrice[i * NumResolution * 3] > 9)
466 cp.matrice[i * NumResolution * 3 + 1] = 0;
467 cp.matrice[i * NumResolution * 3 + 2] = 0;
468 for (j = 1; j < NumResolution; j++) {
469 sscanf(s, "%d,%d,%d",
470 &cp.matrice[i * NumResolution * 3 + j * 3 + 0],
471 &cp.matrice[i * NumResolution * 3 + j * 3 + 1],
472 &cp.matrice[i * NumResolution * 3 + j * 3 + 2]);
474 if (cp.matrice[i * NumResolution * 3 + j * 3] > 9)
476 if (cp.matrice[i * NumResolution * 3 + j * 3 + 1] > 9)
478 if (cp.matrice[i * NumResolution * 3 + j * 3 + 2] > 9)
481 if (i < tcp_init->numlayers - 1)
486 /* ----------------------------------------------------- */
487 case 't': /* tiles */
488 sscanf(optarg, "%d,%d", &cp.tdx, &cp.tdy);
491 /* ----------------------------------------------------- */
492 case 'n': /* resolution */
493 sscanf(optarg, "%d", &NumResolution);
495 /* ----------------------------------------------------- */
496 case 'c': /* precinct dimension */
500 sscanf(s, "[%d,%d]%c", &prcw_init[res_spec],
501 &prch_init[res_spec], &sep);
504 s = strpbrk(s, "]") + 2;
505 } while (sep == ',');
507 /* ----------------------------------------------------- */
508 case 'b': /* code-block dimension */
509 sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
510 if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
511 || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
513 "!! Size of code_block error (option -b) !!\n\nRestriction :\n * width*height<=4096\n * 4<=width,height<= 1024\n\n");
517 /* ----------------------------------------------------- */
518 case 'x': /* creation of index file */
522 /* ----------------------------------------------------- */
523 case 'p': /* progression order */
525 for (i = 0; i < 4; i++) {
529 Prog_order = give_progression(progression);
531 if (Prog_order == -1) {
533 "Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
537 /* ----------------------------------------------------- */
538 case 's': /* subsampling factor */
539 if (sscanf(optarg, "%d,%d", &subsampling_dx, &subsampling_dy)
542 "'-s' sub-sampling argument error ! [-s dx,dy]\n");
546 /* ----------------------------------------------------- */
547 case 'd': /* coordonnate of the reference grid */
548 if (sscanf(optarg, "%d,%d", &Dim[0], &Dim[1]) != 2) {
550 "-d 'coordonnate of the reference grid' argument error !! [-d x0,y0]\n");
554 /* ----------------------------------------------------- */
555 case 'h': /* Display an help description */
559 /* ----------------------------------------------------- */
561 fprintf(stderr, "/----------------------------------\\\n");
562 fprintf(stderr, "| POC option not fully tested !! |\n");
563 fprintf(stderr, "\\----------------------------------/\n");
566 while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile,
567 &POC[numpocs].resno0, &POC[numpocs].compno0,
568 &POC[numpocs].layno1, &POC[numpocs].resno1,
569 &POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
570 POC[numpocs].prg = give_progression(POC[numpocs].progorder);
571 /* POC[numpocs].tile; */
573 while (*s && *s != '/') {
581 /* ------------------------------------------------------ */
582 case 'S': /* SOP marker */
585 /* ------------------------------------------------------ */
586 case 'E': /* EPH marker */
589 /* ------------------------------------------------------ */
590 case 'M': /* Mode switch pas tous au point !! */
591 if (sscanf(optarg, "%d", &value) == 1) {
592 for (i = 0; i <= 5; i++) {
593 int cache = value & (1 << i);
599 /* ------------------------------------------------------ */
601 if (sscanf(optarg, "OI:c=%d,U=%d", &ROI_compno, &ROI_shift) != 2) {
602 fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
606 /* ------------------------------------------------------ */
607 case 'T': /* Tile offset */
608 if (sscanf(optarg, "%d,%d", &TX0, &TY0) != 2) {
609 fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
613 /* ------------------------------------------------------ */
614 case 'C': /* Add a comment */
617 /* ------------------------------------------------------ */
618 case 'I': /* reversible or not */
621 /* ------------------------------------------------------ */
622 case 'W': /* Width and Height and Cb and Cr subsampling in case of YUV format files */
624 (optarg, "%d,%d,%d,%d", &w, &h, &CbCr_subsampling_dx,
625 &CbCr_subsampling_dy) != 4) {
626 fprintf(stderr, "-W argument error");
630 /* ------------------------------------------------------ */
631 case 'F': /* Video frame rate */
632 if (sscanf(optarg, "%d", &frame_rate) != 1) {
633 fprintf(stderr, "-F argument error");
637 /* ------------------------------------------------------ */
648 if (!infile || !outfile) {
650 "usage: frames_to_mj2 -i yuv-file -o mj2-file (+ options)\n");
654 if ((cp.disto_alloc || cp.fixed_alloc || cp.fixed_quality)
655 && (!(cp.disto_alloc ^ cp.fixed_alloc ^ cp.fixed_quality))) {
657 "Error: options -r -q and -f can not be used together !!\n");
659 } // mod fixed_quality
661 /* if no rate entered, lossless by default */
662 if (tcp_init->numlayers == 0) {
663 tcp_init->rates[tcp_init->numlayers] = 0; //MOD antonin : losslessbug
664 tcp_init->numlayers++;
668 if (TX0 > Dim[0] || TY0 > Dim[1]) {
670 "Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
671 TX0, Dim[0], TY0, Dim[1]);
675 for (i = 0; i < numpocs; i++) {
676 if (POC[i].prg == -1) {
678 "Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n",
683 /* to respect profile - 0 */
684 /* ---------------------- */
687 x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
690 y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
695 cp.tw = int_ceildiv(x1 - cp.tx0, cp.tdx);
696 cp.th = int_ceildiv(y1 - cp.ty0, cp.tdy);
698 cp.tdx = x1 - cp.tx0;
699 cp.tdy = y1 - cp.ty0;
703 /* Initialization for PPM marker */
709 numcomps = 3; /* Because YUV files only have 3 components */
711 tcp_init->mct = 0; /* No component transform needed */
713 prec = 8; /* Because in YUV files, components have 8-bit depth */
715 /* Init the mutiple tiles */
716 /* ---------------------- */
717 cp.tcps = (j2k_tcp_t *) malloc(cp.tw * cp.th * sizeof(j2k_tcp_t));
719 for (tileno = 0; tileno < cp.tw * cp.th; tileno++) {
720 tcp = &cp.tcps[tileno];
721 tcp->numlayers = tcp_init->numlayers;
722 for (j = 0; j < tcp->numlayers; j++) {
723 if (cp.fixed_quality) // add fixed_quality
724 tcp->distoratio[j] = tcp_init->distoratio[j];
726 tcp->rates[j] = tcp_init->rates[j];
729 tcp->prg = Prog_order;
730 tcp->mct = tcp_init->mct;
732 tcp->ppt_data = NULL;
738 /* intialisation of POC */
740 for (i = 0; i < numpocs; i++) {
741 if (tileno == POC[i].tile - 1 || POC[i].tile == -1) {
742 tcp_poc = &tcp->pocs[numpocs_tile];
743 tcp_poc->resno0 = POC[numpocs_tile].resno0;
744 tcp_poc->compno0 = POC[numpocs_tile].compno0;
745 tcp_poc->layno1 = POC[numpocs_tile].layno1;
746 tcp_poc->resno1 = POC[numpocs_tile].resno1;
747 tcp_poc->compno1 = POC[numpocs_tile].compno1;
748 tcp_poc->prg = POC[numpocs_tile].prg;
749 tcp_poc->tile = POC[numpocs_tile].tile;
754 tcp->numpocs = numpocs_tile;
755 tcp->tccps = (j2k_tccp_t *) malloc(numcomps * sizeof(j2k_tccp_t));
757 for (i = 0; i < numcomps; i++) {
758 tccp = &tcp->tccps[i];
759 tccp->csty = CSty & 0x01; /* 0 => one precinct || 1 => custom precinct */
760 tccp->numresolutions = NumResolution;
761 tccp->cblkw = int_floorlog2(cblockw_init);
762 tccp->cblkh = int_floorlog2(cblockh_init);
763 tccp->cblksty = mode;
764 tccp->qmfbid = ir ? 0 : 1;
765 tccp->qntsty = ir ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
768 tccp->roishift = ROI_shift;
771 if (CSty & J2K_CCP_CSTY_PRT) {
773 for (j = tccp->numresolutions - 1; j >= 0; j--) {
775 if (prcw_init[p] < 1)
778 tccp->prcw[j] = int_floorlog2(prcw_init[p]);
780 if (prch_init[p] < 1)
783 tccp->prch[j] = int_floorlog2(prch_init[p]);
785 int size_prcw, size_prch;
786 size_prcw = prcw_init[res_spec - 1] >> (p - (res_spec - 1));
787 size_prch = prch_init[res_spec - 1] >> (p - (res_spec - 1));
791 tccp->prcw[j] = int_floorlog2(size_prcw);
795 tccp->prch[j] = int_floorlog2(size_prch);
798 /*printf("\nsize precinct pour level %d : %d,%d\n", j,
799 tccp->prcw[j], tccp->prch[j]); */
802 for (j = 0; j < tccp->numresolutions; j++) {
807 calc_explicit_stepsizes(tccp, prec);
811 movie.tk = (mj2_tk_t *) malloc(sizeof(mj2_tk_t));
816 movie.tk[0].imagefile = infile;
817 movie.tk[0].track_type = 0; // Video Track
818 movie.tk[0].track_ID = 1;
819 movie.mj2file = outfile;
820 movie.tk[0].subsampling_dx = subsampling_dx;
821 movie.tk[0].subsampling_dy = subsampling_dy;
822 movie.tk[0].Dim[0] = Dim[0];
823 movie.tk[0].Dim[1] = Dim[1];
826 movie.tk[0].CbCr_subsampling_dx = CbCr_subsampling_dx;
827 movie.tk[0].CbCr_subsampling_dy = CbCr_subsampling_dy;
828 movie.tk[0].sample_rate = frame_rate;
830 if (mj2_init_stdmovie(&movie)) {
831 fprintf(stderr, "Error with movie initialization");
834 if (mj2_encode(&movie, &cp, index)) {
835 fprintf(stderr, "Error encoding movie");
838 mj2_memory_free(&movie);
842 if (tcp_init->numlayers > 9)
844 for (tileno = 0; tileno < cp.tw * cp.th; tileno++)
845 free(cp.tcps[tileno].tccps);