INFORMAÇÕES: Stream map '' matches no streams.
nov. 08, 2024 1:20:31 PM data.CommandRunnerImp runCommandlambda0
INFORMAÇÕES: To ignore this, add a trailing '?' to the map.
nov. 08, 2024 1:20:31 PM data.CommandRunnerImp runCommandlambda0
INFORMAÇÕES: Failed to set value '0:5' for option 'map': Invalid argument
nov. 08, 2024 1:20:31 PM data.CommandRunnerImp runCommandlambda0
INFORMAÇÕES: Error parsing options for output file C:\Users\xiyun\Downloads[ACESSE...HD-ELITE.ME]...Paprika.2006.BluRay.1080p.x264.DTS.5.1.Dual\Paprika.2006.BluRay.1080p.x264.DTS.5.1.Dual\Paprika.2006.BluRay.1080p.x264.DTS.5.1.Dual part 0_1.mp4.
nov. 08, 2024 1:20:31 PM data.CommandRunnerImp runCommandlambda0
INFORMAÇÕES: Error opening output files: Invalid argument
The error you're encountering is due to the way you're handling stream indices in your executeAdjustment function. Specifically, you're using the position of the streams in your list (the list index) rather than the actual stream indices as they exist in the media file. This leads to incorrect mapping in your ffmpeg command, resulting in errors like:
code
INFORMAÇÕES: Stream map '' matches no streams.
INFORMAÇÕES: Failed to set value '0:5' for option 'map': Invalid argument
In multimedia files, stream indices are not guaranteed to be sequential or start from 0. They are assigned based on the file's internal structure and can vary depending on how the file was created or processed previously.
Here's a detailed breakdown of the issue and how to fix it:
Issue with Using List Indexes Instead of Actual Stream Indices
In your code, you're using the onEachIndexed function to iterate over the streams and get their indices:
However, index here is just the position in the videoStreams list (starting from 0), not the actual stream index in the file. The actual stream index should come from the stream's metadata, typically accessed via a key like "index" in your stream maps.
Similarly, when you're mapping audio streams:
kotlin
val allAudioStreamIndexes = audioStreams.map { it["index"] ?: "" }
You're correctly getting the actual stream indices, but the issue lies in mapping the video streams.
Solution: Use Actual Stream Indices from the Stream Metadata
To fix the problem, you should retrieve the actual stream indices from the stream metadata and use those in your ffmpeg command mapping. Here's how you can modify your executeAdjustment function:
kotlin
private fun executeAdjustment(
stream: Streams,
selectedStreams: List<Map<String, String>>,
adjustmentValue: Double,
isAdvance: Boolean,
file: File,
) {
val selectedStreamIndexes = selectedStreams.map { it["index"] ?: "" }
if (selectedStreamIndexes.isEmpty()) {
logger.warning("No audio stream selected for adjustment.")
return
}
val inputFile = file.absolutePath
val outputFile = fileUtilities.generateUniqueFileName(file).absolutePath
val itsoffsetValue = if (isAdvance) -adjustmentValue else adjustmentValue
val command = mutableListOf<String>()
command.add("ffmpeg")
command.add("-copyts")
command.add("-i")
command.add(inputFile)
command.add("-itsoffset")
command.add(itsoffsetValue.toString())
command.add("-i")
command.add(inputFile)
val videoStreams = stream.getVideoStream(file)
val videoStreamIndexes = videoStreams.map { it["index"] ?: "" }
videoStreamIndexes.forEach { index ->
if (index.isNotEmpty()) {
command.add("-map")
command.add("0:$index")
}
}
val audioStreams = stream.getAudioStreams(file)
val allAudioStreamIndexes = audioStreams.map { it["index"] ?: "" }
val nonAdjustedIndexes = allAudioStreamIndexes.filter { !selectedStreamIndexes.contains(it) }
nonAdjustedIndexes.forEach { index ->
if (index.isNotEmpty()) {
command.add("-map")
command.add("0:$index")
}
}
selectedStreamIndexes.forEach { index ->
if (index.isNotEmpty()) {
command.add("-map")
command.add("1:$index")
}
}
command.add("-c")
command.add("copy")
command.add("-map_metadata")
command.add("0")
command.add("-avoid_negative_ts")
command.add("make_zero")
command.add(outputFile)
commandRunner.runCommand(
command.toTypedArray(),
stream.getDuration(file)
)
}
Explanation of Changes:
Get Actual Stream Indices: Instead of using onEachIndexed and relying on list positions, we extract the "index" from each stream's metadata.
kotlin
val videoStreamIndexes = videoStreams.map { it["index"] ?: "" }
Map Using Actual Indices: We loop over the videoStreamIndexes and add the correct mapping to the ffmpeg command only if the index is not empty.
kotlin
videoStreamIndexes.forEach { index ->
if (index.isNotEmpty()) {
command.add("-map")
command.add("0:$index")
}
}
Handle Audio Streams Similarly: We apply the same logic to audio streams, ensuring that we're using the actual indices.
Check for Empty Indices: We add a check to skip any entries where the index might be empty, preventing any invalid mappings.
By making these changes, your ffmpeg command will now correctly map the streams using their actual indices, which should resolve the errors you're encountering.
Example of Corrected ffmpeg Command:
Assuming your media file has video streams with actual indices of 0, 1, 4, etc., and audio streams with indices like 2, 3, 5, etc., the generated ffmpeg command would look something like:
This command correctly references the actual stream indices in the file, ensuring that ffmpeg maps the streams without errors.
Conclusion:
The key takeaway is that stream indices in multimedia files are not the same as their positions in the list returned by your code. Always use the actual stream indices from the metadata when constructing ffmpeg commands.
I recommend you update your code as shown above, and this should resolve the errors you're experiencing when running the ffmpeg command.