mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
2642af896e | |||
7ce09815f7 | |||
adbd1aac0e | |||
fe4d497877 | |||
bd3b4b343a | |||
406f0e0f44 | |||
1170c9a610 | |||
a56831da9f | |||
aa2ca1e348 | |||
7b1f213618 | |||
5af13f7d79 | |||
5c534696a9 | |||
33e12bc4f5 | |||
bfb6aa3cb8 | |||
360cf7dc8b | |||
43ab433178 | |||
47c164c85a | |||
d52b8bbf13 | |||
f67cfe227e | |||
e476728e77 | |||
dac71de305 | |||
61b6a9e383 | |||
5888fddccf | |||
c5c459082a | |||
00799c5e44 | |||
6887939854 | |||
6854317606 | |||
8960a17764 |
@ -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])
|
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],[],[],[])
|
||||||
|
@ -142,7 +142,7 @@ int aac_encode_frame(HANDLE_AACENCODER encoder,
|
|||||||
unsigned channel_mode, obytes;
|
unsigned channel_mode, obytes;
|
||||||
|
|
||||||
channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE);
|
channel_mode = aacEncoder_GetParam(encoder, AACENC_CHANNELMODE);
|
||||||
obytes = 6144 / 8 * channel_mode;
|
obytes = 6144 / 8 * channel_mode + 7;
|
||||||
if (!*output || *osize < obytes) {
|
if (!*output || *osize < obytes) {
|
||||||
*osize = obytes;
|
*osize = obytes;
|
||||||
*output = realloc(*output, obytes);
|
*output = realloc(*output, obytes);
|
||||||
|
@ -20,5 +20,6 @@ FILE *aacenc_fopen(const char *name, const char *mode);
|
|||||||
void aacenc_getmainargs(int *argc, char ***argv);
|
void aacenc_getmainargs(int *argc, char ***argv);
|
||||||
char *aacenc_to_utf8(const char *s);
|
char *aacenc_to_utf8(const char *s);
|
||||||
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
|
int aacenc_fprintf(FILE *fp, const char *fmt, ...);
|
||||||
|
const char *aacenc_basename(const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,6 +48,16 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Different from POSIX basename() when path ends with /.
|
||||||
|
* Since we use this only for a regular file, the difference doesn't matter.
|
||||||
|
*/
|
||||||
|
const char *aacenc_basename(const char *path)
|
||||||
|
{
|
||||||
|
const char *p = strrchr(path, '/');
|
||||||
|
return p ? p + 1: path;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef HAVE_ICONV
|
#ifndef HAVE_ICONV
|
||||||
char *aacenc_to_utf8(const char *s)
|
char *aacenc_to_utf8(const char *s)
|
||||||
{
|
{
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.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
|
||||||
@ -65,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;
|
||||||
@ -85,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)
|
||||||
@ -92,6 +110,20 @@ char *aacenc_to_utf8(const char *s)
|
|||||||
return _strdup(s);
|
return _strdup(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) && !defined(HAVE__VSCPRINTF)
|
||||||
|
int _vscprintf(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
static int (*fp_vscprintf)(const char *, va_list) = 0;
|
||||||
|
if (!fp_vscprintf) {
|
||||||
|
HANDLE h = GetModuleHandleA("msvcrt.dll");
|
||||||
|
FARPROC fp = GetProcAddress(h, "_vscprintf");
|
||||||
|
InterlockedCompareExchangePointer(&fp_vscprintf, fp, 0);
|
||||||
|
}
|
||||||
|
assert(fp_vscprintf);
|
||||||
|
return fp_vscprintf(fmt, ap);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -126,3 +158,15 @@ int aacenc_fprintf(FILE *fp, const char *fmt, ...)
|
|||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *aacenc_basename(const char *path)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Since path is encoded with UTF-8, naive usage of strrchr() shoule be safe.
|
||||||
|
*/
|
||||||
|
const char *p = strrchr(path, '/');
|
||||||
|
const char *q = strrchr(path, '\\');
|
||||||
|
const char *r = strrchr(path, ':');
|
||||||
|
if (q > p) p = q;
|
||||||
|
if (r > p) p = r;
|
||||||
|
return p ? p + 1 : path;
|
||||||
|
}
|
||||||
|
57
src/m4af.c
57
src/m4af.c
@ -456,12 +456,18 @@ int m4af_add_itmf_int16_tag(m4af_writer_t *ctx, uint32_t type, int value)
|
|||||||
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 2);
|
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, int value)
|
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, uint32_t value)
|
||||||
{
|
{
|
||||||
uint32_t data = m4af_htob32(value);
|
uint32_t data = m4af_htob32(value);
|
||||||
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 4);
|
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int m4af_add_itmf_int64_tag(m4af_writer_t *ctx, uint32_t type, uint64_t value)
|
||||||
|
{
|
||||||
|
uint64_t data = m4af_htob64(value);
|
||||||
|
return m4af_add_itmf_short_tag(ctx, type, M4AF_INTEGER, &data, 8);
|
||||||
|
}
|
||||||
|
|
||||||
int m4af_add_itmf_track_tag(m4af_writer_t *ctx, int track, int total)
|
int m4af_add_itmf_track_tag(m4af_writer_t *ctx, int track, int total)
|
||||||
{
|
{
|
||||||
uint16_t data[4] = { 0 };
|
uint16_t data[4] = { 0 };
|
||||||
@ -509,15 +515,6 @@ void m4af_update_size(m4af_writer_t *ctx, int64_t pos)
|
|||||||
m4af_set_pos(ctx, current_pos);
|
m4af_set_pos(ctx, current_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
int m4af_head_version(m4af_writer_t *ctx, int track_idx)
|
|
||||||
{
|
|
||||||
m4af_track_t *track = &ctx->track[track_idx];
|
|
||||||
return track->duration > UINT32_MAX
|
|
||||||
|| track->creation_time > UINT32_MAX
|
|
||||||
|| track->modification_time > UINT32_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void m4af_descriptor(m4af_writer_t *ctx, uint32_t tag, uint32_t size)
|
void m4af_descriptor(m4af_writer_t *ctx, uint32_t tag, uint32_t size)
|
||||||
{
|
{
|
||||||
@ -829,7 +826,9 @@ void m4af_mdhd_box(m4af_writer_t *ctx, int track_idx)
|
|||||||
{
|
{
|
||||||
m4af_track_t *track = &ctx->track[track_idx];
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
uint8_t version = m4af_head_version(ctx, track_idx);
|
uint8_t version = (track->creation_time > UINT32_MAX ||
|
||||||
|
track->modification_time > UINT32_MAX ||
|
||||||
|
track->duration > UINT32_MAX);
|
||||||
|
|
||||||
m4af_write(ctx, "\0\0\0\0mdhd", 8);
|
m4af_write(ctx, "\0\0\0\0mdhd", 8);
|
||||||
m4af_write(ctx, &version, 1);
|
m4af_write(ctx, &version, 1);
|
||||||
@ -892,7 +891,11 @@ void m4af_tkhd_box(m4af_writer_t *ctx, int track_idx)
|
|||||||
{
|
{
|
||||||
m4af_track_t *track = &ctx->track[track_idx];
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
uint8_t version = m4af_head_version(ctx, track_idx);
|
int64_t duration =
|
||||||
|
(double)track->duration / track->timescale * ctx->timescale + .5;
|
||||||
|
uint8_t version = (track->creation_time > UINT32_MAX ||
|
||||||
|
track->modification_time > UINT32_MAX ||
|
||||||
|
duration > UINT32_MAX);
|
||||||
m4af_write(ctx, "\0\0\0\0tkhd", 8);
|
m4af_write(ctx, "\0\0\0\0tkhd", 8);
|
||||||
m4af_write(ctx, &version, 1);
|
m4af_write(ctx, &version, 1);
|
||||||
m4af_write(ctx, "\0\0\007", 3); /* flags */
|
m4af_write(ctx, "\0\0\007", 3); /* flags */
|
||||||
@ -902,14 +905,14 @@ void m4af_tkhd_box(m4af_writer_t *ctx, int track_idx)
|
|||||||
m4af_write32(ctx, track_idx + 1);
|
m4af_write32(ctx, track_idx + 1);
|
||||||
m4af_write(ctx, "\0\0\0\0" /* reserved */
|
m4af_write(ctx, "\0\0\0\0" /* reserved */
|
||||||
, 4);
|
, 4);
|
||||||
m4af_write64(ctx, track->duration);
|
m4af_write64(ctx, duration);
|
||||||
} else {
|
} else {
|
||||||
m4af_write32(ctx, track->creation_time);
|
m4af_write32(ctx, track->creation_time);
|
||||||
m4af_write32(ctx, track->modification_time);
|
m4af_write32(ctx, track->modification_time);
|
||||||
m4af_write32(ctx, track_idx + 1);
|
m4af_write32(ctx, track_idx + 1);
|
||||||
m4af_write(ctx, "\0\0\0\0" /* reserved */
|
m4af_write(ctx, "\0\0\0\0" /* reserved */
|
||||||
, 4);
|
, 4);
|
||||||
m4af_write32(ctx, track->duration);
|
m4af_write32(ctx, duration);
|
||||||
}
|
}
|
||||||
m4af_write(ctx,
|
m4af_write(ctx,
|
||||||
"\0\0\0\0" /* reserved[0] */
|
"\0\0\0\0" /* reserved[0] */
|
||||||
@ -950,7 +953,7 @@ int64_t m4af_movie_duration(m4af_writer_t *ctx)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
for (i = 0; i < ctx->num_tracks; ++i) {
|
for (i = 0; i < ctx->num_tracks; ++i) {
|
||||||
double x = ctx->track[i].duration;
|
double x = ctx->track[i].duration;
|
||||||
int64_t duration = x * ctx->track[i].timescale / ctx->timescale + .5;
|
int64_t duration = x / ctx->track[i].timescale * ctx->timescale + .5;
|
||||||
if (duration > movie_duration)
|
if (duration > movie_duration)
|
||||||
movie_duration = duration;
|
movie_duration = duration;
|
||||||
}
|
}
|
||||||
@ -961,8 +964,10 @@ static
|
|||||||
void m4af_mvhd_box(m4af_writer_t *ctx)
|
void m4af_mvhd_box(m4af_writer_t *ctx)
|
||||||
{
|
{
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
uint8_t version = m4af_head_version(ctx, 0);
|
|
||||||
int64_t movie_duration = m4af_movie_duration(ctx);
|
int64_t movie_duration = m4af_movie_duration(ctx);
|
||||||
|
uint8_t version = (ctx->creation_time > UINT32_MAX ||
|
||||||
|
ctx->modification_time > UINT32_MAX ||
|
||||||
|
movie_duration > UINT32_MAX);
|
||||||
|
|
||||||
m4af_write(ctx, "\0\0\0\0mvhd", 8);
|
m4af_write(ctx, "\0\0\0\0mvhd", 8);
|
||||||
m4af_write(ctx, &version, 1);
|
m4af_write(ctx, &version, 1);
|
||||||
@ -1137,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 =
|
||||||
@ -1171,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);
|
||||||
|
@ -103,7 +103,9 @@ int m4af_add_itmf_int8_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
|||||||
|
|
||||||
int m4af_add_itmf_int16_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
int m4af_add_itmf_int16_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
||||||
|
|
||||||
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, int value);
|
int m4af_add_itmf_int32_tag(m4af_writer_t *ctx, uint32_t type, uint32_t value);
|
||||||
|
|
||||||
|
int m4af_add_itmf_int64_tag(m4af_writer_t *ctx, uint32_t type, uint64_t value);
|
||||||
|
|
||||||
int m4af_add_itmf_track_tag(m4af_writer_t *ctx, int track, int total);
|
int m4af_add_itmf_track_tag(m4af_writer_t *ctx, int track, int total);
|
||||||
|
|
||||||
|
570
src/main.c
570
src/main.c
@ -8,9 +8,15 @@
|
|||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_INTTYPES_H
|
||||||
|
# include <inttypes.h>
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
# define SCNd64 "I64d"
|
||||||
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -18,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"
|
||||||
@ -30,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)
|
||||||
{
|
{
|
||||||
@ -97,12 +142,27 @@ PROGNAME " %s\n"
|
|||||||
" 6: LATM MCP=1\n"
|
" 6: LATM MCP=1\n"
|
||||||
" 7: LATM MCP=0\n"
|
" 7: LATM MCP=0\n"
|
||||||
" 10: LOAS/LATM (LATM within LOAS)\n"
|
" 10: LOAS/LATM (LATM within LOAS)\n"
|
||||||
" -c, --adts-crc-check Add CRC protection on ADTS header\n"
|
" -C, --adts-crc-check Add CRC protection on ADTS header\n"
|
||||||
" -h, --header-period <n> StreamMuxConfig/PCE repetition period in\n"
|
" -h, --header-period <n> StreamMuxConfig/PCE repetition period in\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"
|
||||||
|
"Options for raw (headerless) input:\n"
|
||||||
|
" -R, --raw Treat input as raw (by default WAV is\n"
|
||||||
|
" assumed)\n"
|
||||||
|
" --raw-channels <n> Number of channels (default: 2)\n"
|
||||||
|
" --raw-rate <n> Sample rate (default: 44100)\n"
|
||||||
|
" --raw-format <spec> Sample format, default is \"S16L\".\n"
|
||||||
|
" Spec is as follows:\n"
|
||||||
|
" 1st char: S(igned)|U(nsigned)|F(loat)\n"
|
||||||
|
" 2nd part: bits per channel\n"
|
||||||
|
" Last char: L(ittle)|B(ig)\n"
|
||||||
|
" Last char can be omitted, in which case L is\n"
|
||||||
|
" assumed. Spec is case insensitive, therefore\n"
|
||||||
|
" \"u16b\" is same as \"U16B\".\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Tagging options:\n"
|
"Tagging options:\n"
|
||||||
" --title <string>\n"
|
" --title <string>\n"
|
||||||
@ -117,12 +177,19 @@ PROGNAME " %s\n"
|
|||||||
" --track <number[/total]>\n"
|
" --track <number[/total]>\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-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);
|
, fdkaac_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct aacenc_tag_entry_t {
|
typedef struct aacenc_tag_entry_t {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
|
const char *name;
|
||||||
const char *data;
|
const char *data;
|
||||||
|
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 {
|
||||||
@ -131,18 +198,53 @@ 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;
|
||||||
|
unsigned raw_channels;
|
||||||
|
unsigned raw_rate;
|
||||||
|
const char *raw_format;
|
||||||
|
|
||||||
aacenc_tag_entry_t *tag_table;
|
aacenc_tag_entry_t *tag_table;
|
||||||
unsigned tag_count;
|
unsigned tag_count;
|
||||||
unsigned tag_table_capacity;
|
unsigned tag_table_capacity;
|
||||||
} aacenc_param_ex_t;
|
} aacenc_param_ex_t;
|
||||||
|
|
||||||
|
static
|
||||||
|
void param_add_itmf_entry(aacenc_param_ex_t *params, uint32_t tag,
|
||||||
|
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) {
|
||||||
|
unsigned newsize = params->tag_table_capacity;
|
||||||
|
newsize = newsize ? newsize * 2 : 1;
|
||||||
|
params->tag_table =
|
||||||
|
realloc(params->tag_table, newsize * sizeof(aacenc_tag_entry_t));
|
||||||
|
params->tag_table_capacity = newsize;
|
||||||
|
}
|
||||||
|
entry = params->tag_table + params->tag_count;
|
||||||
|
entry->tag = tag;
|
||||||
|
if (tag == M4AF_FOURCC('-','-','-','-'))
|
||||||
|
entry->name = key;
|
||||||
|
entry->data = value;
|
||||||
|
entry->data_size = size;
|
||||||
|
entry->is_file_name = is_file_name;
|
||||||
|
params->tag_count++;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
aacenc_tag_entry_t *tag;
|
|
||||||
|
#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[] = {
|
static struct option long_options[] = {
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
@ -154,28 +256,38 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
||||||
{ "sbr-signaling", required_argument, 0, 's' },
|
{ "sbr-signaling", required_argument, 0, 's' },
|
||||||
{ "transport-format", required_argument, 0, 'f' },
|
{ "transport-format", required_argument, 0, 'f' },
|
||||||
{ "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' },
|
||||||
|
|
||||||
{ "title", required_argument, 0, M4AF_TAG_TITLE },
|
{ "raw", no_argument, 0, 'R' },
|
||||||
{ "artist", required_argument, 0, M4AF_TAG_ARTIST },
|
{ "raw-channels", required_argument, 0, OPT_RAW_CHANNELS },
|
||||||
{ "album", required_argument, 0, M4AF_TAG_ALBUM },
|
{ "raw-rate", required_argument, 0, OPT_RAW_RATE },
|
||||||
{ "genre", required_argument, 0, M4AF_TAG_GENRE },
|
{ "raw-format", required_argument, 0, OPT_RAW_FORMAT },
|
||||||
{ "date", required_argument, 0, M4AF_TAG_DATE },
|
|
||||||
{ "composer", required_argument, 0, M4AF_TAG_COMPOSER },
|
{ "title", required_argument, 0, M4AF_TAG_TITLE },
|
||||||
{ "grouping", required_argument, 0, M4AF_TAG_GROUPING },
|
{ "artist", required_argument, 0, M4AF_TAG_ARTIST },
|
||||||
{ "comment", required_argument, 0, M4AF_TAG_COMMENT },
|
{ "album", required_argument, 0, M4AF_TAG_ALBUM },
|
||||||
{ "album-artist", required_argument, 0, M4AF_TAG_ALBUM_ARTIST },
|
{ "genre", required_argument, 0, M4AF_TAG_GENRE },
|
||||||
{ "track", required_argument, 0, M4AF_TAG_TRACK },
|
{ "date", required_argument, 0, M4AF_TAG_DATE },
|
||||||
{ "disk", required_argument, 0, M4AF_TAG_DISK },
|
{ "composer", required_argument, 0, M4AF_TAG_COMPOSER },
|
||||||
{ "tempo", required_argument, 0, M4AF_TAG_TEMPO },
|
{ "grouping", required_argument, 0, M4AF_TAG_GROUPING },
|
||||||
|
{ "comment", required_argument, 0, M4AF_TAG_COMMENT },
|
||||||
|
{ "album-artist", required_argument, 0, M4AF_TAG_ALBUM_ARTIST },
|
||||||
|
{ "track", required_argument, 0, M4AF_TAG_TRACK },
|
||||||
|
{ "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;
|
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:",
|
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':
|
||||||
@ -248,6 +360,29 @@ 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':
|
||||||
|
params->is_raw = 1;
|
||||||
|
break;
|
||||||
|
case OPT_RAW_CHANNELS:
|
||||||
|
if (sscanf(optarg, "%u", &n) != 1) {
|
||||||
|
fprintf(stderr, "invalid arg for raw-channels\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->raw_channels = n;
|
||||||
|
break;
|
||||||
|
case OPT_RAW_RATE:
|
||||||
|
if (sscanf(optarg, "%u", &n) != 1) {
|
||||||
|
fprintf(stderr, "invalid arg for raw-rate\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->raw_rate = n;
|
||||||
|
break;
|
||||||
|
case OPT_RAW_FORMAT:
|
||||||
|
params->raw_format = optarg;
|
||||||
|
break;
|
||||||
case M4AF_TAG_TITLE:
|
case M4AF_TAG_TITLE:
|
||||||
case M4AF_TAG_ARTIST:
|
case M4AF_TAG_ARTIST:
|
||||||
case M4AF_TAG_ALBUM:
|
case M4AF_TAG_ALBUM:
|
||||||
@ -260,18 +395,42 @@ 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:
|
||||||
if (params->tag_count == params->tag_table_capacity) {
|
param_add_itmf_entry(params, ch, 0, optarg, strlen(optarg), 0);
|
||||||
unsigned newsize = params->tag_table_capacity;
|
break;
|
||||||
newsize = newsize ? newsize * 2 : 1;
|
case OPT_SHORT_TAG:
|
||||||
params->tag_table =
|
case OPT_SHORT_TAG_FILE:
|
||||||
realloc(params->tag_table,
|
case OPT_LONG_TAG:
|
||||||
newsize * sizeof(aacenc_tag_entry_t));
|
{
|
||||||
params->tag_table_capacity = newsize;
|
char *val;
|
||||||
|
size_t klen;
|
||||||
|
unsigned fcc = M4AF_FOURCC('-','-','-','-');
|
||||||
|
|
||||||
|
if ((val = strchr(optarg, ':')) == 0) {
|
||||||
|
fprintf(stderr, "invalid arg for tag\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*val++ = '\0';
|
||||||
|
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) {
|
||||||
|
fprintf(stderr, "invalid arg for tag\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (; *optarg; ++optarg)
|
||||||
|
fcc = ((fcc << 8) | (*optarg & 0xff));
|
||||||
|
}
|
||||||
|
param_add_itmf_entry(params, fcc, optarg, val, strlen(val),
|
||||||
|
ch == OPT_SHORT_TAG_FILE);
|
||||||
}
|
}
|
||||||
tag = params->tag_table + params->tag_count;
|
|
||||||
tag->tag = ch;
|
|
||||||
tag->data = optarg;
|
|
||||||
params->tag_count++;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return usage(), -1;
|
return usage(), -1;
|
||||||
@ -279,6 +438,7 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
}
|
}
|
||||||
if (argc == optind)
|
if (argc == optind)
|
||||||
return usage(), -1;
|
return usage(), -1;
|
||||||
|
|
||||||
if (!params->bitrate && !params->bitrate_mode) {
|
if (!params->bitrate && !params->bitrate_mode) {
|
||||||
fprintf(stderr, "bitrate or bitrate-mode is mandatory\n");
|
fprintf(stderr, "bitrate or bitrate-mode is mandatory\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -290,6 +450,15 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
}
|
}
|
||||||
if (params->bitrate && params->bitrate < 10000)
|
if (params->bitrate && params->bitrate < 10000)
|
||||||
params->bitrate *= 1000;
|
params->bitrate *= 1000;
|
||||||
|
|
||||||
|
if (params->is_raw) {
|
||||||
|
if (!params->raw_channels)
|
||||||
|
params->raw_channels = 2;
|
||||||
|
if (!params->raw_rate)
|
||||||
|
params->raw_rate = 44100;
|
||||||
|
if (!params->raw_format)
|
||||||
|
params->raw_format = "S16L";
|
||||||
|
}
|
||||||
params->input_filename = argv[optind];
|
params->input_filename = argv[optind];
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
@ -313,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;
|
||||||
@ -331,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;
|
||||||
@ -342,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)
|
||||||
@ -354,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);
|
||||||
@ -363,67 +538,194 @@ 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
|
||||||
|
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(data, "%u/%u", &m, &n) >= 1)
|
||||||
|
m4af_add_itmf_track_tag(m4af, m, n);
|
||||||
|
break;
|
||||||
|
case M4AF_TAG_DISK:
|
||||||
|
if (sscanf(data, "%u/%u", &m, &n) >= 1)
|
||||||
|
m4af_add_itmf_disk_tag(m4af, m, n);
|
||||||
|
break;
|
||||||
|
case M4AF_TAG_GENRE_ID3:
|
||||||
|
if (sscanf(data, "%u", &n) == 1)
|
||||||
|
m4af_add_itmf_genre_tag(m4af, n);
|
||||||
|
break;
|
||||||
|
case M4AF_TAG_TEMPO:
|
||||||
|
if (sscanf(data, "%u", &n) == 1)
|
||||||
|
m4af_add_itmf_int16_tag(m4af, tag->tag, n);
|
||||||
|
break;
|
||||||
|
case M4AF_TAG_COMPILATION:
|
||||||
|
case M4AF_FOURCC('a','k','I','D'):
|
||||||
|
case M4AF_FOURCC('h','d','v','d'):
|
||||||
|
case M4AF_FOURCC('p','c','s','t'):
|
||||||
|
case M4AF_FOURCC('p','g','a','p'):
|
||||||
|
case M4AF_FOURCC('r','t','n','g'):
|
||||||
|
case M4AF_FOURCC('s','t','i','k'):
|
||||||
|
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('c','m','I','D'):
|
||||||
|
case M4AF_FOURCC('c','n','I','D'):
|
||||||
|
case M4AF_FOURCC('g','e','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(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(data, "%" SCNd64, &qn) == 1)
|
||||||
|
m4af_add_itmf_int64_tag(m4af, tag->tag, qn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M4AF_TAG_ARTWORK:
|
||||||
|
{
|
||||||
|
int data_type = 0;
|
||||||
|
if (!memcmp(data, "GIF", 3))
|
||||||
|
data_type = M4AF_GIF;
|
||||||
|
else if (!memcmp(data, "\xff\xd8\xff", 3))
|
||||||
|
data_type = M4AF_JPEG;
|
||||||
|
else if (!memcmp(data, "\x89PNG", 4))
|
||||||
|
data_type = M4AF_PNG;
|
||||||
|
if (data_type)
|
||||||
|
m4af_add_itmf_short_tag(m4af, tag->tag, data_type,
|
||||||
|
data, data_size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M4AF_FOURCC('-','-','-','-'):
|
||||||
|
{
|
||||||
|
char *u8 = aacenc_to_utf8(data);
|
||||||
|
m4af_add_itmf_long_tag(m4af, tag->name, u8);
|
||||||
|
free(u8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case M4AF_TAG_TITLE:
|
||||||
|
case M4AF_TAG_ARTIST:
|
||||||
|
case M4AF_TAG_ALBUM:
|
||||||
|
case M4AF_TAG_GENRE:
|
||||||
|
case M4AF_TAG_DATE:
|
||||||
|
case M4AF_TAG_COMPOSER:
|
||||||
|
case M4AF_TAG_GROUPING:
|
||||||
|
case M4AF_TAG_COMMENT:
|
||||||
|
case M4AF_TAG_LYRICS:
|
||||||
|
case M4AF_TAG_TOOL:
|
||||||
|
case M4AF_TAG_ALBUM_ARTIST:
|
||||||
|
case M4AF_TAG_DESCRIPTION:
|
||||||
|
case M4AF_TAG_LONG_DESCRIPTION:
|
||||||
|
case M4AF_TAG_COPYRIGHT:
|
||||||
|
case M4AF_FOURCC('a','p','I','D'):
|
||||||
|
case M4AF_FOURCC('c','a','t','g'):
|
||||||
|
case M4AF_FOURCC('k','e','y','w'):
|
||||||
|
case M4AF_FOURCC('p','u','r','d'):
|
||||||
|
case M4AF_FOURCC('p','u','r','l'):
|
||||||
|
case M4AF_FOURCC('s','o','a','a'):
|
||||||
|
case M4AF_FOURCC('s','o','a','l'):
|
||||||
|
case M4AF_FOURCC('s','o','a','r'):
|
||||||
|
case M4AF_FOURCC('s','o','c','o'):
|
||||||
|
case M4AF_FOURCC('s','o','n','m'):
|
||||||
|
case M4AF_FOURCC('s','o','s','n'):
|
||||||
|
case M4AF_FOURCC('t','v','e','n'):
|
||||||
|
case M4AF_FOURCC('t','v','n','n'):
|
||||||
|
case M4AF_FOURCC('t','v','s','h'):
|
||||||
|
case M4AF_FOURCC('x','i','d',' '):
|
||||||
|
case M4AF_FOURCC('\xa9','e','n','c'):
|
||||||
|
case M4AF_FOURCC('\xa9','s','t','3'):
|
||||||
|
{
|
||||||
|
char *u8 = aacenc_to_utf8(data);
|
||||||
|
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
|
||||||
|
free(u8);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "WARNING: unknown/unsupported tag: %c%c%c%c\n",
|
||||||
|
tag->tag >> 24, (tag->tag >> 16) & 0xff,
|
||||||
|
(tag->tag >> 8) & 0xff, tag->tag & 0xff);
|
||||||
|
}
|
||||||
|
if (file_contents) free(file_contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void put_tool_tag(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
||||||
|
HANDLE_AACENCODER encoder)
|
||||||
|
{
|
||||||
|
char tool_info[256];
|
||||||
|
char *p = tool_info;
|
||||||
|
LIB_INFO *lib_info = 0;
|
||||||
|
|
||||||
|
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
||||||
|
|
||||||
|
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
||||||
|
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < FDK_MODULE_LAST; ++i)
|
||||||
|
if (lib_info[i].module_id == FDK_AACENC)
|
||||||
|
break;
|
||||||
|
p += sprintf(p, "libfdk-aac %s, ", lib_info[i].versionStr);
|
||||||
|
}
|
||||||
|
free(lib_info);
|
||||||
|
if (params->bitrate_mode)
|
||||||
|
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
||||||
|
else
|
||||||
|
sprintf(p, "CBR %dkbps",
|
||||||
|
aacEncoder_GetParam(encoder, AACENC_BITRATE) / 1000);
|
||||||
|
|
||||||
|
m4af_add_itmf_string_tag(m4af, M4AF_TAG_TOOL, tool_info);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int finalize_m4a(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
int finalize_m4a(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
||||||
HANDLE_AACENCODER encoder)
|
HANDLE_AACENCODER encoder)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
aacenc_tag_entry_t *tag = params->tag_table;
|
aacenc_tag_entry_t *tag = params->tag_table;
|
||||||
|
for (i = 0; i < params->tag_count; ++i, ++tag)
|
||||||
|
put_tag_entry(m4af, tag);
|
||||||
|
|
||||||
for (i = 0; i < params->tag_count; ++i, ++tag) {
|
put_tool_tag(m4af, params, encoder);
|
||||||
switch (tag->tag) {
|
|
||||||
case M4AF_TAG_TRACK:
|
|
||||||
{
|
|
||||||
unsigned m, n = 0;
|
|
||||||
if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
|
|
||||||
m4af_add_itmf_track_tag(m4af, m, n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case M4AF_TAG_DISK:
|
|
||||||
{
|
|
||||||
unsigned m, n = 0;
|
|
||||||
if (sscanf(tag->data, "%u/%u", &m, &n) >= 1)
|
|
||||||
m4af_add_itmf_disk_tag(m4af, m, n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case M4AF_TAG_TEMPO:
|
|
||||||
{
|
|
||||||
unsigned n;
|
|
||||||
if (sscanf(tag->data, "%u", &n) == 1)
|
|
||||||
m4af_add_itmf_int16_tag(m4af, tag->tag, n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
char *u8 = aacenc_to_utf8(tag->data);
|
|
||||||
m4af_add_itmf_string_tag(m4af, tag->tag, u8);
|
|
||||||
free(u8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
char tool_info[256];
|
|
||||||
char *p = tool_info;
|
|
||||||
LIB_INFO *lib_info = 0;
|
|
||||||
|
|
||||||
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
|
||||||
|
|
||||||
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
|
||||||
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
|
||||||
for (i = 0; i < FDK_MODULE_LAST; ++i)
|
|
||||||
if (lib_info[i].module_id == FDK_AACENC)
|
|
||||||
break;
|
|
||||||
p += sprintf(p, "libfdk-aac %s, ", lib_info[i].versionStr);
|
|
||||||
}
|
|
||||||
free(lib_info);
|
|
||||||
if (params->bitrate_mode)
|
|
||||||
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
|
||||||
else
|
|
||||||
sprintf(p, "CBR %dkbps",
|
|
||||||
aacEncoder_GetParam(encoder, AACENC_BITRATE) / 1000);
|
|
||||||
|
|
||||||
m4af_add_itmf_string_tag(m4af, M4AF_TAG_TOOL, tool_info);
|
|
||||||
}
|
|
||||||
if (m4af_finalize(m4af) < 0) {
|
if (m4af_finalize(m4af) < 0) {
|
||||||
fprintf(stderr, "ERROR: failed to finalize m4a\n");
|
fprintf(stderr, "ERROR: failed to finalize m4a\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -431,17 +733,6 @@ int finalize_m4a(m4af_writer_t *m4af, const aacenc_param_ex_t *params,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
const char *basename(const char *filename)
|
|
||||||
{
|
|
||||||
char *p = strrchr(filename, '/');
|
|
||||||
#ifdef _WIN32
|
|
||||||
char *q = strrchr(filename, '\\');
|
|
||||||
if (p < q) p = q;
|
|
||||||
#endif
|
|
||||||
return p ? p + 1 : filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
char *generate_output_filename(const char *filename, const char *ext)
|
char *generate_output_filename(const char *filename, const char *ext)
|
||||||
{
|
{
|
||||||
@ -452,7 +743,7 @@ char *generate_output_filename(const char *filename, const char *ext)
|
|||||||
p = malloc(ext_len + 6);
|
p = malloc(ext_len + 6);
|
||||||
sprintf(p, "stdin%s", ext);
|
sprintf(p, "stdin%s", ext);
|
||||||
} else {
|
} else {
|
||||||
const char *base = basename(filename);
|
const char *base = aacenc_basename(filename);
|
||||||
size_t ilen = strlen(base);
|
size_t ilen = strlen(base);
|
||||||
const char *ext_org = strrchr(base, '.');
|
const char *ext_org = strrchr(base, '.');
|
||||||
if (ext_org) ilen = ext_org - base;
|
if (ext_org) ilen = ext_org - base;
|
||||||
@ -462,9 +753,45 @@ char *generate_output_filename(const char *filename, const char *ext)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int parse_raw_spec(const char *spec, pcm_sample_description_t *desc)
|
||||||
|
{
|
||||||
|
unsigned bits;
|
||||||
|
unsigned char c_type, c_endian = 'L';
|
||||||
|
int type;
|
||||||
|
|
||||||
|
if (sscanf(spec, "%c%u%c", &c_type, &bits, &c_endian) < 2)
|
||||||
|
return -1;
|
||||||
|
c_type = toupper(c_type);
|
||||||
|
c_endian = toupper(c_endian);
|
||||||
|
|
||||||
|
if (c_type == 'S')
|
||||||
|
type = 1;
|
||||||
|
else if (c_type == 'U')
|
||||||
|
type = 2;
|
||||||
|
else if (c_type == 'F')
|
||||||
|
type = 4;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (c_endian == 'B')
|
||||||
|
type |= 8;
|
||||||
|
else if (c_endian != 'L')
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (c_type == 'F' && bits != 32 && bits != 64)
|
||||||
|
return -1;
|
||||||
|
if (c_type != 'F' && (bits < 8 || bits > 32))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
desc->sample_type = type;
|
||||||
|
desc->bits_per_channel = bits;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
wav_io_context_t wav_io = { read_callback, seek_callback };
|
wav_io_context_t wav_io = { read_callback, seek_callback, tell_callback };
|
||||||
m4af_io_callbacks_t m4af_io = {
|
m4af_io_callbacks_t m4af_io = {
|
||||||
write_callback, seek_callback, tell_callback };
|
write_callback, seek_callback, tell_callback };
|
||||||
aacenc_param_ex_t params = { 0 };
|
aacenc_param_ex_t params = { 0 };
|
||||||
@ -493,13 +820,30 @@ int main(int argc, char **argv)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
if (fstat(fileno(ifp), &stb) == 0 && (stb.st_mode & S_IFMT) != S_IFREG) {
|
||||||
if (fstat(fileno(ifp), &stb) == 0 && (stb.st_mode & S_IFMT) != S_IFREG)
|
|
||||||
wav_io.seek = 0;
|
wav_io.seek = 0;
|
||||||
|
wav_io.tell = 0;
|
||||||
if ((wavf = wav_open(&wav_io, ifp, params.ignore_length)) == 0) {
|
}
|
||||||
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
if (!params.is_raw) {
|
||||||
goto END;
|
if ((wavf = wav_open(&wav_io, ifp, params.ignore_length)) == 0) {
|
||||||
|
fprintf(stderr, "ERROR: broken / unsupported input file\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int bytes_per_channel;
|
||||||
|
pcm_sample_description_t desc = { 0 };
|
||||||
|
if (parse_raw_spec(params.raw_format, &desc) < 0) {
|
||||||
|
fprintf(stderr, "ERROR: invalid raw-format spec\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
desc.sample_rate = params.raw_rate;
|
||||||
|
desc.channels_per_frame = params.raw_channels;
|
||||||
|
bytes_per_channel = (desc.bits_per_channel + 7) / 8;
|
||||||
|
desc.bytes_per_frame = params.raw_channels * bytes_per_channel;
|
||||||
|
if ((wavf = raw_open(&wav_io, ifp, &desc)) == 0) {
|
||||||
|
fprintf(stderr, "ERROR: failed to open raw input\n");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sample_format = wav_get_format(wavf);
|
sample_format = wav_get_format(wavf);
|
||||||
|
|
||||||
@ -518,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;
|
||||||
@ -533,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,
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
@ -51,11 +53,14 @@ void aacenc_progress_init(aacenc_progress_t *progress, int64_t total,
|
|||||||
void aacenc_progress_update(aacenc_progress_t *progress, int64_t current,
|
void aacenc_progress_update(aacenc_progress_t *progress, int64_t current,
|
||||||
int period)
|
int period)
|
||||||
{
|
{
|
||||||
int percent = 100.0 * current / progress->total + .5;
|
|
||||||
double seconds = current / progress->timescale;
|
double seconds = current / progress->timescale;
|
||||||
double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
|
double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
|
||||||
double eta = ellapsed * (progress->total / (double)current - 1.0);
|
double speed = ellapsed ? seconds / ellapsed : 1.0;
|
||||||
double speed = ellapsed ? seconds / ellapsed : 0.0;
|
int percent = progress->total ? 100.0 * current / progress->total + .5
|
||||||
|
: 100;
|
||||||
|
double eta = current ? ellapsed * (progress->total / (double)current - 1.0)
|
||||||
|
: progress->total ? DBL_MAX : 0;
|
||||||
|
|
||||||
if (current < progress->processed + period)
|
if (current < progress->processed + period)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -80,7 +85,7 @@ void aacenc_progress_finish(aacenc_progress_t *progress, int64_t current)
|
|||||||
double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
|
double ellapsed = (aacenc_timer() - progress->start) / 1000.0;
|
||||||
aacenc_progress_update(progress, current, 0);
|
aacenc_progress_update(progress, current, 0);
|
||||||
if (progress->total == INT64_MAX)
|
if (progress->total == INT64_MAX)
|
||||||
fprintf(stderr, "\n%" PRId64 "samples processed in ", current);
|
fprintf(stderr, "\n%" PRId64 " samples processed in ", current);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "\n%" PRId64 "/%" PRId64 " samples processed in ",
|
fprintf(stderr, "\n%" PRId64 "/%" PRId64 " samples processed in ",
|
||||||
current, progress->total);
|
current, progress->total);
|
||||||
|
@ -38,6 +38,7 @@ struct wav_reader_t {
|
|||||||
pcm_sample_description_t sample_format;
|
pcm_sample_description_t sample_format;
|
||||||
int64_t length;
|
int64_t length;
|
||||||
int64_t position;
|
int64_t position;
|
||||||
|
int32_t data_offset;
|
||||||
int ignore_length;
|
int ignore_length;
|
||||||
int last_error;
|
int last_error;
|
||||||
wav_io_context_t io;
|
wav_io_context_t io;
|
||||||
@ -91,7 +92,7 @@ int riff_read(wav_reader_t *reader, void *buffer, uint32_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int riff_skip(wav_reader_t *reader, uint32_t count)
|
int riff_skip(wav_reader_t *reader, int64_t count)
|
||||||
{
|
{
|
||||||
char buff[8192];
|
char buff[8192];
|
||||||
int rc;
|
int rc;
|
||||||
@ -114,6 +115,37 @@ int riff_skip(wav_reader_t *reader, uint32_t count)
|
|||||||
return reader->last_error ? -1 : 0;
|
return reader->last_error ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int riff_seek(wav_reader_t *reader, int64_t off, int whence)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
if (reader->last_error)
|
||||||
|
return -1;
|
||||||
|
if (!reader->io.seek)
|
||||||
|
goto FAIL;
|
||||||
|
if ((rc = reader->io.seek(reader->io_cookie, off, whence)) < 0)
|
||||||
|
goto FAIL;
|
||||||
|
return 0;
|
||||||
|
FAIL:
|
||||||
|
reader->last_error = WAV_IO_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int64_t riff_tell(wav_reader_t *reader)
|
||||||
|
{
|
||||||
|
int64_t off;
|
||||||
|
|
||||||
|
if (reader->last_error || !reader->io.tell)
|
||||||
|
return -1;
|
||||||
|
off = reader->io.tell(reader->io_cookie);
|
||||||
|
if (off < 0) {
|
||||||
|
reader->last_error = WAV_IO_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return off;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int riff_read16(wav_reader_t *reader, uint16_t *value)
|
int riff_read16(wav_reader_t *reader, uint16_t *value)
|
||||||
{
|
{
|
||||||
@ -209,9 +241,8 @@ int riff_ds64(wav_reader_t *reader, int64_t *length)
|
|||||||
fcc == RIFF_FOURCC('d','s','6','4') && chunk_size >= 28);
|
fcc == RIFF_FOURCC('d','s','6','4') && chunk_size >= 28);
|
||||||
TRY_IO(riff_scan(reader, "QQQL",
|
TRY_IO(riff_scan(reader, "QQQL",
|
||||||
&riff_size, length, &sample_count, &table_size) != 4);
|
&riff_size, length, &sample_count, &table_size) != 4);
|
||||||
if (table_size == 0)
|
TRY_IO(riff_skip(reader, (chunk_size - 27) & ~1));
|
||||||
return 0;
|
reader->data_offset += (chunk_size + 9) & ~1;
|
||||||
reader->last_error = WAV_UNSUPPORTED_FORMAT;
|
|
||||||
FAIL:
|
FAIL:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -290,6 +321,8 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
|||||||
TRY_IO(riff_read32(reader, &fcc));
|
TRY_IO(riff_read32(reader, &fcc));
|
||||||
if (fcc != RIFF_FOURCC('W','A','V','E'))
|
if (fcc != RIFF_FOURCC('W','A','V','E'))
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
|
reader->data_offset = 12;
|
||||||
|
|
||||||
if (container == RIFF_FOURCC('R','F','6','4'))
|
if (container == RIFF_FOURCC('R','F','6','4'))
|
||||||
riff_ds64(reader, data_length);
|
riff_ds64(reader, data_length);
|
||||||
while ((fcc = riff_next_chunk(reader, &chunk_size)) != 0) {
|
while ((fcc = riff_next_chunk(reader, &chunk_size)) != 0) {
|
||||||
@ -299,9 +332,12 @@ int wav_parse(wav_reader_t *reader, int64_t *data_length)
|
|||||||
} else if (fcc == RIFF_FOURCC('d','a','t','a')) {
|
} else if (fcc == RIFF_FOURCC('d','a','t','a')) {
|
||||||
if (container == RIFF_FOURCC('R','I','F','F'))
|
if (container == RIFF_FOURCC('R','I','F','F'))
|
||||||
*data_length = chunk_size;
|
*data_length = chunk_size;
|
||||||
|
reader->data_offset += 8;
|
||||||
break;
|
break;
|
||||||
} else
|
} else {
|
||||||
TRY_IO(riff_skip(reader, (chunk_size + 1) & ~1));
|
TRY_IO(riff_skip(reader, (chunk_size + 1) & ~1));
|
||||||
|
}
|
||||||
|
reader->data_offset += (chunk_size + 9) & ~1;
|
||||||
}
|
}
|
||||||
if (fcc == RIFF_FOURCC('d','a','t','a'))
|
if (fcc == RIFF_FOURCC('d','a','t','a'))
|
||||||
return 0;
|
return 0;
|
||||||
@ -312,8 +348,9 @@ FAIL:
|
|||||||
wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||||
int ignore_length)
|
int ignore_length)
|
||||||
{
|
{
|
||||||
wav_reader_t *reader;
|
wav_reader_t *reader = 0;
|
||||||
int64_t data_length;
|
int64_t data_length;
|
||||||
|
unsigned bpf;
|
||||||
|
|
||||||
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -324,10 +361,43 @@ wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
|||||||
free(reader);
|
free(reader);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (ignore_length || !data_length ||
|
bpf = reader->sample_format.bytes_per_frame;
|
||||||
data_length % reader->sample_format.bytes_per_frame != 0)
|
if (ignore_length || !data_length || data_length % bpf)
|
||||||
reader->length = INT64_MAX;
|
reader->length = INT64_MAX;
|
||||||
else
|
else
|
||||||
reader->length = data_length / reader->sample_format.bytes_per_frame;
|
reader->length = data_length / bpf;
|
||||||
|
|
||||||
|
if (reader->length == INT64_MAX && reader->io.seek && reader->io.tell) {
|
||||||
|
if (reader->io.seek(reader->io_cookie, 0, SEEK_END) >= 0) {
|
||||||
|
int64_t size = reader->io.tell(reader->io_cookie);
|
||||||
|
if (size > 0)
|
||||||
|
reader->length = (size - reader->data_offset) / bpf;
|
||||||
|
reader->io.seek(reader->io_cookie, reader->data_offset, SEEK_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wav_reader_t *raw_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||||
|
const pcm_sample_description_t *desc)
|
||||||
|
{
|
||||||
|
wav_reader_t *reader = 0;
|
||||||
|
|
||||||
|
if ((reader = calloc(1, sizeof(wav_reader_t))) == 0)
|
||||||
|
return 0;
|
||||||
|
memcpy(&reader->io, io_ctx, sizeof(wav_io_context_t));
|
||||||
|
memcpy(&reader->sample_format, desc, sizeof(pcm_sample_description_t));
|
||||||
|
reader->io_cookie = io_cookie;
|
||||||
|
if (io_ctx->seek && io_ctx->tell) {
|
||||||
|
if (reader->io.seek(reader->io_cookie, 0, SEEK_END) >= 0) {
|
||||||
|
int64_t size = reader->io.tell(reader->io_cookie);
|
||||||
|
if (size > 0)
|
||||||
|
reader->length = size / desc->bytes_per_frame;
|
||||||
|
reader->io.seek(reader->io_cookie, reader->data_offset, SEEK_SET);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
reader->length = INT64_MAX;
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,16 +16,20 @@ enum wav_error_code {
|
|||||||
|
|
||||||
typedef int (*wav_read_callback)(void *cookie, void *data, uint32_t size);
|
typedef int (*wav_read_callback)(void *cookie, void *data, uint32_t size);
|
||||||
typedef int (*wav_seek_callback)(void *cookie, int64_t off, int whence);
|
typedef int (*wav_seek_callback)(void *cookie, int64_t off, int whence);
|
||||||
|
typedef int64_t (*wav_tell_callback)(void *cookie);
|
||||||
|
|
||||||
typedef struct wav_io_context_t {
|
typedef struct wav_io_context_t {
|
||||||
wav_read_callback read;
|
wav_read_callback read;
|
||||||
wav_seek_callback seek;
|
wav_seek_callback seek;
|
||||||
|
wav_tell_callback tell;
|
||||||
} wav_io_context_t;
|
} wav_io_context_t;
|
||||||
|
|
||||||
typedef struct wav_reader_t wav_reader_t;
|
typedef struct wav_reader_t wav_reader_t;
|
||||||
|
|
||||||
wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
wav_reader_t *wav_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||||
int ignore_length);
|
int ignore_length);
|
||||||
|
wav_reader_t *raw_open(wav_io_context_t *io_ctx, void *io_cookie,
|
||||||
|
const pcm_sample_description_t *desc);
|
||||||
const pcm_sample_description_t *wav_get_format(wav_reader_t *reader);
|
const pcm_sample_description_t *wav_get_format(wav_reader_t *reader);
|
||||||
int wav_read_frames(wav_reader_t *reader, void *buffer, unsigned nframes);
|
int wav_read_frames(wav_reader_t *reader, void *buffer, unsigned nframes);
|
||||||
int64_t wav_get_length(wav_reader_t *reader);
|
int64_t wav_get_length(wav_reader_t *reader);
|
||||||
|
Reference in New Issue
Block a user