FFMPEG 版本3.2 releaseios
以前遇到過調用FFMPEG轉碼,kill一次沒法中止轉碼過程。ide
做爲一個記錄,具體緣由未知,奇怪的問題。函數
while (!received_sigterm) { int64_t cur_time= av_gettime_relative(); /* if 'q' pressed, exits */ if (stdin_interaction) if (check_keyboard_interaction(cur_time) < 0) break; /* check if there's any stream where output is still needed */ if (!need_output()) { av_log(NULL, AV_LOG_VERBOSE, "No more output streams to write to, finishing.\n"); break; } ret = transcode_step(); if (ret < 0 && ret != AVERROR_EOF) { char errbuf[128]; av_strerror(ret, errbuf, sizeof(errbuf)); av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", errbuf); break; } /* dump report by using the output first video and audio streams */ print_report(0, timer_start, cur_time); }
static volatile int received_sigterm = 0; static volatile int received_nb_signals = 0; static volatile int transcode_init_done = 0; static volatile int ffmpeg_exited = 0; static int main_return_code = 0; static void sigterm_handler(int sig) { received_sigterm = sig; received_nb_signals++; term_exit_sigsafe(); if(received_nb_signals > 3) { write(2/*STDERR_FILENO*/, "Received > 3 system signals, hard exiting\n", strlen("Received > 3 system signals, hard exiting\n")); exit(123); } }
也就是說只要執行函數sigterm_handler(),received_sigterm的值確定不爲0.ui
void term_init(void) { #if HAVE_TERMIOS_H if (!run_as_daemon && stdin_interaction) { struct termios tty; if (tcgetattr (0, &tty) == 0) { oldtty = tty; restore_tty = 1; tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP |INLCR|IGNCR|ICRNL|IXON); tty.c_oflag |= OPOST; tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN); tty.c_cflag &= ~(CSIZE|PARENB); tty.c_cflag |= CS8; tty.c_cc[VMIN] = 1; tty.c_cc[VTIME] = 0; tcsetattr (0, TCSANOW, &tty); } signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */ } #endif signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ #ifdef SIGXCPU signal(SIGXCPU, sigterm_handler); #endif #if HAVE_SETCONSOLECTRLHANDLER SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE); #endif }
個人理解是,只要kill ffmpeg進程,那麼確定會執行sigterm_handler()函數,也就是received_sigterm這個的值確定不爲0,會中止轉碼。spa
可是事實有可能不是這樣的,爲何哪?rest