mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
b87f2251a4 | |||
afe73f4916 | |||
fe2d3aa3e7 | |||
2f960ef8fd | |||
fb2b36350a | |||
f5363b23c3 | |||
9517c27537 | |||
d317e29d46 | |||
ffc230a83e | |||
70e912edba | |||
bd02d0e753 |
176
ChangeLog
176
ChangeLog
@ -0,0 +1,176 @@
|
|||||||
|
2013-09-07 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* updated ChangeLog with new git2changelog.py [HEAD]
|
||||||
|
|
||||||
|
2013-06-14 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* add --moov-before-mdat [v0.3.0]
|
||||||
|
|
||||||
|
2013-03-04 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix an error message
|
||||||
|
|
||||||
|
2013-03-03 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.2.0]
|
||||||
|
|
||||||
|
* add --gapless-mode
|
||||||
|
|
||||||
|
2013-02-20 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* simplify __timeb64 condition
|
||||||
|
|
||||||
|
* use fseeko64() on i686-pc-mingw32
|
||||||
|
|
||||||
|
2013-02-18 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix build issue on i686-pc-mingw (struct __timeb64 is missing)
|
||||||
|
|
||||||
|
2013-02-17 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.9]
|
||||||
|
|
||||||
|
* fix to accept option -C
|
||||||
|
|
||||||
|
2013-02-16 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.8]
|
||||||
|
|
||||||
|
* refine json metadata importing
|
||||||
|
|
||||||
|
* m4af: duplication check on adding tags
|
||||||
|
|
||||||
|
2013-02-15 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* add --tag-from-json [v0.1.7]
|
||||||
|
|
||||||
|
* fix implicit int variable decl.
|
||||||
|
|
||||||
|
* update m4af
|
||||||
|
|
||||||
|
2013-02-03 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.6]
|
||||||
|
|
||||||
|
* win32: change _wfopen() -> wfsopen()
|
||||||
|
|
||||||
|
2013-01-30 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* update README (add note for character encoding)
|
||||||
|
|
||||||
|
2013-01-28 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.5]
|
||||||
|
|
||||||
|
* gracefully shutdown on signals
|
||||||
|
|
||||||
|
2013-01-27 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix MSVC project build issue
|
||||||
|
|
||||||
|
2013-01-25 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.4]
|
||||||
|
|
||||||
|
* add --tag-from-file
|
||||||
|
|
||||||
|
2013-01-24 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* add --silent
|
||||||
|
|
||||||
|
2013-01-19 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* retab
|
||||||
|
|
||||||
|
* bump version [v0.1.3]
|
||||||
|
|
||||||
|
* fix crash on wrong long option, rename --ignore-length to --ignorelength
|
||||||
|
|
||||||
|
2013-01-17 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.2]
|
||||||
|
|
||||||
|
* compat_win32: free argv with atexit()
|
||||||
|
|
||||||
|
* take care of COPYRIGHT-SIGN in UTF-8
|
||||||
|
|
||||||
|
2013-01-15 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.1.1]
|
||||||
|
|
||||||
|
* fix return type of put_type_entry() to void
|
||||||
|
|
||||||
|
* add ADTS header size(7) to output byte length
|
||||||
|
|
||||||
|
2013-01-13 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix mp4 duration & version calcuration [v0.1.0]
|
||||||
|
|
||||||
|
2013-01-11 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* add support for xid
|
||||||
|
|
||||||
|
* support for i686-pc-mingw32 (missing _vscprintf)
|
||||||
|
|
||||||
|
2013-01-10 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.0.9]
|
||||||
|
|
||||||
|
* rename basename() -> aacenc_basename() and move to compat layer
|
||||||
|
|
||||||
|
2013-01-09 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* add --tag and --long-tag
|
||||||
|
|
||||||
|
* fix corner case of progress display
|
||||||
|
|
||||||
|
* calculate length from file size
|
||||||
|
|
||||||
|
* raw input support
|
||||||
|
|
||||||
|
2013-01-08 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* insert a white space in progress message
|
||||||
|
|
||||||
|
2013-01-07 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix typo of bitrate-mode option [v0.0.8]
|
||||||
|
|
||||||
|
* more static inlining (missed on the previous commit) [v0.0.7]
|
||||||
|
|
||||||
|
* check error of fread() and fwrite() [v0.0.6]
|
||||||
|
|
||||||
|
* change inline->static inline to follow C99 semantics (for Clang)
|
||||||
|
|
||||||
|
* explicitly add -lfdk-aac to LDADD in Makefile.am
|
||||||
|
|
||||||
|
* add some files to EXTRA_DIST in Makefile.am
|
||||||
|
|
||||||
|
* fixed a typo in usage message [v0.0.5]
|
||||||
|
|
||||||
|
2013-01-06 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* add MSVC projects
|
||||||
|
|
||||||
|
* add .gitattributes
|
||||||
|
|
||||||
|
* more tweak on configure.ac and Makefile.am (take care of getopt_long) [v0.0.4]
|
||||||
|
|
||||||
|
* use fstat() to test seekability of input file
|
||||||
|
|
||||||
|
* retrieve bitrate for tool tag with aacEncoder_GetParam()
|
||||||
|
|
||||||
|
* output to current working directory by default
|
||||||
|
|
||||||
|
2013-01-05 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* zero clear LIB_INFO before calling aacEncGetLibInfo() [v0.0.3]
|
||||||
|
|
||||||
|
* tweak configure.ac and Makefile.am
|
||||||
|
|
||||||
|
* update version.h [v0.0.2]
|
||||||
|
|
||||||
|
* fixed to clip before converting float to int
|
||||||
|
|
||||||
|
* initial commit [v0.0.1]
|
||||||
|
|
||||||
|
13
README
13
README
@ -32,6 +32,19 @@ look like the following:
|
|||||||
|
|
||||||
MSVC solution for Visual Studio 2010 is under MSVC directory.
|
MSVC solution for Visual Studio 2010 is under MSVC directory.
|
||||||
|
|
||||||
|
Available input format
|
||||||
|
----------------------
|
||||||
|
WAV (or RF64), upto 32bit int / 64bit float format is supported.
|
||||||
|
However, since FDK AAC encoder is implemented based on fixed point integer,
|
||||||
|
encoder itself treats 16bit input only.
|
||||||
|
Therefore, when feeding non-integer input, be careful so that input doesn't
|
||||||
|
exceed 0dBFS to avoid hard clips.
|
||||||
|
You might also want to apply dither/noise shape beforehand when your input
|
||||||
|
has higher resolution.
|
||||||
|
|
||||||
|
Note that fdkaac doesn't automatically resample for you
|
||||||
|
when input samplerate is not supported by AAC spec.
|
||||||
|
|
||||||
Tagging Options
|
Tagging Options
|
||||||
---------------
|
---------------
|
||||||
Generic tagging options like --tag, --tag-from-file, --long-tag allows you
|
Generic tagging options like --tag, --tag-from-file, --long-tag allows you
|
||||||
|
@ -31,8 +31,9 @@ AC_TYPE_UINT8_T
|
|||||||
AC_CHECK_TYPES([ptrdiff_t])
|
AC_CHECK_TYPES([ptrdiff_t])
|
||||||
|
|
||||||
AC_SYS_LARGEFILE
|
AC_SYS_LARGEFILE
|
||||||
|
AC_CHECK_TYPES([struct __timeb64],[],[],[[#include <sys/timeb.h>]])
|
||||||
AC_FUNC_FSEEKO
|
AC_FUNC_FSEEKO
|
||||||
AC_CHECK_FUNCS([sigaction gettimeofday nl_langinfo strdup _vscprintf])
|
AC_CHECK_FUNCS([sigaction gettimeofday nl_langinfo _vscprintf fseeko64])
|
||||||
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],[],[],[])
|
||||||
|
40
git2changelog.py
Executable file
40
git2changelog.py
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Copyright (C) 2013 nu774
|
||||||
|
# For conditions of distribution and use, see copyright notice in COPYING
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
from itertools import groupby
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
GITLOG_FMT = 'commit %H%nauthor %cn <%ae>%ndate %ad%nsubject %s%nref %d%n%n'
|
||||||
|
GITLOG_CMD = ['git','log','--date=short','--format={0}'.format(GITLOG_FMT)]
|
||||||
|
|
||||||
|
Commit = namedtuple('Commit', 'commit author date subject ref')
|
||||||
|
|
||||||
|
def parse_gitlog(stream):
|
||||||
|
re_decode_tag = re.compile(r'(?<=\()([^,)]+)')
|
||||||
|
commit = dict()
|
||||||
|
for line in stream:
|
||||||
|
fields = line.decode('utf-8').rstrip('\r\n').split(' ', 1)
|
||||||
|
if len(fields) == 2:
|
||||||
|
key, value = fields
|
||||||
|
if key == 'ref':
|
||||||
|
m = re_decode_tag.search(value)
|
||||||
|
value = ' [{0}]'.format(m.group()) if m else ''
|
||||||
|
commit[key] = value
|
||||||
|
elif commit:
|
||||||
|
yield Commit(**commit)
|
||||||
|
commit = dict()
|
||||||
|
|
||||||
|
output=sys.stdout.write
|
||||||
|
|
||||||
|
with Popen(GITLOG_CMD, shell=False, stdout=PIPE).stdout as pipe:
|
||||||
|
commits = parse_gitlog(pipe)
|
||||||
|
commits_by_date_author = groupby(commits, key=lambda x: (x.date, x.author))
|
||||||
|
for (date, author), commits in commits_by_date_author:
|
||||||
|
output('{0} {1}\n\n'.format(date, author))
|
||||||
|
for c in commits:
|
||||||
|
output(' * {0}{1}\n\n'.format(c.subject, c.ref))
|
@ -97,7 +97,7 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
|||||||
}
|
}
|
||||||
if (aacEncoder_SetParam(*encoder, AACENC_SIGNALING_MODE,
|
if (aacEncoder_SetParam(*encoder, AACENC_SIGNALING_MODE,
|
||||||
params->sbr_signaling) != AACENC_OK) {
|
params->sbr_signaling) != AACENC_OK) {
|
||||||
fprintf(stderr, "ERROR: unsupported transport format\n");
|
fprintf(stderr, "ERROR: failed to set SBR signaling mode\n");
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
if (params->adts_crc_check)
|
if (params->adts_crc_check)
|
||||||
|
@ -6,7 +6,10 @@
|
|||||||
#define COMPAT_H
|
#define COMPAT_H
|
||||||
|
|
||||||
#ifndef HAVE_FSEEKO
|
#ifndef HAVE_FSEEKO
|
||||||
# if _MSC_VER >= 1400
|
# if HAVE_FSEEKO64
|
||||||
|
# define fseeko fseeko64
|
||||||
|
# define ftello ftello64
|
||||||
|
# elif _MSC_VER >= 1400
|
||||||
# define fseeko _fseeki64
|
# define fseeko _fseeki64
|
||||||
# define ftello _ftelli64
|
# define ftello _ftelli64
|
||||||
# else
|
# else
|
||||||
|
@ -31,8 +31,13 @@ int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, _startupinfo *);
|
|||||||
|
|
||||||
int64_t aacenc_timer(void)
|
int64_t aacenc_timer(void)
|
||||||
{
|
{
|
||||||
|
#if HAVE_STRUCT___TIMEB64
|
||||||
struct __timeb64 tv;
|
struct __timeb64 tv;
|
||||||
_ftime64(&tv);
|
_ftime64(&tv);
|
||||||
|
#else
|
||||||
|
struct timeb tv;
|
||||||
|
ftime(&tv);
|
||||||
|
#endif
|
||||||
return (int64_t)tv.time * 1000 + tv.millitm;
|
return (int64_t)tv.time * 1000 + tv.millitm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
144
src/m4af.c
144
src/m4af.c
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#define m4af_realloc(memory,size) realloc(memory, size)
|
#define m4af_realloc(memory,size) realloc(memory, size)
|
||||||
#define m4af_free(memory) free(memory)
|
#define m4af_free(memory) free(memory)
|
||||||
|
#define m4af_max(a,b) ((a)<(b)?(b):(a))
|
||||||
|
|
||||||
#define M4AF_ATOM_WILD 0xffffffff
|
#define M4AF_ATOM_WILD 0xffffffff
|
||||||
|
|
||||||
@ -79,6 +80,7 @@ struct m4af_ctx_t {
|
|||||||
int64_t modification_time;
|
int64_t modification_time;
|
||||||
int64_t mdat_pos;
|
int64_t mdat_pos;
|
||||||
int64_t mdat_size;
|
int64_t mdat_size;
|
||||||
|
int priming_mode;
|
||||||
int last_error;
|
int last_error;
|
||||||
|
|
||||||
m4af_itmf_entry_t *itmf_table;
|
m4af_itmf_entry_t *itmf_table;
|
||||||
@ -148,6 +150,13 @@ int m4af_write(m4af_ctx_t *ctx, const void *data, uint32_t size)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
int m4af_write16(m4af_ctx_t *ctx, uint32_t data)
|
||||||
|
{
|
||||||
|
data = m4af_htob16(data);
|
||||||
|
return m4af_write(ctx, &data, 2);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int m4af_write32(m4af_ctx_t *ctx, uint32_t data)
|
int m4af_write32(m4af_ctx_t *ctx, uint32_t data)
|
||||||
{
|
{
|
||||||
@ -277,6 +286,11 @@ void m4af_set_priming(m4af_ctx_t *ctx, uint32_t track_idx,
|
|||||||
track->padding = padding;
|
track->padding = padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void m4af_set_priming_mode(m4af_ctx_t *ctx, int mode)
|
||||||
|
{
|
||||||
|
ctx->priming_mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int m4af_add_sample_entry(m4af_ctx_t *ctx, uint32_t track_idx,
|
int m4af_add_sample_entry(m4af_ctx_t *ctx, uint32_t track_idx,
|
||||||
uint32_t size, uint32_t delta)
|
uint32_t size, uint32_t delta)
|
||||||
@ -583,12 +597,13 @@ int m4af_set_iTunSMPB(m4af_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void m4af_update_box_size(m4af_ctx_t *ctx, int64_t pos)
|
uint32_t m4af_update_box_size(m4af_ctx_t *ctx, int64_t pos)
|
||||||
{
|
{
|
||||||
int64_t current_pos = m4af_tell(ctx);
|
int64_t current_pos = m4af_tell(ctx);
|
||||||
m4af_set_pos(ctx, pos);
|
m4af_set_pos(ctx, pos);
|
||||||
m4af_write32(ctx, current_pos - pos);
|
m4af_write32(ctx, current_pos - pos);
|
||||||
m4af_set_pos(ctx, current_pos);
|
m4af_set_pos(ctx, current_pos);
|
||||||
|
return current_pos - pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -756,7 +771,11 @@ void m4af_write_esds_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
, 2);
|
, 2);
|
||||||
m4af_write24(ctx, track->bufferSizeDB);
|
m4af_write24(ctx, track->bufferSizeDB);
|
||||||
m4af_write32(ctx, track->maxBitrate);
|
m4af_write32(ctx, track->maxBitrate);
|
||||||
|
#if 0
|
||||||
m4af_write32(ctx, track->avgBitrate);
|
m4af_write32(ctx, track->avgBitrate);
|
||||||
|
#else
|
||||||
|
m4af_write32(ctx, 0);
|
||||||
|
#endif
|
||||||
/* DecoderSpecificInfo */
|
/* DecoderSpecificInfo */
|
||||||
m4af_write_descriptor(ctx, 5, track->decSpecificInfoSize);
|
m4af_write_descriptor(ctx, 5, track->decSpecificInfoSize);
|
||||||
m4af_write(ctx, track->decSpecificInfo, track->decSpecificInfoSize);
|
m4af_write(ctx, track->decSpecificInfo, track->decSpecificInfoSize);
|
||||||
@ -823,12 +842,50 @@ void m4af_write_stsd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
m4af_update_box_size(ctx, pos);
|
m4af_update_box_size(ctx, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void m4af_write_sbgp_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
|
{
|
||||||
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
|
m4af_write(ctx,
|
||||||
|
"\0\0\0\034" /* size: 28 */
|
||||||
|
"sbgp" /* type */
|
||||||
|
"\0" /* version */
|
||||||
|
"\0\0\0" /* flags */
|
||||||
|
"roll" /* grouping_type */
|
||||||
|
"\0\0\0\001" /* entry_count: 1 */
|
||||||
|
, 20);
|
||||||
|
m4af_write32(ctx, track->num_samples);
|
||||||
|
m4af_write32(ctx, 1); /* group_description_index */
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void m4af_write_sgpd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
|
{
|
||||||
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
|
m4af_write(ctx,
|
||||||
|
"\0\0\0\032" /* size */
|
||||||
|
"sgpd" /* type */
|
||||||
|
"\001" /* version */
|
||||||
|
"\0\0\0" /* flags */
|
||||||
|
"roll" /* grouping_type */
|
||||||
|
"\0\0\0\002" /* default_length: 2 */
|
||||||
|
"\0\0\0\001" /* entry_count: 1 */
|
||||||
|
"\377\377" /* payload_data: -1 */
|
||||||
|
, 26);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void m4af_write_stbl_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
void m4af_write_stbl_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
{
|
{
|
||||||
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
m4af_write(ctx, "\0\0\0\0stbl", 8);
|
m4af_write(ctx, "\0\0\0\0stbl", 8);
|
||||||
m4af_write_stsd_box(ctx, track_idx);
|
m4af_write_stsd_box(ctx, track_idx);
|
||||||
|
if ((ctx->priming_mode & M4AF_PRIMING_MODE_EDTS) &&
|
||||||
|
(track->encoder_delay || track->padding)) {
|
||||||
|
m4af_write_sbgp_box(ctx, track_idx);
|
||||||
|
m4af_write_sgpd_box(ctx, track_idx);
|
||||||
|
}
|
||||||
m4af_write_stts_box(ctx, track_idx);
|
m4af_write_stts_box(ctx, track_idx);
|
||||||
m4af_write_stsc_box(ctx, track_idx);
|
m4af_write_stsc_box(ctx, track_idx);
|
||||||
m4af_write_stsz_box(ctx, track_idx);
|
m4af_write_stsz_box(ctx, track_idx);
|
||||||
@ -962,6 +1019,42 @@ void m4af_write_mdia_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
m4af_update_box_size(ctx, pos);
|
m4af_update_box_size(ctx, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void m4af_write_elst_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
|
{
|
||||||
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
|
uint8_t version;
|
||||||
|
int64_t duration = track->duration - track->encoder_delay - track->padding;
|
||||||
|
int64_t pos = m4af_tell(ctx);
|
||||||
|
duration = (double)duration / track->timescale * ctx->timescale + .5;
|
||||||
|
version = (duration > UINT32_MAX);
|
||||||
|
|
||||||
|
m4af_write(ctx, "\0\0\0\0elst", 8);
|
||||||
|
m4af_write(ctx, &version, 1);
|
||||||
|
m4af_write(ctx, "\0\0\0", 3); /* flags */
|
||||||
|
m4af_write32(ctx, 1); /* entry_count: 1 */
|
||||||
|
if (version) {
|
||||||
|
m4af_write64(ctx, duration);
|
||||||
|
m4af_write64(ctx, track->encoder_delay);
|
||||||
|
} else {
|
||||||
|
m4af_write32(ctx, duration);
|
||||||
|
m4af_write32(ctx, track->encoder_delay);
|
||||||
|
}
|
||||||
|
m4af_write16(ctx, 1); /* media_rate_integer */
|
||||||
|
m4af_write16(ctx, 0); /* media_rate_fraction */
|
||||||
|
m4af_update_box_size(ctx, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void m4af_write_edts_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
|
{
|
||||||
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
|
int64_t pos = m4af_tell(ctx);
|
||||||
|
m4af_write(ctx, "\0\0\0\0edts", 8);
|
||||||
|
m4af_write_elst_box(ctx, track_idx);
|
||||||
|
m4af_update_box_size(ctx, pos);
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void m4af_write_tkhd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
void m4af_write_tkhd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
{
|
{
|
||||||
@ -1015,9 +1108,13 @@ void m4af_write_tkhd_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
|||||||
static
|
static
|
||||||
void m4af_write_trak_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
void m4af_write_trak_box(m4af_ctx_t *ctx, uint32_t track_idx)
|
||||||
{
|
{
|
||||||
|
m4af_track_t *track = &ctx->track[track_idx];
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
m4af_write(ctx, "\0\0\0\0trak", 8);
|
m4af_write(ctx, "\0\0\0\0trak", 8);
|
||||||
m4af_write_tkhd_box(ctx, track_idx);
|
m4af_write_tkhd_box(ctx, track_idx);
|
||||||
|
if ((ctx->priming_mode & M4AF_PRIMING_MODE_EDTS) &&
|
||||||
|
(track->encoder_delay || track->padding))
|
||||||
|
m4af_write_edts_box(ctx, track_idx);
|
||||||
m4af_write_mdia_box(ctx, track_idx);
|
m4af_write_mdia_box(ctx, track_idx);
|
||||||
m4af_update_box_size(ctx, pos);
|
m4af_update_box_size(ctx, pos);
|
||||||
}
|
}
|
||||||
@ -1182,7 +1279,7 @@ void m4af_write_udta_box(m4af_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void m4af_write_moov_box(m4af_ctx_t *ctx)
|
uint32_t m4af_write_moov_box(m4af_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int64_t pos = m4af_tell(ctx);
|
int64_t pos = m4af_tell(ctx);
|
||||||
@ -1192,7 +1289,7 @@ void m4af_write_moov_box(m4af_ctx_t *ctx)
|
|||||||
m4af_write_trak_box(ctx, i);
|
m4af_write_trak_box(ctx, i);
|
||||||
if (ctx->num_tags)
|
if (ctx->num_tags)
|
||||||
m4af_write_udta_box(ctx);
|
m4af_write_udta_box(ctx);
|
||||||
m4af_update_box_size(ctx, pos);
|
return m4af_update_box_size(ctx, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -1210,10 +1307,35 @@ void m4af_finalize_mdat(m4af_ctx_t *ctx)
|
|||||||
m4af_set_pos(ctx, ctx->mdat_pos + ctx->mdat_size);
|
m4af_set_pos(ctx, ctx->mdat_pos + ctx->mdat_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int m4af_finalize(m4af_ctx_t *ctx)
|
static
|
||||||
|
void m4af_shift_mdat_pos(m4af_ctx_t *ctx, uint32_t offset)
|
||||||
|
{
|
||||||
|
unsigned i, j;
|
||||||
|
int64_t begin, end;
|
||||||
|
char buf[8192];
|
||||||
|
|
||||||
|
end = ctx->mdat_pos + ctx->mdat_size;
|
||||||
|
for (; (begin = m4af_max(ctx->mdat_pos, end - 8192)) < end; end = begin) {
|
||||||
|
m4af_set_pos(ctx, begin);
|
||||||
|
ctx->io.read(ctx->io_cookie, buf, end - begin);
|
||||||
|
m4af_set_pos(ctx, begin + offset);
|
||||||
|
m4af_write(ctx, buf, end - begin);
|
||||||
|
}
|
||||||
|
for (i = 0; i < ctx->num_tracks; ++i)
|
||||||
|
for (j = 0; j < ctx->track[i].num_chunks; ++j)
|
||||||
|
ctx->track[i].chunk_table[j].offset += offset;
|
||||||
|
ctx->mdat_pos += offset;
|
||||||
|
m4af_set_pos(ctx, ctx->mdat_pos - 16);
|
||||||
|
m4af_write_free_box(ctx, 0);
|
||||||
|
m4af_write(ctx, "\0\0\0\0mdat", 8);
|
||||||
|
m4af_finalize_mdat(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
int m4af_finalize(m4af_ctx_t *ctx, int optimize)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
m4af_track_t *track;
|
m4af_track_t *track;
|
||||||
|
uint32_t moov_size;
|
||||||
|
|
||||||
for (i = 0; i < ctx->num_tracks; ++i) {
|
for (i = 0; i < ctx->num_tracks; ++i) {
|
||||||
track = ctx->track + i;
|
track = ctx->track + i;
|
||||||
@ -1227,9 +1349,19 @@ int m4af_finalize(m4af_ctx_t *ctx)
|
|||||||
}
|
}
|
||||||
m4af_flush_chunk(ctx, i);
|
m4af_flush_chunk(ctx, i);
|
||||||
}
|
}
|
||||||
if (ctx->track[0].encoder_delay || ctx->track[0].padding)
|
track = ctx->track;
|
||||||
|
if ((ctx->priming_mode & M4AF_PRIMING_MODE_ITUNSMPB) &&
|
||||||
|
(track->encoder_delay || track->padding))
|
||||||
m4af_set_iTunSMPB(ctx);
|
m4af_set_iTunSMPB(ctx);
|
||||||
m4af_finalize_mdat(ctx);
|
m4af_finalize_mdat(ctx);
|
||||||
m4af_write_moov_box(ctx);
|
moov_size = m4af_write_moov_box(ctx);
|
||||||
|
if (optimize) {
|
||||||
|
int64_t pos;
|
||||||
|
m4af_shift_mdat_pos(ctx, moov_size + 1024);
|
||||||
|
m4af_set_pos(ctx, 32);
|
||||||
|
m4af_write_moov_box(ctx);
|
||||||
|
pos = m4af_tell(ctx);
|
||||||
|
m4af_write_free_box(ctx, ctx->mdat_pos - pos - 24);
|
||||||
|
}
|
||||||
return ctx->last_error;
|
return ctx->last_error;
|
||||||
}
|
}
|
||||||
|
10
src/m4af.h
10
src/m4af.h
@ -52,6 +52,12 @@ enum m4af_codec_type {
|
|||||||
M4AF_CODEC_TEXT = M4AF_FOURCC('t','e','x','t'),
|
M4AF_CODEC_TEXT = M4AF_FOURCC('t','e','x','t'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum m4af_priming_mode {
|
||||||
|
M4AF_PRIMING_MODE_ITUNSMPB = 1,
|
||||||
|
M4AF_PRIMING_MODE_EDTS = 2,
|
||||||
|
M4AF_PRIMING_MODE_BOTH = 3
|
||||||
|
};
|
||||||
|
|
||||||
typedef int (*m4af_read_callback)(void *cookie, void *buffer, uint32_t size);
|
typedef int (*m4af_read_callback)(void *cookie, void *buffer, uint32_t size);
|
||||||
typedef int (*m4af_write_callback)(void *cookie, const void *data,
|
typedef int (*m4af_write_callback)(void *cookie, const void *data,
|
||||||
uint32_t size);
|
uint32_t size);
|
||||||
@ -81,7 +87,7 @@ m4af_ctx_t *m4af_create(uint32_t codec, uint32_t timescale,
|
|||||||
|
|
||||||
int m4af_begin_write(m4af_ctx_t *ctx);
|
int m4af_begin_write(m4af_ctx_t *ctx);
|
||||||
|
|
||||||
int m4af_finalize(m4af_ctx_t *ctx);
|
int m4af_finalize(m4af_ctx_t *ctx, int optimize);
|
||||||
|
|
||||||
void m4af_teardown(m4af_ctx_t **ctx);
|
void m4af_teardown(m4af_ctx_t **ctx);
|
||||||
|
|
||||||
@ -94,6 +100,8 @@ int m4af_set_decoder_specific_info(m4af_ctx_t *ctx, uint32_t track_idx,
|
|||||||
void m4af_set_priming(m4af_ctx_t *ctx, uint32_t track_idx,
|
void m4af_set_priming(m4af_ctx_t *ctx, uint32_t track_idx,
|
||||||
uint32_t encoder_delay, uint32_t padding);
|
uint32_t encoder_delay, uint32_t padding);
|
||||||
|
|
||||||
|
void m4af_set_priming_mode(m4af_ctx_t *ctx, int mode);
|
||||||
|
|
||||||
void m4af_set_fixed_frame_duration(m4af_ctx_t *ctx, uint32_t track_idx,
|
void m4af_set_fixed_frame_duration(m4af_ctx_t *ctx, uint32_t track_idx,
|
||||||
uint32_t length);
|
uint32_t length);
|
||||||
|
|
||||||
|
29
src/main.c
29
src/main.c
@ -148,8 +148,13 @@ PROGNAME " %s\n"
|
|||||||
" transport layer\n"
|
" transport layer\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -o <filename> Output filename\n"
|
" -o <filename> Output filename\n"
|
||||||
|
" -G, --gapless-mode <n> Encoder delay signaling for gapless playback\n"
|
||||||
|
" 0: iTunSMPB (default)\n"
|
||||||
|
" 1: ISO standard (edts + sgpd)\n"
|
||||||
|
" 2: Both\n"
|
||||||
" --ignorelength Ignore length of WAV header\n"
|
" --ignorelength Ignore length of WAV header\n"
|
||||||
" -S, --silent Don't print progress messages\n"
|
" -S, --silent Don't print progress messages\n"
|
||||||
|
" --moov-before-mdat Place moov box before mdat box on m4a output\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"
|
||||||
@ -199,8 +204,10 @@ typedef struct aacenc_param_ex_t {
|
|||||||
|
|
||||||
char *input_filename;
|
char *input_filename;
|
||||||
char *output_filename;
|
char *output_filename;
|
||||||
|
unsigned gapless_mode;
|
||||||
unsigned ignore_length;
|
unsigned ignore_length;
|
||||||
int silent;
|
int silent;
|
||||||
|
int moov_before_mdat;
|
||||||
|
|
||||||
int is_raw;
|
int is_raw;
|
||||||
unsigned raw_channels;
|
unsigned raw_channels;
|
||||||
@ -218,6 +225,7 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
int ch;
|
int ch;
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
|
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
||||||
#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')
|
||||||
@ -239,8 +247,10 @@ 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' },
|
||||||
|
|
||||||
|
{ "gapless-mode", required_argument, 0, 'G' },
|
||||||
{ "ignorelength", no_argument, 0, 'I' },
|
{ "ignorelength", no_argument, 0, 'I' },
|
||||||
{ "silent", no_argument, 0, 'S' },
|
{ "silent", no_argument, 0, 'S' },
|
||||||
|
{ "moov-before-mdat", no_argument, 0, OPT_MOOV_BEFORE_MDAT },
|
||||||
|
|
||||||
{ "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 },
|
||||||
@ -268,7 +278,7 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
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:SR",
|
while ((ch = getopt_long(argc, argv, "hp:b:m:w:a:Ls:f:CP:G:Io:SR",
|
||||||
long_options, 0)) != EOF) {
|
long_options, 0)) != EOF) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@ -338,12 +348,22 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
case 'o':
|
case 'o':
|
||||||
params->output_filename = optarg;
|
params->output_filename = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'G':
|
||||||
|
if (sscanf(optarg, "%u", &n) != 1 || n > 2) {
|
||||||
|
fprintf(stderr, "invalid arg for gapless-mode\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->gapless_mode = n;
|
||||||
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
params->ignore_length = 1;
|
params->ignore_length = 1;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
params->silent = 1;
|
params->silent = 1;
|
||||||
break;
|
break;
|
||||||
|
case OPT_MOOV_BEFORE_MDAT:
|
||||||
|
params->moov_before_mdat = 1;
|
||||||
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
params->is_raw = 1;
|
params->is_raw = 1;
|
||||||
break;
|
break;
|
||||||
@ -567,7 +587,7 @@ int finalize_m4a(m4af_ctx_t *m4af, const aacenc_param_ex_t *params,
|
|||||||
|
|
||||||
put_tool_tag(m4af, params, encoder);
|
put_tool_tag(m4af, params, encoder);
|
||||||
|
|
||||||
if (m4af_finalize(m4af) < 0) {
|
if (m4af_finalize(m4af, params->moov_before_mdat) < 0) {
|
||||||
fprintf(stderr, "ERROR: failed to finalize m4a\n");
|
fprintf(stderr, "ERROR: failed to finalize m4a\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -634,7 +654,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
wav_io_context_t wav_io = { read_callback, seek_callback, tell_callback };
|
wav_io_context_t wav_io = { read_callback, seek_callback, tell_callback };
|
||||||
m4af_io_callbacks_t
|
m4af_io_callbacks_t
|
||||||
m4af_io = { 0, write_callback, seek_callback, tell_callback };
|
m4af_io = { read_callback, write_callback, seek_callback, tell_callback };
|
||||||
aacenc_param_ex_t params = { 0 };
|
aacenc_param_ex_t params = { 0 };
|
||||||
|
|
||||||
int result = 2;
|
int result = 2;
|
||||||
@ -698,7 +718,7 @@ int main(int argc, char **argv)
|
|||||||
params.output_filename = output_filename;
|
params.output_filename = output_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ofp = aacenc_fopen(params.output_filename, "wb")) == 0) {
|
if ((ofp = aacenc_fopen(params.output_filename, "wb+")) == 0) {
|
||||||
aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.output_filename,
|
aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.output_filename,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
@ -718,6 +738,7 @@ int main(int argc, char **argv)
|
|||||||
aacinfo.confSize);
|
aacinfo.confSize);
|
||||||
m4af_set_fixed_frame_duration(m4af, 0,
|
m4af_set_fixed_frame_duration(m4af, 0,
|
||||||
framelen >> downsampled_timescale);
|
framelen >> downsampled_timescale);
|
||||||
|
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
|
||||||
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,
|
||||||
|
Reference in New Issue
Block a user