bop
This commit is contained in:
parent
3d798a13fb
commit
f3d42c06d2
@ -3,19 +3,19 @@ package no.iktdev.mediaprocessing.processer.ffmpeg
|
||||
import com.github.pgreze.process.Redirect
|
||||
import com.github.pgreze.process.process
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import no.iktdev.exfl.coroutines.Coroutines
|
||||
import no.iktdev.exfl.using
|
||||
import no.iktdev.mediaprocessing.shared.kafka.dto.events_result.FfmpegWorkRequestCreated
|
||||
import no.iktdev.mediaprocessing.processer.ProcesserEnv
|
||||
import java.io.BufferedWriter
|
||||
import no.iktdev.mediaprocessing.shared.kafka.dto.events_result.FfmpegWorkRequestCreated
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
class FfmpegWorker(val referenceId: String, val eventId: String, val info: FfmpegWorkRequestCreated, val listener: FfmpegWorkerEvents, val logDir: File) {
|
||||
val scope = Coroutines.io()
|
||||
val decoder = FfmpegProgressDecoder()
|
||||
private val outputCache = mutableListOf<String>()
|
||||
val logFile = logDir.using("$eventId-${File(info.outFile).nameWithoutExtension}.log")
|
||||
val logFile = logDir.using("$eventId-=-${File(info.outFile).nameWithoutExtension}.log")
|
||||
|
||||
val getOutputCache = outputCache.toList()
|
||||
|
||||
@ -53,6 +53,9 @@ class FfmpegWorker(val referenceId: String, val eventId: String, val info: Ffmpe
|
||||
}
|
||||
|
||||
private suspend fun execute(args: List<String>) {
|
||||
withContext(Dispatchers.IO) {
|
||||
logFile.createNewFile()
|
||||
}
|
||||
listener.onStarted(info)
|
||||
val processOp = process(
|
||||
ProcesserEnv.ffmpeg, *args.toTypedArray(),
|
||||
@ -65,6 +68,11 @@ class FfmpegWorker(val referenceId: String, val eventId: String, val info: Ffmpe
|
||||
|
||||
val result = processOp
|
||||
println(Gson().toJson(result))
|
||||
if (outputCache.isEmpty()) {
|
||||
result.output.forEach {
|
||||
onOutputChanged(it)
|
||||
}
|
||||
}
|
||||
onOutputChanged("Received exit code: ${result.resultCode}")
|
||||
if (result.resultCode != 0) {
|
||||
listener.onError(info, result.output.joinToString("\n"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user