diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/Mux.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/Mux.kt index 5c0f36fdb3..68a8055d35 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/Mux.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/Mux.kt @@ -53,6 +53,7 @@ class Mux { private var avio: AVIOContext? = null private var running: AtomicBoolean = AtomicBoolean(false) private var stopFlag: AtomicBoolean = AtomicBoolean(false) + private var writeHeader = false fun start() { if (!running.compareAndSet(false, true)) { @@ -126,7 +127,7 @@ class Mux { check(avformat.avformat_write_header(ofmtCtx, null as? PointerPointer<*>) >= 0) { "Error occurred when opening output file" } - + writeHeader = true var dts = 0L var count = 0L while (!stopFlag.get()) { @@ -196,7 +197,9 @@ class Mux { } if (ofmtCtx != null) { - avformat.av_write_trailer(ofmtCtx) + if (writeHeader) { + avformat.av_write_trailer(ofmtCtx) + } logger.info("Finish remux $fileName to ${outputFile!!.absolutePath}") if (ofmtCtx!!.oformat().flags() and avformat.AVFMT_NOFILE == 0) { avformat.avio_closep(ofmtCtx!!.pb())