2 * Copyright (C) 2013 nu774
3 * For conditions of distribution and use, see copyright notice in COPYING
12 # include <inttypes.h>
13 #elif defined(_MSC_VER)
14 # define SCNd64 "I64d"
32 #define WIN32_LEAN_AND_MEAN
36 #include "wav_reader.h"
37 #include "caf_reader.h"
44 #define PROGNAME "fdkaac"
46 static volatile int g_interrupted
= 0;
49 static void signal_handler(int signum
)
53 static void handle_signals(void)
55 int i
, sigs
[] = { SIGINT
, SIGHUP
, SIGTERM
};
56 for (i
= 0; i
< sizeof(sigs
)/sizeof(sigs
[0]); ++i
) {
57 struct sigaction sa
= { 0 };
58 sa
.sa_handler
= signal_handler
;
59 sa
.sa_flags
|= SA_RESTART
;
60 sigaction(sigs
[i
], &sa
, 0);
64 static BOOL WINAPI
signal_handler(DWORD type
)
70 static void handle_signals(void)
72 SetConsoleCtrlHandler(signal_handler
, TRUE
);
75 static void handle_signals(void)
81 int read_callback(void *cookie
, void *data
, uint32_t size
)
83 size_t rc
= fread(data
, 1, size
, (FILE*)cookie
);
84 return ferror((FILE*)cookie
) ? -1 : (int)rc
;
88 int write_callback(void *cookie
, const void *data
, uint32_t size
)
90 size_t rc
= fwrite(data
, 1, size
, (FILE*)cookie
);
91 return ferror((FILE*)cookie
) ? -1 : (int)rc
;
95 int seek_callback(void *cookie
, int64_t off
, int whence
)
97 return fseeko((FILE*)cookie
, off
, whence
);
101 int64_t tell_callback(void *cookie
)
103 return ftello((FILE*)cookie
);
111 "Usage: " PROGNAME
" [options] input_file\n"
113 " -h, --help Print this help message\n"
114 " -p, --profile <n> Profile (audio object type)\n"
115 " 2: MPEG-4 AAC LC (default)\n"
116 " 5: MPEG-4 HE-AAC (SBR)\n"
117 " 29: MPEG-4 HE-AAC v2 (SBR+PS)\n"
118 " 23: MPEG-4 AAC LD\n"
119 " 39: MPEG-4 AAC ELD\n"
120 " 129: MPEG-2 AAC LC\n"
121 " 132: MPEG-2 HE-AAC (SBR)\n"
122 " 156: MPEG-2 HE-AAC v2 (SBR+PS)\n"
123 " -b, --bitrate <n> Bitrate in bits per seconds (for CBR)\n"
124 " -m, --bitrate-mode <n> Bitrate configuration\n"
125 " 0: CBR (default)\n"
127 " (VBR mode is not officially supported, and\n"
128 " works only on a certain combination of\n"
129 " parameter settings, sample rate, and\n"
130 " channel configuration)\n"
131 " -w, --bandwidth <n> Frequency bandwidth in Hz (AAC LC only)\n"
132 " -a, --afterburner <n> Afterburner\n"
135 " -L, --lowdelay-sbr Enable ELD-SBR (AAC ELD only)\n"
136 " -f, --transport-format <n> Transport format\n"
137 " 0: RAW (default, muxed into M4A)\n"
142 " 10: LOAS/LATM (LATM within LOAS)\n"
143 " -C, --adts-crc-check Add CRC protection on ADTS header\n"
144 " -h, --header-period <n> StreamMuxConfig/PCE repetition period in\n"
147 " -o <filename> Output filename\n"
148 " -G, --gapless-mode <n> Encoder delay signaling for gapless playback\n"
149 " 0: iTunSMPB (default)\n"
150 " 1: ISO standard (edts + sgpd)\n"
152 " -I, --ignorelength Ignore length of WAV header\n"
153 " -S, --silent Don't print progress messages\n"
154 " --moov-before-mdat Place moov box before mdat box on m4a output\n"
156 "Options for raw (headerless) input:\n"
157 " -R, --raw Treat input as raw (by default WAV is\n"
159 " --raw-channels <n> Number of channels (default: 2)\n"
160 " --raw-rate <n> Sample rate (default: 44100)\n"
161 " --raw-format <spec> Sample format, default is \"S16L\".\n"
162 " Spec is as follows:\n"
163 " 1st char: S(igned)|U(nsigned)|F(loat)\n"
164 " 2nd part: bits per channel\n"
165 " Last char: L(ittle)|B(ig)\n"
166 " Last char can be omitted, in which case L is\n"
167 " assumed. Spec is case insensitive, therefore\n"
168 " \"u16b\" is same as \"U16B\".\n"
171 " --title <string>\n"
172 " --artist <string>\n"
173 " --album <string>\n"
174 " --genre <string>\n"
176 " --composer <string>\n"
177 " --grouping <string>\n"
178 " --comment <string>\n"
179 " --album-artist <string>\n"
180 " --track <number[/total]>\n"
181 " --disk <number[/total]>\n"
183 " --tag <fcc>:<value> Set iTunes predefined tag with four char code.\n"
184 " --tag-from-file <fcc>:<filename>\n"
185 " Same as above, but value is read from file.\n"
186 " --long-tag <name>:<value> Set arbitrary tag as iTunes custom metadata.\n"
187 " --tag-from-json <filename[?dot_notation]>\n"
188 " Read tags from JSON. By default, tags are\n"
189 " assumed to be direct children of the root\n"
190 " object(dictionary).\n"
191 " Optionally, position of the dictionary\n"
192 " that contains tags can be specified with\n"
193 " dotted notation.\n"
195 " --tag-from-json /path/to/json?format.tags\n"
199 typedef struct aacenc_param_ex_t
{
202 char *input_filename
;
204 char *output_filename
;
206 unsigned gapless_mode
;
207 unsigned ignore_length
;
209 int moov_before_mdat
;
212 unsigned raw_channels
;
214 const char *raw_format
;
216 aacenc_tag_store_t tags
;
217 aacenc_tag_store_t source_tags
;
218 aacenc_translate_generic_text_tag_ctx_t source_tag_ctx
;
224 int parse_options(int argc
, char **argv
, aacenc_param_ex_t
*params
)
229 #define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
230 #define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
231 #define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
232 #define OPT_RAW_FORMAT M4AF_FOURCC('r','f','m','t')
233 #define OPT_SHORT_TAG M4AF_FOURCC('s','t','a','g')
234 #define OPT_SHORT_TAG_FILE M4AF_FOURCC('s','t','g','f')
235 #define OPT_LONG_TAG M4AF_FOURCC('l','t','a','g')
236 #define OPT_TAG_FROM_JSON M4AF_FOURCC('t','f','j','s')
238 static struct option long_options
[] = {
239 { "help", no_argument
, 0, 'h' },
240 { "profile", required_argument
, 0, 'p' },
241 { "bitrate", required_argument
, 0, 'b' },
242 { "bitrate-mode", required_argument
, 0, 'm' },
243 { "bandwidth", required_argument
, 0, 'w' },
244 { "afterburner", required_argument
, 0, 'a' },
245 { "lowdelay-sbr", no_argument
, 0, 'L' },
246 { "transport-format", required_argument
, 0, 'f' },
247 { "adts-crc-check", no_argument
, 0, 'C' },
248 { "header-period", required_argument
, 0, 'P' },
250 { "gapless-mode", required_argument
, 0, 'G' },
251 { "ignorelength", no_argument
, 0, 'I' },
252 { "silent", no_argument
, 0, 'S' },
253 { "moov-before-mdat", no_argument
, 0, OPT_MOOV_BEFORE_MDAT
},
255 { "raw", no_argument
, 0, 'R' },
256 { "raw-channels", required_argument
, 0, OPT_RAW_CHANNELS
},
257 { "raw-rate", required_argument
, 0, OPT_RAW_RATE
},
258 { "raw-format", required_argument
, 0, OPT_RAW_FORMAT
},
260 { "title", required_argument
, 0, M4AF_TAG_TITLE
},
261 { "artist", required_argument
, 0, M4AF_TAG_ARTIST
},
262 { "album", required_argument
, 0, M4AF_TAG_ALBUM
},
263 { "genre", required_argument
, 0, M4AF_TAG_GENRE
},
264 { "date", required_argument
, 0, M4AF_TAG_DATE
},
265 { "composer", required_argument
, 0, M4AF_TAG_COMPOSER
},
266 { "grouping", required_argument
, 0, M4AF_TAG_GROUPING
},
267 { "comment", required_argument
, 0, M4AF_TAG_COMMENT
},
268 { "album-artist", required_argument
, 0, M4AF_TAG_ALBUM_ARTIST
},
269 { "track", required_argument
, 0, M4AF_TAG_TRACK
},
270 { "disk", required_argument
, 0, M4AF_TAG_DISK
},
271 { "tempo", required_argument
, 0, M4AF_TAG_TEMPO
},
272 { "tag", required_argument
, 0, OPT_SHORT_TAG
},
273 { "tag-from-file", required_argument
, 0, OPT_SHORT_TAG_FILE
},
274 { "long-tag", required_argument
, 0, OPT_LONG_TAG
},
275 { "tag-from-json", required_argument
, 0, OPT_TAG_FROM_JSON
},
278 params
->afterburner
= 1;
280 aacenc_getmainargs(&argc
, &argv
);
281 while ((ch
= getopt_long(argc
, argv
, "hp:b:m:w:a:Ls:f:CP:G:Io:SR",
282 long_options
, 0)) != EOF
) {
287 if (sscanf(optarg
, "%u", &n
) != 1) {
288 fprintf(stderr
, "invalid arg for profile\n");
294 if (sscanf(optarg
, "%u", &n
) != 1) {
295 fprintf(stderr
, "invalid arg for bitrate\n");
301 if (sscanf(optarg
, "%u", &n
) != 1 || n
> 5) {
302 fprintf(stderr
, "invalid arg for bitrate-mode\n");
305 params
->bitrate_mode
= n
;
308 if (sscanf(optarg
, "%u", &n
) != 1) {
309 fprintf(stderr
, "invalid arg for bandwidth\n");
312 params
->bandwidth
= n
;
315 if (sscanf(optarg
, "%u", &n
) != 1 || n
> 1) {
316 fprintf(stderr
, "invalid arg for afterburner\n");
319 params
->afterburner
= n
;
322 params
->lowdelay_sbr
= 1;
325 if (sscanf(optarg
, "%u", &n
) != 1) {
326 fprintf(stderr
, "invalid arg for transport-format\n");
329 params
->transport_format
= n
;
332 params
->adts_crc_check
= 1;
335 if (sscanf(optarg
, "%u", &n
) != 1) {
336 fprintf(stderr
, "invalid arg for header-period\n");
339 params
->header_period
= n
;
342 params
->output_filename
= optarg
;
345 if (sscanf(optarg
, "%u", &n
) != 1 || n
> 2) {
346 fprintf(stderr
, "invalid arg for gapless-mode\n");
349 params
->gapless_mode
= n
;
352 params
->ignore_length
= 1;
357 case OPT_MOOV_BEFORE_MDAT
:
358 params
->moov_before_mdat
= 1;
363 case OPT_RAW_CHANNELS
:
364 if (sscanf(optarg
, "%u", &n
) != 1) {
365 fprintf(stderr
, "invalid arg for raw-channels\n");
368 params
->raw_channels
= n
;
371 if (sscanf(optarg
, "%u", &n
) != 1) {
372 fprintf(stderr
, "invalid arg for raw-rate\n");
375 params
->raw_rate
= n
;
378 params
->raw_format
= optarg
;
381 case M4AF_TAG_ARTIST
:
385 case M4AF_TAG_COMPOSER
:
386 case M4AF_TAG_GROUPING
:
387 case M4AF_TAG_COMMENT
:
388 case M4AF_TAG_ALBUM_ARTIST
:
392 aacenc_add_tag_to_store(¶ms
->tags
, ch
, 0, optarg
,
396 case OPT_SHORT_TAG_FILE
:
401 unsigned fcc
= M4AF_FOURCC('-','-','-','-');
403 if ((val
= strchr(optarg
, ':')) == 0) {
404 fprintf(stderr
, "invalid arg for tag\n");
408 if (ch
== OPT_SHORT_TAG
|| ch
== OPT_SHORT_TAG_FILE
) {
410 * take care of U+00A9(COPYRIGHT SIGN).
411 * 1) if length of fcc is 3, we prepend '\xa9'.
412 * 2) U+00A9 becomes "\xc2\xa9" in UTF-8. Therefore
413 * we remove first '\xc2'.
415 if (optarg
[0] == '\xc2')
417 if ((klen
= strlen(optarg
))== 3)
419 else if (klen
!= 4) {
420 fprintf(stderr
, "invalid arg for tag\n");
423 for (; *optarg
; ++optarg
)
424 fcc
= ((fcc
<< 8) | (*optarg
& 0xff));
426 aacenc_add_tag_to_store(¶ms
->tags
, fcc
, optarg
,
428 ch
== OPT_SHORT_TAG_FILE
);
431 case OPT_TAG_FROM_JSON
:
432 params
->json_filename
= optarg
;
441 if (!params
->bitrate
&& !params
->bitrate_mode
) {
442 fprintf(stderr
, "bitrate or bitrate-mode is mandatory\n");
445 if (params
->output_filename
&& !strcmp(params
->output_filename
, "-") &&
446 !params
->transport_format
) {
447 fprintf(stderr
, "stdout streaming is not available on M4A output\n");
450 if (params
->bitrate
&& params
->bitrate
< 10000)
451 params
->bitrate
*= 1000;
453 if (params
->is_raw
) {
454 if (!params
->raw_channels
)
455 params
->raw_channels
= 2;
456 if (!params
->raw_rate
)
457 params
->raw_rate
= 44100;
458 if (!params
->raw_format
)
459 params
->raw_format
= "S16L";
461 params
->input_filename
= argv
[optind
];
466 int write_sample(FILE *ofp
, m4af_ctx_t
*m4af
,
467 const void *data
, uint32_t size
, uint32_t duration
)
470 fwrite(data
, 1, size
, ofp
);
472 fprintf(stderr
, "ERROR: fwrite(): %s\n", strerror(errno
));
475 } else if (m4af_write_sample(m4af
, 0, data
, size
, duration
) < 0) {
476 fprintf(stderr
, "ERROR: failed to write m4a sample\n");
483 int encode(pcm_reader_t
*reader
, HANDLE_AACENCODER encoder
,
484 uint32_t frame_length
, FILE *ofp
, m4af_ctx_t
*m4af
,
494 int frames_written
= 0;
495 aacenc_progress_t progress
= { 0 };
496 const pcm_sample_description_t
*fmt
= pcm_get_format(reader
);
498 ibuf
= malloc(frame_length
* fmt
->bytes_per_frame
);
499 aacenc_progress_init(&progress
, pcm_get_length(reader
), fmt
->sample_rate
);
504 if ((nread
= pcm_read_frames(reader
, ibuf
, frame_length
)) < 0) {
505 fprintf(stderr
, "ERROR: read failed\n");
509 aacenc_progress_update(&progress
, pcm_get_position(reader
),
510 fmt
->sample_rate
* 2);
512 if ((consumed
= aac_encode_frame(encoder
, fmt
, ibuf
, nread
,
513 &obuf
, &olen
, &osize
)) < 0)
516 if (write_sample(ofp
, m4af
, obuf
, olen
, frame_length
) < 0)
520 } while (nread
> 0 || olen
> 0);
523 aacenc_progress_finish(&progress
, pcm_get_position(reader
));
526 if (ibuf
) free(ibuf
);
527 if (obuf
) free(obuf
);
532 void put_tool_tag(m4af_ctx_t
*m4af
, const aacenc_param_ex_t
*params
,
533 HANDLE_AACENCODER encoder
)
537 LIB_INFO
*lib_info
= 0;
539 p
+= sprintf(p
, PROGNAME
" %s, ", fdkaac_version
);
541 lib_info
= calloc(FDK_MODULE_LAST
, sizeof(LIB_INFO
));
542 if (aacEncGetLibInfo(lib_info
) == AACENC_OK
) {
544 for (i
= 0; i
< FDK_MODULE_LAST
; ++i
)
545 if (lib_info
[i
].module_id
== FDK_AACENC
)
547 p
+= sprintf(p
, "libfdk-aac %s, ", lib_info
[i
].versionStr
);
550 if (params
->bitrate_mode
)
551 sprintf(p
, "VBR mode %d", params
->bitrate_mode
);
553 sprintf(p
, "CBR %dkbps",
554 aacEncoder_GetParam(encoder
, AACENC_BITRATE
) / 1000);
556 m4af_add_itmf_string_tag(m4af
, M4AF_TAG_TOOL
, tool_info
);
560 int finalize_m4a(m4af_ctx_t
*m4af
, const aacenc_param_ex_t
*params
,
561 HANDLE_AACENCODER encoder
)
564 aacenc_tag_entry_t
*tag
;
566 tag
= params
->source_tags
.tag_table
;
567 for (i
= 0; i
< params
->source_tags
.tag_count
; ++i
, ++tag
)
568 aacenc_write_tag_entry(m4af
, tag
);
570 if (params
->json_filename
)
571 aacenc_write_tags_from_json(m4af
, params
->json_filename
);
573 tag
= params
->tags
.tag_table
;
574 for (i
= 0; i
< params
->tags
.tag_count
; ++i
, ++tag
)
575 aacenc_write_tag_entry(m4af
, tag
);
577 put_tool_tag(m4af
, params
, encoder
);
579 if (m4af_finalize(m4af
, params
->moov_before_mdat
) < 0) {
580 fprintf(stderr
, "ERROR: failed to finalize m4a\n");
587 char *generate_output_filename(const char *filename
, const char *ext
)
590 size_t ext_len
= strlen(ext
);
592 if (strcmp(filename
, "-") == 0) {
593 p
= malloc(ext_len
+ 6);
594 sprintf(p
, "stdin%s", ext
);
596 const char *base
= aacenc_basename(filename
);
597 size_t ilen
= strlen(base
);
598 const char *ext_org
= strrchr(base
, '.');
599 if (ext_org
) ilen
= ext_org
- base
;
600 p
= malloc(ilen
+ ext_len
+ 1);
601 sprintf(p
, "%.*s%s", ilen
, base
, ext
);
607 int parse_raw_spec(const char *spec
, pcm_sample_description_t
*desc
)
610 unsigned char c_type
, c_endian
= 'L';
613 if (sscanf(spec
, "%c%u%c", &c_type
, &bits
, &c_endian
) < 2)
615 c_type
= toupper(c_type
);
616 c_endian
= toupper(c_endian
);
620 else if (c_type
== 'U')
622 else if (c_type
== 'F')
629 else if (c_endian
!= 'L')
632 if (c_type
== 'F' && bits
!= 32 && bits
!= 64)
634 if (c_type
!= 'F' && (bits
< 8 || bits
> 32))
637 desc
->sample_type
= type
;
638 desc
->bits_per_channel
= bits
;
642 static pcm_io_vtbl_t pcm_io_vtbl
= {
643 read_callback
, seek_callback
, tell_callback
645 static pcm_io_vtbl_t pcm_io_vtbl_noseek
= { read_callback
, 0, 0 };
648 pcm_reader_t
*open_input(aacenc_param_ex_t
*params
)
650 pcm_io_context_t io
= { 0 };
651 pcm_reader_t
*reader
= 0;
652 struct stat stb
= { 0 };
654 if ((params
->input_fp
= aacenc_fopen(params
->input_filename
, "rb")) == 0) {
655 aacenc_fprintf(stderr
, "ERROR: %s: %s\n", params
->input_filename
,
659 io
.cookie
= params
->input_fp
;
660 if (fstat(fileno(params
->input_fp
), &stb
) == 0
661 && (stb
.st_mode
& S_IFMT
) == S_IFREG
)
662 io
.vtbl
= &pcm_io_vtbl
;
664 io
.vtbl
= &pcm_io_vtbl_noseek
;
666 if (params
->is_raw
) {
667 int bytes_per_channel
;
668 pcm_sample_description_t desc
= { 0 };
669 if (parse_raw_spec(params
->raw_format
, &desc
) < 0) {
670 fprintf(stderr
, "ERROR: invalid raw-format spec\n");
673 desc
.sample_rate
= params
->raw_rate
;
674 desc
.channels_per_frame
= params
->raw_channels
;
675 bytes_per_channel
= (desc
.bits_per_channel
+ 7) / 8;
676 desc
.bytes_per_frame
= params
->raw_channels
* bytes_per_channel
;
677 if ((reader
= raw_open(&io
, &desc
)) == 0) {
678 fprintf(stderr
, "ERROR: failed to open raw input\n");
683 ungetc(c
= getc(params
->input_fp
), params
->input_fp
);
687 if ((reader
= wav_open(&io
, params
->ignore_length
)) == 0) {
688 fprintf(stderr
, "ERROR: broken / unsupported input file\n");
693 params
->source_tag_ctx
.add
= aacenc_add_tag_entry_to_store
;
694 params
->source_tag_ctx
.add_ctx
= ¶ms
->source_tags
;
695 if ((reader
= caf_open(&io
,
696 aacenc_translate_generic_text_tag
,
697 ¶ms
->source_tag_ctx
)) == 0) {
698 fprintf(stderr
, "ERROR: broken / unsupported input file\n");
706 return pcm_open_sint16_converter(reader
);
711 int main(int argc
, char **argv
)
713 static m4af_io_callbacks_t m4af_io
= {
714 read_callback
, write_callback
, seek_callback
, tell_callback
716 aacenc_param_ex_t params
= { 0 };
719 char *output_filename
= 0;
720 pcm_reader_t
*reader
= 0;
721 HANDLE_AACENCODER encoder
= 0;
722 AACENC_InfoStruct aacinfo
= { 0 };
723 m4af_ctx_t
*m4af
= 0;
724 const pcm_sample_description_t
*sample_format
;
725 int downsampled_timescale
= 0;
729 setlocale(LC_CTYPE
, "");
732 if (parse_options(argc
, argv
, ¶ms
) < 0)
735 if ((reader
= open_input(¶ms
)) == 0)
738 sample_format
= pcm_get_format(reader
);
741 * We use explicit/hierarchical signaling for LOAS.
742 * Other than that, we request implicit signaling to FDK library, then
743 * append explicit/backward-compatible signaling to ASC in case of MP4FF.
745 * Explicit/backward-compatible signaling of SBR is the most recommended
746 * way in MPEG4 part3 spec, and seems the only way supported by iTunes.
747 * Since FDK library does not support it, we have to do it on our side.
749 params
.sbr_signaling
= (params
.transport_format
== TT_MP4_LOAS
) ? 2 : 0;
751 if (aacenc_init(&encoder
, (aacenc_param_t
*)¶ms
, sample_format
,
755 if (!params
.output_filename
) {
756 const char *ext
= params
.transport_format
? ".aac" : ".m4a";
757 output_filename
= generate_output_filename(params
.input_filename
, ext
);
758 params
.output_filename
= output_filename
;
761 if ((params
.output_fp
= aacenc_fopen(params
.output_filename
, "wb+")) == 0) {
762 aacenc_fprintf(stderr
, "ERROR: %s: %s\n", params
.output_filename
,
767 sbr_mode
= aacenc_is_sbr_active((aacenc_param_t
*)¶ms
);
768 if (!params
.transport_format
) {
771 uint32_t ascsize
= sizeof(mp4asc
);
772 unsigned framelen
= aacinfo
.frameLength
;
774 downsampled_timescale
= 1;
775 scale
= sample_format
->sample_rate
>> downsampled_timescale
;
776 if ((m4af
= m4af_create(M4AF_CODEC_MP4A
, scale
, &m4af_io
,
777 params
.output_fp
)) < 0)
779 aacenc_mp4asc((aacenc_param_t
*)¶ms
, aacinfo
.confBuf
,
780 aacinfo
.confSize
, mp4asc
, &ascsize
);
781 m4af_set_decoder_specific_info(m4af
, 0, mp4asc
, ascsize
);
782 m4af_set_fixed_frame_duration(m4af
, 0,
783 framelen
>> downsampled_timescale
);
784 m4af_set_vbr_mode(m4af
, 0, params
.bitrate_mode
);
785 m4af_set_priming_mode(m4af
, params
.gapless_mode
+ 1);
786 m4af_begin_write(m4af
);
788 frame_count
= encode(reader
, encoder
, aacinfo
.frameLength
,
789 params
.output_fp
, m4af
, !params
.silent
);
793 uint32_t delay
= aacinfo
.encoderDelay
;
794 int64_t frames_read
= pcm_get_position(reader
);
795 uint32_t padding
= frame_count
* aacinfo
.frameLength
796 - frames_read
- aacinfo
.encoderDelay
;
797 m4af_set_priming(m4af
, 0, delay
>> downsampled_timescale
,
798 padding
>> downsampled_timescale
);
799 if (finalize_m4a(m4af
, ¶ms
, encoder
) < 0)
804 if (reader
) pcm_teardown(&reader
);
805 if (params
.input_fp
) fclose(params
.input_fp
);
806 if (m4af
) m4af_teardown(&m4af
);
807 if (params
.output_fp
) fclose(params
.output_fp
);
808 if (encoder
) aacEncClose(&encoder
);
809 if (output_filename
) free(output_filename
);
810 if (params
.tags
.tag_table
)
811 aacenc_free_tag_store(¶ms
.tags
);
812 if (params
.source_tags
.tag_table
)
813 aacenc_free_tag_store(¶ms
.source_tags
);