Skip to content

Commit

Permalink
bug: 修复视频转录过程中进程挂了 TencentBlueKing#2775
Browse files Browse the repository at this point in the history
  • Loading branch information
felixncheng committed Nov 20, 2024
1 parent 78aeb71 commit c212be6
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit c212be6

Please sign in to comment.