X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fmain.c;h=1eb9a0e827c6338c9dc1095ca8e988d2e0b0eaec;hb=9b7e1ca68c3a594f6657ad1d3d151cd74b3e0228;hp=f4ecd756be0e238a9f6456a2c0a7ee7b09337f4c;hpb=fcfed4cd0c1a53898af6fb4ef43bf16cd74c2c1b;p=fdkaac.git diff --git a/src/main.c b/src/main.c index f4ecd75..1eb9a0e 100644 --- a/src/main.c +++ b/src/main.c @@ -117,9 +117,6 @@ PROGNAME " %s\n" " 29: MPEG-4 HE-AAC v2 (SBR+PS)\n" " 23: MPEG-4 AAC LD\n" " 39: MPEG-4 AAC ELD\n" -" 129: MPEG-2 AAC LC\n" -" 132: MPEG-2 HE-AAC (SBR)\n" -" 156: MPEG-2 HE-AAC v2 (SBR+PS)\n" " -b, --bitrate Bitrate in bits per seconds (for CBR)\n" " -m, --bitrate-mode Bitrate configuration\n" " 0: CBR (default)\n" @@ -563,11 +560,20 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader, ++encoded; if (encoded == 1 || encoded == 3) continue; - obp = &obuf[flip]; - if (write_sample(params->output_fp, m4af, obp) < 0) + + if (write_sample(params->output_fp, m4af, &obuf[flip]) < 0) goto END; ++frames_written; } while (remaining > 0); + /* + * When interrupted, we haven't pulled out last extrapolated frames + * from the reader. Therefore, we have to write the final outcome. + */ + if (g_interrupted) { + if (write_sample(params->output_fp, m4af, &obp[flip^1]) < 0) + goto END; + ++frames_written; + } } DONE: if (!params->silent) @@ -693,7 +699,6 @@ pcm_reader_t *open_input(aacenc_param_ex_t *params) { pcm_io_context_t io = { 0 }; pcm_reader_t *reader = 0; - struct stat stb = { 0 }; if ((params->input_fp = aacenc_fopen(params->input_filename, "rb")) == 0) { aacenc_fprintf(stderr, "ERROR: %s: %s\n", params->input_filename, @@ -701,8 +706,7 @@ pcm_reader_t *open_input(aacenc_param_ex_t *params) goto FAIL; } io.cookie = params->input_fp; - if (fstat(fileno(params->input_fp), &stb) == 0 - && (stb.st_mode & S_IFMT) == S_IFREG) + if (aacenc_seekable(params->input_fp)) io.vtbl = &pcm_io_vtbl; else io.vtbl = &pcm_io_vtbl_noseek; @@ -794,12 +798,14 @@ int main(int argc, char **argv) params.sbr_ratio = 2; } scale_shift = aacenc_is_dual_rate_sbr((aacenc_param_t*)¶ms); - params.sbr_signaling = - (params.transport_format == TT_MP4_LOAS) ? 2 : - (params.transport_format == TT_MP4_RAW) ? 1 : 0; - if (sbr_mode && !scale_shift) - params.sbr_signaling = 2; - + params.sbr_signaling = 0; + if (sbr_mode) { + if (params.transport_format == TT_MP4_LOAS || !scale_shift) + params.sbr_signaling = 2; + if (params.transport_format == TT_MP4_RAW && + aacenc_is_explicit_bw_compatible_sbr_signaling_available()) + params.sbr_signaling = 1; + } if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format, &aacinfo) < 0) goto END; @@ -825,9 +831,17 @@ int main(int argc, char **argv) params.output_fp)) < 0) goto END; m4af_set_num_channels(m4af, 0, sample_format->channels_per_frame); - m4af_set_decoder_specific_info(m4af, 0, - aacinfo.confBuf, aacinfo.confSize); m4af_set_fixed_frame_duration(m4af, 0, framelen >> scale_shift); + if (aacenc_is_explicit_bw_compatible_sbr_signaling_available()) + m4af_set_decoder_specific_info(m4af, 0, + aacinfo.confBuf, aacinfo.confSize); + else { + uint8_t mp4asc[32]; + uint32_t ascsize = sizeof(mp4asc); + aacenc_mp4asc((aacenc_param_t*)¶ms, aacinfo.confBuf, + aacinfo.confSize, mp4asc, &ascsize); + m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize); + } m4af_set_vbr_mode(m4af, 0, params.bitrate_mode); m4af_set_priming_mode(m4af, params.gapless_mode + 1); m4af_begin_write(m4af);