" transport layer\n"
"\n"
" -o <filename> Output filename\n"
-" --ignore-length Ignore length of WAV header\n"
+" --ignorelength Ignore length of WAV header\n"
+" -S, --silent Don't print progress messages\n"
"\n"
"Options for raw (headerless) input:\n"
" -R, --raw Treat input as raw (by default WAV is\n"
" --disk <number[/total]>\n"
" --tempo <n>\n"
" --tag <fcc>:<value> Set iTunes predefined tag with four char code.\n"
+" --tag-from-file <fcc>:<filename>\n"
+" Same as above, but value is read from file.\n"
" --long-tag <name>:<value> Set arbitrary tag as iTunes custom metadata.\n"
, fdkaac_version);
}
const char *name;
const char *data;
uint32_t data_size;
+ int is_file_name;
} aacenc_tag_entry_t;
typedef struct aacenc_param_ex_t {
char *input_filename;
char *output_filename;
unsigned ignore_length;
+ int silent;
int is_raw;
unsigned raw_channels;
static
void param_add_itmf_entry(aacenc_param_ex_t *params, uint32_t tag,
- const char *key, const char *value, uint32_t size)
+ const char *key, const char *value, uint32_t size,
+ int is_file_name)
{
aacenc_tag_entry_t *entry;
if (params->tag_count == params->tag_table_capacity) {
entry->name = key;
entry->data = value;
entry->data_size = size;
+ entry->is_file_name = is_file_name;
params->tag_count++;
}
int ch;
unsigned n;
-#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
-#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
-#define OPT_RAW_FORMAT M4AF_FOURCC('r','f','m','t')
-#define OPT_SHORT_TAG M4AF_FOURCC('s','t','a','g')
-#define OPT_LONG_TAG M4AF_FOURCC('l','t','a','g')
+#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
+#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
+#define OPT_RAW_FORMAT M4AF_FOURCC('r','f','m','t')
+#define OPT_SHORT_TAG M4AF_FOURCC('s','t','a','g')
+#define OPT_SHORT_TAG_FILE M4AF_FOURCC('s','t','g','f')
+#define OPT_LONG_TAG M4AF_FOURCC('l','t','a','g')
static struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "adts-crc-check", no_argument, 0, 'C' },
{ "header-period", required_argument, 0, 'P' },
- { "ignore-length", no_argument, 0, 'I' },
+ { "ignorelength", no_argument, 0, 'I' },
+ { "silent", no_argument, 0, 'S' },
{ "raw", no_argument, 0, 'R' },
{ "raw-channels", required_argument, 0, OPT_RAW_CHANNELS },
{ "disk", required_argument, 0, M4AF_TAG_DISK },
{ "tempo", required_argument, 0, M4AF_TAG_TEMPO },
{ "tag", required_argument, 0, OPT_SHORT_TAG },
+ { "tag-from-file", required_argument, 0, OPT_SHORT_TAG_FILE },
{ "long-tag", required_argument, 0, OPT_LONG_TAG },
+ { 0, 0, 0, 0 },
};
params->afterburner = 1;
aacenc_getmainargs(&argc, &argv);
- while ((ch = getopt_long(argc, argv, "hp:b:m:w:a:Ls:f:CP:Io:R",
+ while ((ch = getopt_long(argc, argv, "hp:b:m:w:a:Ls:f:CP:Io:SR",
long_options, 0)) != EOF) {
switch (ch) {
case 'h':
case 'I':
params->ignore_length = 1;
break;
+ case 'S':
+ params->silent = 1;
+ break;
case 'R':
params->is_raw = 1;
break;
case M4AF_TAG_TRACK:
case M4AF_TAG_DISK:
case M4AF_TAG_TEMPO:
- param_add_itmf_entry(params, ch, 0, optarg, strlen(optarg));
+ param_add_itmf_entry(params, ch, 0, optarg, strlen(optarg), 0);
break;
case OPT_SHORT_TAG:
+ case OPT_SHORT_TAG_FILE:
case OPT_LONG_TAG:
{
char *val;
return -1;
}
*val++ = '\0';
- if (ch == OPT_SHORT_TAG) {
+ if (ch == OPT_SHORT_TAG || ch == OPT_SHORT_TAG_FILE) {
+ /*
+ * take care of U+00A9(COPYRIGHT SIGN).
+ * 1) if length of fcc is 3, we prepend '\xa9'.
+ * 2) U+00A9 becomes "\xc2\xa9" in UTF-8. Therefore
+ * we remove first '\xc2'.
+ */
+ if (optarg[0] == '\xc2')
+ ++optarg;
if ((klen = strlen(optarg))== 3)
fcc = 0xa9;
else if (klen != 4) {
for (; *optarg; ++optarg)
fcc = ((fcc << 8) | (*optarg & 0xff));
}
- param_add_itmf_entry(params, fcc, optarg, val, strlen(val));
+ param_add_itmf_entry(params, fcc, optarg, val, strlen(val),
+ ch == OPT_SHORT_TAG_FILE);
}
break;
default:
static
int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
- uint32_t frame_length, FILE *ofp, m4af_writer_t *m4af)
+ uint32_t frame_length, FILE *ofp, m4af_writer_t *m4af,
+ int show_progress)
{
uint8_t *ibuf = 0;
int16_t *pcmbuf = 0;
goto END;
}
}
- aacenc_progress_update(&progress, wav_get_position(wavf),
- format->sample_rate * 2);
+ if (show_progress)
+ aacenc_progress_update(&progress, wav_get_position(wavf),
+ format->sample_rate * 2);
}
if ((consumed = aac_encode_frame(encoder, format, pcmbuf, nread,
&obuf, &olen, &osize)) < 0)
++frames_written;
}
} while (nread > 0 || olen > 0);
- aacenc_progress_finish(&progress, wav_get_position(wavf));
+
+ if (show_progress)
+ aacenc_progress_finish(&progress, wav_get_position(wavf));
rc = frames_written;
END:
if (ibuf) free(ibuf);
}
static
-int put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
+char *load_tag_from_file(const char *path, uint32_t *data_size)
+{
+ FILE *fp = 0;
+ char *data = 0;
+ int64_t size;
+
+ if ((fp = aacenc_fopen(path, "rb")) == NULL) {
+ aacenc_fprintf(stderr, "WARNING: %s: %s\n", path, strerror(errno));
+ goto END;
+ }
+ fseeko(fp, 0, SEEK_END);
+ size = ftello(fp);
+ if (size > 5*1024*1024) {
+ aacenc_fprintf(stderr, "WARNING: %s: size too large\n", path);
+ goto END;
+ }
+ fseeko(fp, 0, SEEK_SET);
+ data = malloc(size + 1);
+ if (data) fread(data, 1, size, fp);
+ data[size] = 0;
+ *data_size = (uint32_t)size;
+END:
+ if (fp) fclose(fp);
+ return data;
+}
+
+static
+void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
{
unsigned m, n = 0;
+ const char *data = tag->data;
+ uint32_t data_size = tag->data_size;
+ char *file_contents = 0;
+ if (tag->is_file_name) {
+ data = file_contents = load_tag_from_file(tag->data, &data_size);
+ if (!data) return;
+ }
switch (tag->tag) {
case M4AF_TAG_TRACK:
- if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
+ if (sscanf(data, "%u/%u", &m, &n) >= 1)
m4af_add_itmf_track_tag(m4af, m, n);
break;
case M4AF_TAG_DISK:
- if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
+ if (sscanf(data, "%u/%u", &m, &n) >= 1)
m4af_add_itmf_disk_tag(m4af, m, n);
break;
case M4AF_TAG_GENRE_ID3:
- if (sscanf(tag->data, "%u", &n) == 1)
+ if (sscanf(data, "%u", &n) == 1)
m4af_add_itmf_genre_tag(m4af, n);
break;
case M4AF_TAG_TEMPO:
- if (sscanf(tag->data, "%u", &n) == 1)
+ if (sscanf(data, "%u", &n) == 1)
m4af_add_itmf_int16_tag(m4af, tag->tag, n);
break;
case M4AF_TAG_COMPILATION:
case M4AF_FOURCC('p','g','a','p'):
case M4AF_FOURCC('r','t','n','g'):
case M4AF_FOURCC('s','t','i','k'):
- if (sscanf(tag->data, "%u", &n) == 1)
+ if (sscanf(data, "%u", &n) == 1)
m4af_add_itmf_int8_tag(m4af, tag->tag, n);
break;
case M4AF_FOURCC('a','t','I','D'):
case M4AF_FOURCC('s','f','I','D'):
case M4AF_FOURCC('t','v','s','n'):
case M4AF_FOURCC('t','v','s','s'):
- if (sscanf(tag->data, "%u", &n) == 1)
+ if (sscanf(data, "%u", &n) == 1)
m4af_add_itmf_int32_tag(m4af, tag->tag, n);
break;
case M4AF_FOURCC('p','l','I','D'):
{
int64_t qn;
- if (sscanf(tag->data, "%" SCNd64, &qn) == 1)
+ if (sscanf(data, "%" SCNd64, &qn) == 1)
m4af_add_itmf_int64_tag(m4af, tag->tag, qn);
break;
}
case M4AF_TAG_ARTWORK:
{
int data_type = 0;
- if (!memcmp(tag->data, "GIF", 3))
+ if (!memcmp(data, "GIF", 3))
data_type = M4AF_GIF;
- else if (!memcmp(tag->data, "\xff\xd8\xff", 3))
+ else if (!memcmp(data, "\xff\xd8\xff", 3))
data_type = M4AF_JPEG;
- else if (!memcmp(tag->data, "\x89PNG", 4))
+ else if (!memcmp(data, "\x89PNG", 4))
data_type = M4AF_PNG;
if (data_type)
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
- tag->data, tag->data_size);
+ data, data_size);
break;
}
case M4AF_FOURCC('-','-','-','-'):
{
- char *u8 = aacenc_to_utf8(tag->data);
+ char *u8 = aacenc_to_utf8(data);
m4af_add_itmf_long_tag(m4af, tag->name, u8);
free(u8);
break;
case M4AF_FOURCC('\xa9','e','n','c'):
case M4AF_FOURCC('\xa9','s','t','3'):
{
- char *u8 = aacenc_to_utf8(tag->data);
+ char *u8 = aacenc_to_utf8(data);
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
free(u8);
break;
tag->tag >> 24, (tag->tag >> 16) & 0xff,
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
}
+ if (file_contents) free(file_contents);
}
static
if (!params.transport_format) {
uint32_t scale;
unsigned framelen = aacinfo.frameLength;
- int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
- int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
- if (sbr_mode && !sig_mode)
- downsampled_timescale = 1;
+ int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
+ int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
+ if (sbr_mode && !sig_mode)
+ downsampled_timescale = 1;
scale = sample_format->sample_rate >> downsampled_timescale;
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io, ofp)) < 0)
goto END;
framelen >> downsampled_timescale);
m4af_begin_write(m4af);
}
- frame_count = encode(wavf, encoder, aacinfo.frameLength, ofp, m4af);
+ frame_count = encode(wavf, encoder, aacinfo.frameLength, ofp, m4af,
+ !params.silent);
if (frame_count < 0)
goto END;
if (m4af) {
uint32_t delay = aacinfo.encoderDelay;
- int64_t frames_read = wav_get_position(wavf);
+ int64_t frames_read = wav_get_position(wavf);
uint32_t padding = frame_count * aacinfo.frameLength
- frames_read - aacinfo.encoderDelay;
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,