Fixed duration to set progress
This commit is contained in:
parent
513815a9c5
commit
c464b110da
@ -111,7 +111,7 @@ class FfmpegRunner(
|
|||||||
fun onOutputChanged(line: String) {
|
fun onOutputChanged(line: String) {
|
||||||
outputCache.add(line)
|
outputCache.add(line)
|
||||||
writeToLog(line)
|
writeToLog(line)
|
||||||
|
decoder.defineDuration(line)
|
||||||
decoder.parseVideoProgress(outputCache.toList())?.let { decoded ->
|
decoder.parseVideoProgress(outputCache.toList())?.let { decoded ->
|
||||||
try {
|
try {
|
||||||
val _progress = decoder.getProgress(decoded)
|
val _progress = decoder.getProgress(decoded)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package no.iktdev.mediaprocessing.processer.ffmpeg.progress
|
package no.iktdev.mediaprocessing.processer.ffmpeg.progress
|
||||||
|
|
||||||
|
import mu.KotlinLogging
|
||||||
import java.lang.StringBuilder
|
import java.lang.StringBuilder
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
@ -7,6 +8,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
class FfmpegProgressDecoder {
|
class FfmpegProgressDecoder {
|
||||||
|
private val log = KotlinLogging.logger {}
|
||||||
|
|
||||||
data class DecodedProgressData(
|
data class DecodedProgressData(
|
||||||
val frame: Int?,
|
val frame: Int?,
|
||||||
@ -81,13 +83,29 @@ class FfmpegProgressDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun isDuration(value: String): Boolean {
|
val parsedDurations: MutableList<String> = mutableListOf()
|
||||||
return value.contains("Duration", ignoreCase = true)
|
var hasReadContinue: Boolean = false
|
||||||
}
|
fun defineDuration(value: String) {
|
||||||
fun setDuration(value: String) {
|
if (hasReadContinue) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (value.contains(Regex("progress=continue"))) {
|
||||||
|
hasReadContinue = true
|
||||||
|
}
|
||||||
|
|
||||||
val results = Regex("Duration:\\s*([^,]+),").find(value)?.groupValues?.firstOrNull()
|
val results = Regex("Duration:\\s*([^,]+),").find(value)?.groupValues?.firstOrNull()
|
||||||
durationTime = Regex("[0-9]+:[0-9]+:[0-9]+.[0-9]+").find(results.toString())?.value ?: "NA"
|
log.info { "Identified duration for estimation $results" }
|
||||||
duration = timeSpanToSeconds(results)
|
|
||||||
|
val parsedDuration = Regex("[0-9]+:[0-9]+:[0-9]+.[0-9]+").find(results.toString())?.value ?: return
|
||||||
|
if (!parsedDurations.contains(parsedDuration)) {
|
||||||
|
parsedDurations.add(parsedDuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
val longestDuration = parsedDurations.mapNotNull {
|
||||||
|
timeSpanToSeconds(it)
|
||||||
|
}.maxOrNull() ?: return
|
||||||
|
|
||||||
|
duration = longestDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun timeSpanToSeconds(time: String?): Int?
|
private fun timeSpanToSeconds(time: String?): Int?
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user