mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
2642af896e | |||
7ce09815f7 | |||
adbd1aac0e | |||
fe4d497877 | |||
bd3b4b343a | |||
406f0e0f44 | |||
1170c9a610 | |||
a56831da9f | |||
aa2ca1e348 | |||
7b1f213618 | |||
5af13f7d79 | |||
5c534696a9 | |||
33e12bc4f5 | |||
bfb6aa3cb8 | |||
360cf7dc8b |
@ -52,13 +52,20 @@
|
|||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>HAVE_STDINT_H;inline=__inline;_CRT_SECURE_NO_WARNINGS;WIN32;_CONSOLE;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>HAVE_STDINT_H;inline=__inline;_CRT_SECURE_NO_WARNINGS;WIN32;_CONSOLE;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>../fdk-aac/libSYS/include;../fdk-aac/libAACenc/include;../missings;.;..</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>./include;../missings;.;..</AdditionalIncludeDirectories>
|
||||||
<StringPooling>true</StringPooling>
|
<StringPooling>true</StringPooling>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
|
<PreBuildEvent>
|
||||||
|
<Command>copy ..\fdk-aac\libAACdec\include\aacdecoder_lib.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libAACenc\include\aacenc_lib.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libSYS\include\FDK_Audio.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libSYS\include\genericStds.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libSYS\include\machine_type.h include\fdk-aac\ </Command>
|
||||||
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@ -69,7 +76,7 @@
|
|||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<PreprocessorDefinitions>HAVE_STDINT_H;inline=__inline;_CRT_SECURE_NO_WARNINGS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>HAVE_STDINT_H;inline=__inline;_CRT_SECURE_NO_WARNINGS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>../fdk-aac/libSYS/include;../fdk-aac/libAACenc/include;../missings;.;..</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>./include;../missings;.;..</AdditionalIncludeDirectories>
|
||||||
<StringPooling>true</StringPooling>
|
<StringPooling>true</StringPooling>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@ -78,6 +85,13 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
</Link>
|
</Link>
|
||||||
|
<PreBuildEvent>
|
||||||
|
<Command>copy ..\fdk-aac\libAACdec\include\aacdecoder_lib.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libAACenc\include\aacenc_lib.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libSYS\include\FDK_Audio.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libSYS\include\genericStds.h include\fdk-aac\
|
||||||
|
copy ..\fdk-aac\libSYS\include\machine_type.h include\fdk-aac\ </Command>
|
||||||
|
</PreBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\missings\getopt.c" />
|
<ClCompile Include="..\missings\getopt.c" />
|
||||||
|
0
MSVC/include/fdk-aac/.gitkeep
Normal file
0
MSVC/include/fdk-aac/.gitkeep
Normal file
19
README
19
README
@ -31,3 +31,22 @@ look like the following:
|
|||||||
+- src
|
+- src
|
||||||
|
|
||||||
MSVC solution for Visual Studio 2010 is under MSVC directory.
|
MSVC solution for Visual Studio 2010 is under MSVC directory.
|
||||||
|
|
||||||
|
Tagging Options
|
||||||
|
---------------
|
||||||
|
Generic tagging options like --tag, --tag-from-file, --long-tag allows you
|
||||||
|
to set arbitrary tags.
|
||||||
|
Available tags and their fcc (four char code) for --tag and --tag-from-file
|
||||||
|
can be found at http://code.google.com/p/mp4v2/wiki/iTunesMetadata
|
||||||
|
|
||||||
|
For tags such as Artist where first char of fcc is copyright sign,
|
||||||
|
you can skip first char and just say like --tag="ART:Foo Bar" or
|
||||||
|
--tag-from-file=lyr:/path/to/your/lyrics.txt
|
||||||
|
|
||||||
|
Currently, --tag-from-file just stores file contents into m4a without any
|
||||||
|
character encoding / line terminater conversion.
|
||||||
|
Therefore, only use UTF-8 (without BOM) when setting text tags by this option.
|
||||||
|
|
||||||
|
On the other hand, --tag / --long-tag (and other command line arguments) are
|
||||||
|
converted from locale character encoding to UTF-8 on Posix environment.
|
||||||
|
On Windows, command line arguments are always treated as Unicode.
|
||||||
|
@ -32,7 +32,7 @@ AC_CHECK_TYPES([ptrdiff_t])
|
|||||||
|
|
||||||
AC_SYS_LARGEFILE
|
AC_SYS_LARGEFILE
|
||||||
AC_FUNC_FSEEKO
|
AC_FUNC_FSEEKO
|
||||||
AC_CHECK_FUNCS([gettimeofday nl_langinfo strdup _vscprintf])
|
AC_CHECK_FUNCS([sigaction gettimeofday nl_langinfo strdup _vscprintf])
|
||||||
AC_CHECK_FUNC(getopt_long)
|
AC_CHECK_FUNC(getopt_long)
|
||||||
AM_CONDITIONAL([FDK_NO_GETOPT_LONG],[test "$ac_cv_func_getopt_long" != "yes"])
|
AM_CONDITIONAL([FDK_NO_GETOPT_LONG],[test "$ac_cv_func_getopt_long" != "yes"])
|
||||||
AC_SEARCH_LIBS([aacEncOpen],[fdk-aac],[],[],[])
|
AC_SEARCH_LIBS([aacEncOpen],[fdk-aac],[],[],[])
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <share.h>
|
||||||
#include <sys/timeb.h>
|
#include <sys/timeb.h>
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@ -66,15 +67,29 @@ FILE *aacenc_fopen(const char *name, const char *mode)
|
|||||||
fp = (mode[0] == 'r') ? stdin : stdout;
|
fp = (mode[0] == 'r') ? stdin : stdout;
|
||||||
_setmode(_fileno(fp), _O_BINARY);
|
_setmode(_fileno(fp), _O_BINARY);
|
||||||
} else {
|
} else {
|
||||||
|
int share = _SH_DENYRW;
|
||||||
|
if (strchr(mode, 'r') && !strchr(mode, '+'))
|
||||||
|
share = _SH_DENYWR;
|
||||||
codepage_decode_wchar(CP_UTF8, name, &wname);
|
codepage_decode_wchar(CP_UTF8, name, &wname);
|
||||||
codepage_decode_wchar(CP_UTF8, mode, &wmode);
|
codepage_decode_wchar(CP_UTF8, mode, &wmode);
|
||||||
fp = _wfopen(wname, wmode);
|
fp = _wfsopen(wname, wmode, share);
|
||||||
free(wname);
|
free(wname);
|
||||||
free(wmode);
|
free(wmode);
|
||||||
}
|
}
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char **__aacenc_argv__;
|
||||||
|
|
||||||
|
static
|
||||||
|
void aacenc_free_mainargs(void)
|
||||||
|
{
|
||||||
|
char **p = __aacenc_argv__;
|
||||||
|
for (; *p; ++p)
|
||||||
|
free(*p);
|
||||||
|
free(__aacenc_argv__);
|
||||||
|
}
|
||||||
|
|
||||||
void aacenc_getmainargs(int *argc, char ***argv)
|
void aacenc_getmainargs(int *argc, char ***argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -86,6 +101,8 @@ void aacenc_getmainargs(int *argc, char ***argv)
|
|||||||
for (i = 0; i < *argc; ++i)
|
for (i = 0; i < *argc; ++i)
|
||||||
codepage_encode_wchar(CP_UTF8, wargv[i], &(*argv)[i]);
|
codepage_encode_wchar(CP_UTF8, wargv[i], &(*argv)[i]);
|
||||||
(*argv)[*argc] = 0;
|
(*argv)[*argc] = 0;
|
||||||
|
__aacenc_argv__ = *argv;
|
||||||
|
atexit(aacenc_free_mainargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *aacenc_to_utf8(const char *s)
|
char *aacenc_to_utf8(const char *s)
|
||||||
|
20
src/m4af.c
20
src/m4af.c
@ -1142,7 +1142,7 @@ int m4af_finalize(m4af_writer_t *ctx)
|
|||||||
track = ctx->track + i;
|
track = ctx->track + i;
|
||||||
if (track->duration) {
|
if (track->duration) {
|
||||||
int64_t track_size = 0;
|
int64_t track_size = 0;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
for (j = 0; j < track->num_chunks; ++j)
|
for (j = 0; j < track->num_chunks; ++j)
|
||||||
track_size += track->chunk_table[j].size;
|
track_size += track->chunk_table[j].size;
|
||||||
track->avgBitrate =
|
track->avgBitrate =
|
||||||
@ -1176,15 +1176,15 @@ void m4af_teardown(m4af_writer_t **ctxp)
|
|||||||
m4af_writer_t *ctx = *ctxp;
|
m4af_writer_t *ctx = *ctxp;
|
||||||
m4af_track_t *track;
|
m4af_track_t *track;
|
||||||
for (i = 0; i < ctx->num_tracks; ++i) {
|
for (i = 0; i < ctx->num_tracks; ++i) {
|
||||||
track = ctx->track + i;
|
track = ctx->track + i;
|
||||||
if (track->decSpecificInfo)
|
if (track->decSpecificInfo)
|
||||||
m4af_free(track->decSpecificInfo);
|
m4af_free(track->decSpecificInfo);
|
||||||
if (track->sample_table)
|
if (track->sample_table)
|
||||||
m4af_free(track->sample_table);
|
m4af_free(track->sample_table);
|
||||||
if (track->chunk_table)
|
if (track->chunk_table)
|
||||||
m4af_free(track->chunk_table);
|
m4af_free(track->chunk_table);
|
||||||
if (track->chunk_buffer)
|
if (track->chunk_buffer)
|
||||||
m4af_free(track->chunk_buffer);
|
m4af_free(track->chunk_buffer);
|
||||||
}
|
}
|
||||||
if (ctx->itmf_table)
|
if (ctx->itmf_table)
|
||||||
m4af_free_itmf_table(ctx);
|
m4af_free_itmf_table(ctx);
|
||||||
|
178
src/main.c
178
src/main.c
@ -24,8 +24,13 @@
|
|||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_SIGACTION
|
||||||
|
#include <signal.h>
|
||||||
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "wav_reader.h"
|
#include "wav_reader.h"
|
||||||
@ -36,6 +41,40 @@
|
|||||||
|
|
||||||
#define PROGNAME "fdkaac"
|
#define PROGNAME "fdkaac"
|
||||||
|
|
||||||
|
static volatile g_interrupted = 0;
|
||||||
|
|
||||||
|
#if HAVE_SIGACTION
|
||||||
|
static void signal_handler(int signum)
|
||||||
|
{
|
||||||
|
g_interrupted = 1;
|
||||||
|
}
|
||||||
|
static void handle_signals(void)
|
||||||
|
{
|
||||||
|
int i, sigs[] = { SIGINT, SIGHUP, SIGTERM };
|
||||||
|
for (i = 0; i < sizeof(sigs)/sizeof(sigs[0]); ++i) {
|
||||||
|
struct sigaction sa = { 0 };
|
||||||
|
sa.sa_handler = signal_handler;
|
||||||
|
sa.sa_flags |= SA_RESTART;
|
||||||
|
sigaction(sigs[i], &sa, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
static BOOL WINAPI signal_handler(DWORD type)
|
||||||
|
{
|
||||||
|
g_interrupted = 1;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_signals(void)
|
||||||
|
{
|
||||||
|
SetConsoleCtrlHandler(signal_handler, TRUE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void handle_signals(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static
|
static
|
||||||
int read_callback(void *cookie, void *data, uint32_t size)
|
int read_callback(void *cookie, void *data, uint32_t size)
|
||||||
{
|
{
|
||||||
@ -108,7 +147,8 @@ PROGNAME " %s\n"
|
|||||||
" transport layer\n"
|
" transport layer\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -o <filename> Output filename\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"
|
"\n"
|
||||||
"Options for raw (headerless) input:\n"
|
"Options for raw (headerless) input:\n"
|
||||||
" -R, --raw Treat input as raw (by default WAV is\n"
|
" -R, --raw Treat input as raw (by default WAV is\n"
|
||||||
@ -138,6 +178,8 @@ PROGNAME " %s\n"
|
|||||||
" --disk <number[/total]>\n"
|
" --disk <number[/total]>\n"
|
||||||
" --tempo <n>\n"
|
" --tempo <n>\n"
|
||||||
" --tag <fcc>:<value> Set iTunes predefined tag with four char code.\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"
|
" --long-tag <name>:<value> Set arbitrary tag as iTunes custom metadata.\n"
|
||||||
, fdkaac_version);
|
, fdkaac_version);
|
||||||
}
|
}
|
||||||
@ -147,6 +189,7 @@ typedef struct aacenc_tag_entry_t {
|
|||||||
const char *name;
|
const char *name;
|
||||||
const char *data;
|
const char *data;
|
||||||
uint32_t data_size;
|
uint32_t data_size;
|
||||||
|
int is_file_name;
|
||||||
} aacenc_tag_entry_t;
|
} aacenc_tag_entry_t;
|
||||||
|
|
||||||
typedef struct aacenc_param_ex_t {
|
typedef struct aacenc_param_ex_t {
|
||||||
@ -155,6 +198,7 @@ typedef struct aacenc_param_ex_t {
|
|||||||
char *input_filename;
|
char *input_filename;
|
||||||
char *output_filename;
|
char *output_filename;
|
||||||
unsigned ignore_length;
|
unsigned ignore_length;
|
||||||
|
int silent;
|
||||||
|
|
||||||
int is_raw;
|
int is_raw;
|
||||||
unsigned raw_channels;
|
unsigned raw_channels;
|
||||||
@ -168,7 +212,8 @@ typedef struct aacenc_param_ex_t {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void param_add_itmf_entry(aacenc_param_ex_t *params, uint32_t tag,
|
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;
|
aacenc_tag_entry_t *entry;
|
||||||
if (params->tag_count == params->tag_table_capacity) {
|
if (params->tag_count == params->tag_table_capacity) {
|
||||||
@ -184,6 +229,7 @@ void param_add_itmf_entry(aacenc_param_ex_t *params, uint32_t tag,
|
|||||||
entry->name = key;
|
entry->name = key;
|
||||||
entry->data = value;
|
entry->data = value;
|
||||||
entry->data_size = size;
|
entry->data_size = size;
|
||||||
|
entry->is_file_name = is_file_name;
|
||||||
params->tag_count++;
|
params->tag_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,11 +239,12 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
int ch;
|
int ch;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
|
#define OPT_RAW_CHANNELS M4AF_FOURCC('r','c','h','n')
|
||||||
#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
|
#define OPT_RAW_RATE M4AF_FOURCC('r','r','a','t')
|
||||||
#define OPT_RAW_FORMAT M4AF_FOURCC('r','f','m','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 M4AF_FOURCC('s','t','a','g')
|
||||||
#define OPT_LONG_TAG M4AF_FOURCC('l','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[] = {
|
static struct option long_options[] = {
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
@ -212,7 +259,8 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
{ "adts-crc-check", no_argument, 0, 'C' },
|
{ "adts-crc-check", no_argument, 0, 'C' },
|
||||||
{ "header-period", required_argument, 0, 'P' },
|
{ "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", no_argument, 0, 'R' },
|
||||||
{ "raw-channels", required_argument, 0, OPT_RAW_CHANNELS },
|
{ "raw-channels", required_argument, 0, OPT_RAW_CHANNELS },
|
||||||
@ -232,12 +280,14 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
{ "disk", required_argument, 0, M4AF_TAG_DISK },
|
{ "disk", required_argument, 0, M4AF_TAG_DISK },
|
||||||
{ "tempo", required_argument, 0, M4AF_TAG_TEMPO },
|
{ "tempo", required_argument, 0, M4AF_TAG_TEMPO },
|
||||||
{ "tag", required_argument, 0, OPT_SHORT_TAG },
|
{ "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 },
|
{ "long-tag", required_argument, 0, OPT_LONG_TAG },
|
||||||
|
{ 0, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
params->afterburner = 1;
|
params->afterburner = 1;
|
||||||
|
|
||||||
aacenc_getmainargs(&argc, &argv);
|
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) {
|
long_options, 0)) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -310,6 +360,9 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
case 'I':
|
case 'I':
|
||||||
params->ignore_length = 1;
|
params->ignore_length = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
params->silent = 1;
|
||||||
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
params->is_raw = 1;
|
params->is_raw = 1;
|
||||||
break;
|
break;
|
||||||
@ -342,9 +395,10 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
case M4AF_TAG_TRACK:
|
case M4AF_TAG_TRACK:
|
||||||
case M4AF_TAG_DISK:
|
case M4AF_TAG_DISK:
|
||||||
case M4AF_TAG_TEMPO:
|
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;
|
break;
|
||||||
case OPT_SHORT_TAG:
|
case OPT_SHORT_TAG:
|
||||||
|
case OPT_SHORT_TAG_FILE:
|
||||||
case OPT_LONG_TAG:
|
case OPT_LONG_TAG:
|
||||||
{
|
{
|
||||||
char *val;
|
char *val;
|
||||||
@ -356,7 +410,15 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*val++ = '\0';
|
*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)
|
if ((klen = strlen(optarg))== 3)
|
||||||
fcc = 0xa9;
|
fcc = 0xa9;
|
||||||
else if (klen != 4) {
|
else if (klen != 4) {
|
||||||
@ -366,7 +428,8 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
for (; *optarg; ++optarg)
|
for (; *optarg; ++optarg)
|
||||||
fcc = ((fcc << 8) | (*optarg & 0xff));
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -419,7 +482,8 @@ int write_sample(FILE *ofp, m4af_writer_t *m4af,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
|
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;
|
uint8_t *ibuf = 0;
|
||||||
int16_t *pcmbuf = 0;
|
int16_t *pcmbuf = 0;
|
||||||
@ -437,7 +501,9 @@ int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
|
|||||||
ibuf = malloc(frame_length * format->bytes_per_frame);
|
ibuf = malloc(frame_length * format->bytes_per_frame);
|
||||||
aacenc_progress_init(&progress, wav_get_length(wavf), format->sample_rate);
|
aacenc_progress_init(&progress, wav_get_length(wavf), format->sample_rate);
|
||||||
do {
|
do {
|
||||||
if (nread) {
|
if (g_interrupted)
|
||||||
|
nread = 0;
|
||||||
|
else if (nread) {
|
||||||
if ((nread = wav_read_frames(wavf, ibuf, frame_length)) < 0) {
|
if ((nread = wav_read_frames(wavf, ibuf, frame_length)) < 0) {
|
||||||
fprintf(stderr, "ERROR: read failed\n");
|
fprintf(stderr, "ERROR: read failed\n");
|
||||||
goto END;
|
goto END;
|
||||||
@ -448,8 +514,9 @@ int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
|
|||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
aacenc_progress_update(&progress, wav_get_position(wavf),
|
if (show_progress)
|
||||||
format->sample_rate * 2);
|
aacenc_progress_update(&progress, wav_get_position(wavf),
|
||||||
|
format->sample_rate * 2);
|
||||||
}
|
}
|
||||||
if ((consumed = aac_encode_frame(encoder, format, pcmbuf, nread,
|
if ((consumed = aac_encode_frame(encoder, format, pcmbuf, nread,
|
||||||
&obuf, &olen, &osize)) < 0)
|
&obuf, &olen, &osize)) < 0)
|
||||||
@ -460,7 +527,9 @@ int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
|
|||||||
++frames_written;
|
++frames_written;
|
||||||
}
|
}
|
||||||
} while (nread > 0 || olen > 0);
|
} 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;
|
rc = frames_written;
|
||||||
END:
|
END:
|
||||||
if (ibuf) free(ibuf);
|
if (ibuf) free(ibuf);
|
||||||
@ -469,26 +538,60 @@ END:
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
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
|
static
|
||||||
void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
||||||
{
|
{
|
||||||
unsigned m, n = 0;
|
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) {
|
switch (tag->tag) {
|
||||||
case M4AF_TAG_TRACK:
|
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);
|
m4af_add_itmf_track_tag(m4af, m, n);
|
||||||
break;
|
break;
|
||||||
case M4AF_TAG_DISK:
|
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);
|
m4af_add_itmf_disk_tag(m4af, m, n);
|
||||||
break;
|
break;
|
||||||
case M4AF_TAG_GENRE_ID3:
|
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);
|
m4af_add_itmf_genre_tag(m4af, n);
|
||||||
break;
|
break;
|
||||||
case M4AF_TAG_TEMPO:
|
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);
|
m4af_add_itmf_int16_tag(m4af, tag->tag, n);
|
||||||
break;
|
break;
|
||||||
case M4AF_TAG_COMPILATION:
|
case M4AF_TAG_COMPILATION:
|
||||||
@ -498,7 +601,7 @@ void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
|||||||
case M4AF_FOURCC('p','g','a','p'):
|
case M4AF_FOURCC('p','g','a','p'):
|
||||||
case M4AF_FOURCC('r','t','n','g'):
|
case M4AF_FOURCC('r','t','n','g'):
|
||||||
case M4AF_FOURCC('s','t','i','k'):
|
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);
|
m4af_add_itmf_int8_tag(m4af, tag->tag, n);
|
||||||
break;
|
break;
|
||||||
case M4AF_FOURCC('a','t','I','D'):
|
case M4AF_FOURCC('a','t','I','D'):
|
||||||
@ -508,33 +611,33 @@ void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
|||||||
case M4AF_FOURCC('s','f','I','D'):
|
case M4AF_FOURCC('s','f','I','D'):
|
||||||
case M4AF_FOURCC('t','v','s','n'):
|
case M4AF_FOURCC('t','v','s','n'):
|
||||||
case M4AF_FOURCC('t','v','s','s'):
|
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);
|
m4af_add_itmf_int32_tag(m4af, tag->tag, n);
|
||||||
break;
|
break;
|
||||||
case M4AF_FOURCC('p','l','I','D'):
|
case M4AF_FOURCC('p','l','I','D'):
|
||||||
{
|
{
|
||||||
int64_t qn;
|
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);
|
m4af_add_itmf_int64_tag(m4af, tag->tag, qn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M4AF_TAG_ARTWORK:
|
case M4AF_TAG_ARTWORK:
|
||||||
{
|
{
|
||||||
int data_type = 0;
|
int data_type = 0;
|
||||||
if (!memcmp(tag->data, "GIF", 3))
|
if (!memcmp(data, "GIF", 3))
|
||||||
data_type = M4AF_GIF;
|
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;
|
data_type = M4AF_JPEG;
|
||||||
else if (!memcmp(tag->data, "\x89PNG", 4))
|
else if (!memcmp(data, "\x89PNG", 4))
|
||||||
data_type = M4AF_PNG;
|
data_type = M4AF_PNG;
|
||||||
if (data_type)
|
if (data_type)
|
||||||
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
|
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
|
||||||
tag->data, tag->data_size);
|
data, data_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M4AF_FOURCC('-','-','-','-'):
|
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);
|
m4af_add_itmf_long_tag(m4af, tag->name, u8);
|
||||||
free(u8);
|
free(u8);
|
||||||
break;
|
break;
|
||||||
@ -571,7 +674,7 @@ void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
|||||||
case M4AF_FOURCC('\xa9','e','n','c'):
|
case M4AF_FOURCC('\xa9','e','n','c'):
|
||||||
case M4AF_FOURCC('\xa9','s','t','3'):
|
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);
|
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
|
||||||
free(u8);
|
free(u8);
|
||||||
break;
|
break;
|
||||||
@ -581,6 +684,7 @@ void put_tag_entry(m4af_writer_t *m4af, const aacenc_tag_entry_t *tag)
|
|||||||
tag->tag >> 24, (tag->tag >> 16) & 0xff,
|
tag->tag >> 24, (tag->tag >> 16) & 0xff,
|
||||||
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
|
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
|
||||||
}
|
}
|
||||||
|
if (file_contents) free(file_contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -758,13 +862,14 @@ int main(int argc, char **argv)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
handle_signals();
|
||||||
if (!params.transport_format) {
|
if (!params.transport_format) {
|
||||||
uint32_t scale;
|
uint32_t scale;
|
||||||
unsigned framelen = aacinfo.frameLength;
|
unsigned framelen = aacinfo.frameLength;
|
||||||
int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
||||||
int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
|
int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
|
||||||
if (sbr_mode && !sig_mode)
|
if (sbr_mode && !sig_mode)
|
||||||
downsampled_timescale = 1;
|
downsampled_timescale = 1;
|
||||||
scale = sample_format->sample_rate >> downsampled_timescale;
|
scale = sample_format->sample_rate >> downsampled_timescale;
|
||||||
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io, ofp)) < 0)
|
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io, ofp)) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
@ -773,12 +878,13 @@ int main(int argc, char **argv)
|
|||||||
framelen >> downsampled_timescale);
|
framelen >> downsampled_timescale);
|
||||||
m4af_begin_write(m4af);
|
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)
|
if (frame_count < 0)
|
||||||
goto END;
|
goto END;
|
||||||
if (m4af) {
|
if (m4af) {
|
||||||
uint32_t delay = aacinfo.encoderDelay;
|
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
|
uint32_t padding = frame_count * aacinfo.frameLength
|
||||||
- frames_read - aacinfo.encoderDelay;
|
- frames_read - aacinfo.encoderDelay;
|
||||||
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,
|
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,
|
||||||
|
Reference in New Issue
Block a user