mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-14 10:37:38 +01:00
Pass stream_index to FFmpeg manually for flexibility
This commit is contained in:
parent
3d90731c2c
commit
0103f449d0
@ -198,7 +198,9 @@ void free_at3plus(maiatrac3plus_codec_data *data);
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
/* ffmpeg_decoder */
|
||||
ffmpeg_codec_data * init_ffmpeg_offset(STREAMFILE *streamFile, uint64_t start, uint64_t size);
|
||||
ffmpeg_codec_data * init_ffmpeg_offset_index(STREAMFILE *streamFile, uint64_t start, uint64_t size, int stream_index);
|
||||
ffmpeg_codec_data * init_ffmpeg_header_offset(STREAMFILE *streamFile, uint8_t * header, uint64_t header_size, uint64_t start, uint64_t size);
|
||||
ffmpeg_codec_data * init_ffmpeg_header_offset_index(STREAMFILE *streamFile, uint8_t * header, uint64_t header_size, uint64_t start, uint64_t size, int stream_index);
|
||||
|
||||
void decode_ffmpeg(VGMSTREAM *stream, sample * outbuf, int32_t samples_to_do, int channels);
|
||||
void reset_ffmpeg(VGMSTREAM *vgmstream);
|
||||
|
@ -272,13 +272,16 @@ static int64_t ffmpeg_seek(void *opaque, int64_t offset, int whence) {
|
||||
/* MAIN INIT/DECODER */
|
||||
/* ******************************************** */
|
||||
|
||||
/**
|
||||
* Manually init FFmpeg, from an offset.
|
||||
* Used if the stream has internal data recognized by FFmpeg.
|
||||
*/
|
||||
ffmpeg_codec_data * init_ffmpeg_offset(STREAMFILE *streamFile, uint64_t start, uint64_t size) {
|
||||
return init_ffmpeg_header_offset(streamFile, NULL, 0, start, size);
|
||||
return init_ffmpeg_header_offset_index(streamFile, NULL,0, start,size, 0);
|
||||
}
|
||||
ffmpeg_codec_data * init_ffmpeg_offset_index(STREAMFILE *streamFile, uint64_t start, uint64_t size, int stream_index) {
|
||||
return init_ffmpeg_header_offset_index(streamFile, NULL,0, start,size, stream_index);
|
||||
}
|
||||
ffmpeg_codec_data * init_ffmpeg_header_offset(STREAMFILE *streamFile, uint8_t * header, uint64_t header_size, uint64_t start, uint64_t size) {
|
||||
return init_ffmpeg_header_offset_index(streamFile, header,header_size, start,size, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manually init FFmpeg, from a fake header / offset.
|
||||
@ -286,8 +289,10 @@ ffmpeg_codec_data * init_ffmpeg_offset(STREAMFILE *streamFile, uint64_t start, u
|
||||
* Takes a fake header, to trick FFmpeg into demuxing/decoding the stream.
|
||||
* This header will be seamlessly inserted before 'start' offset, and total filesize will be 'header_size' + 'size'.
|
||||
* The header buffer will be copied and memory-managed internally.
|
||||
* NULL header can used given if the stream has internal data recognized by FFmpeg at offset.
|
||||
* Stream index can be passed to FFmpeg, if the format has multiple streams (1=first).
|
||||
*/
|
||||
ffmpeg_codec_data * init_ffmpeg_header_offset(STREAMFILE *streamFile, uint8_t * header, uint64_t header_size, uint64_t start, uint64_t size) {
|
||||
ffmpeg_codec_data * init_ffmpeg_header_offset_index(STREAMFILE *streamFile, uint8_t * header, uint64_t header_size, uint64_t start, uint64_t size, int stream_index) {
|
||||
char filename[PATH_LIMIT];
|
||||
ffmpeg_codec_data * data;
|
||||
int errcode, i;
|
||||
@ -349,8 +354,7 @@ ffmpeg_codec_data * init_ffmpeg_header_offset(STREAMFILE *streamFile, uint8_t *
|
||||
streamCount++;
|
||||
|
||||
/* select Nth audio stream if specified, or first one */
|
||||
if (streamIndex < 0 ||
|
||||
(streamFile->stream_index > 0 && streamCount == streamFile->stream_index)) {
|
||||
if (streamIndex < 0 || (stream_index > 0 && streamCount == stream_index)) {
|
||||
codecPar = stream->codecpar;
|
||||
streamIndex = i;
|
||||
}
|
||||
@ -359,7 +363,7 @@ ffmpeg_codec_data * init_ffmpeg_header_offset(STREAMFILE *streamFile, uint8_t *
|
||||
if (i != streamIndex)
|
||||
stream->discard = AVDISCARD_ALL; /* disable demuxing for other streams */
|
||||
}
|
||||
if (streamCount < streamFile->stream_index) goto fail;
|
||||
if (streamCount < stream_index) goto fail;
|
||||
if (streamIndex < 0 || !codecPar) goto fail;
|
||||
|
||||
data->streamIndex = streamIndex;
|
||||
|
@ -8,6 +8,7 @@ static int bink_get_info(STREAMFILE *streamFile, int * out_total_streams, int *
|
||||
VGMSTREAM * init_vgmstream_bik(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
int channel_count = 0, loop_flag = 0, sample_rate = 0, num_samples = 0, total_streams = 0;
|
||||
int stream_index = streamFile->stream_index;
|
||||
|
||||
|
||||
/* check extension, case insensitive (bika = manually demuxed audio) */
|
||||
@ -34,7 +35,7 @@ VGMSTREAM * init_vgmstream_bik(STREAMFILE *streamFile) {
|
||||
#ifdef VGM_USE_FFMPEG
|
||||
{
|
||||
/* init_FFmpeg uses streamFile->stream_index internally, if specified */
|
||||
vgmstream->codec_data = init_ffmpeg_offset(streamFile, 0x0, get_streamfile_size(streamFile));
|
||||
vgmstream->codec_data = init_ffmpeg_offset_index(streamFile, 0x0, get_streamfile_size(streamFile), stream_index);
|
||||
if (!vgmstream->codec_data) goto fail;
|
||||
vgmstream->coding_type = coding_FFmpeg;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user