mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-31 12:23:44 +01:00
Fix some .aac encoder delay/sample issues
This commit is contained in:
parent
c5fc5799fb
commit
89ccb06747
@ -570,6 +570,7 @@ STREAMFILE* ffmpeg_get_streamfile(ffmpeg_codec_data* data);
|
||||
/* ffmpeg_decoder_utils.c (helper-things) */
|
||||
ffmpeg_codec_data* init_ffmpeg_atrac3_raw(STREAMFILE* sf, off_t offset, size_t data_size, int sample_count, int channels, int sample_rate, int block_align, int encoder_delay);
|
||||
ffmpeg_codec_data* init_ffmpeg_atrac3_riff(STREAMFILE* sf, off_t offset, int* out_samples);
|
||||
ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size);
|
||||
|
||||
|
||||
/* ffmpeg_decoder_custom_opus.c (helper-things) */
|
||||
|
@ -1006,6 +1006,7 @@ size_t aac_get_samples(STREAMFILE* sf, off_t start_offset, size_t bytes) {
|
||||
if (frame_size <= 0x08)
|
||||
break;
|
||||
|
||||
//;VGM_LOG("AAC: %lx, %x\n", offset, frame_size);
|
||||
frames++;
|
||||
offset += frame_size;
|
||||
}
|
||||
|
@ -187,4 +187,24 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ffmpeg_codec_data* init_ffmpeg_aac(STREAMFILE* sf, off_t offset, size_t size) {
|
||||
ffmpeg_codec_data* data = NULL;
|
||||
|
||||
data = init_ffmpeg_offset(sf, offset, size);
|
||||
if (!data) goto fail;
|
||||
|
||||
/* seeks to 0 eats first frame for whatever reason */
|
||||
ffmpeg_set_force_seek(data);
|
||||
|
||||
/* raw AAC doesn't set this, while some decoders like FAAD remove 1024,
|
||||
* but should be handled in container as each encoder uses its own value
|
||||
* (Apple: 2112, FAAD: probably 1024, etc) */
|
||||
//ffmpeg_set_skip_samples(data, 1024);
|
||||
|
||||
return data;
|
||||
fail:
|
||||
free_ffmpeg(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -66,6 +66,11 @@ VGMSTREAM* init_vgmstream_ffmpeg(STREAMFILE* sf) {
|
||||
/* hack for AAC files (will return 0 samples if not an actual file) */
|
||||
if (!num_samples && check_extensions(sf, "aac,laac")) {
|
||||
num_samples = aac_get_samples(sf, 0x00, get_streamfile_size(sf));
|
||||
|
||||
if (num_samples > 0) {
|
||||
/* FFmpeg seeks to 0 eats first frame for whatever reason */
|
||||
ffmpeg_set_force_seek(data);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VGM_USE_MPEG
|
||||
|
@ -42,15 +42,16 @@ VGMSTREAM* init_vgmstream_naac(STREAMFILE* sf) {
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset, data_size);
|
||||
vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
/* observed default, some files start without silence though seems correct when loop_start=0 */
|
||||
ffmpeg_set_skip_samples(vgmstream->codec_data, 1024); /* raw AAC doesn't set this */
|
||||
vgmstream->num_samples -= 1024; /* may end with 1024 of silence? */
|
||||
vgmstream->num_samples -= 1024;
|
||||
vgmstream->loop_end_sample -= 1024;
|
||||
/* for some reason last frame is ignored/bugged in various decoders (gives EOF errors) */
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
|
@ -42,14 +42,14 @@ VGMSTREAM* init_vgmstream_strm_abylight(STREAMFILE* sf) {
|
||||
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
vgmstream->codec_data = init_ffmpeg_offset(sf, start_offset, data_size);
|
||||
vgmstream->codec_data = init_ffmpeg_aac(sf, start_offset, data_size);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
vgmstream->layout_type = layout_none;
|
||||
|
||||
/* apparently none, or maybe ~600 */
|
||||
//ffmpeg_set_skip_samples(ffmpeg_data, 1024);
|
||||
//vgmstream->num_samples -= 1024;
|
||||
/* assumed, maybe a bit more */
|
||||
ffmpeg_set_skip_samples(vgmstream->codec_data, 1024);
|
||||
vgmstream->num_samples -= 1024;
|
||||
}
|
||||
#else
|
||||
goto fail;
|
||||
|
@ -468,14 +468,18 @@ VGMSTREAM* init_vgmstream_txth(STREAMFILE* sf) {
|
||||
case coding_FFmpeg: {
|
||||
ffmpeg_codec_data *ffmpeg_data = NULL;
|
||||
|
||||
if (txth.codec == FFMPEG || txth.codec == AC3 || txth.codec == AAC) {
|
||||
if (txth.codec == FFMPEG || txth.codec == AC3) {
|
||||
/* default FFmpeg */
|
||||
ffmpeg_data = init_ffmpeg_offset(txth.sf_body, txth.start_offset,txth.data_size);
|
||||
if ( !ffmpeg_data ) goto fail;
|
||||
ffmpeg_data = init_ffmpeg_offset(txth.sf_body, txth.start_offset, txth.data_size);
|
||||
if (!ffmpeg_data) goto fail;
|
||||
|
||||
if (vgmstream->num_samples == 0)
|
||||
vgmstream->num_samples = ffmpeg_data->totalSamples; /* sometimes works */
|
||||
}
|
||||
else if (txth.codec == AAC) {
|
||||
ffmpeg_data = init_ffmpeg_aac(txth.sf_body, txth.start_offset, txth.data_size);
|
||||
if (!ffmpeg_data) goto fail;
|
||||
}
|
||||
else {
|
||||
/* fake header FFmpeg */
|
||||
uint8_t buf[0x100];
|
||||
|
Loading…
x
Reference in New Issue
Block a user