| FFmpegKit Linux API 6.0

Loading...
Searching...
No Matches
FFmpegKitConfig.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <pthread.h>
23 extern "C" {
24 #include "libavutil/ffversion.h"
25 #include "libavutil/bprint.h"
26 #include "fftools_cmdutils.h"
27}
28#include "ArchDetect.h"
29#include "FFmpegKit.h"
30#include "FFmpegKitConfig.h"
31#include "FFmpegSession.h"
32#include "FFprobeKit.h"
33#include "FFprobeSession.h"
34#include "Level.h"
35#include "LogRedirectionStrategy.h"
36#include "MediaInformationSession.h"
37#include "Packages.h"
38#include "SessionState.h"
39#include <atomic>
40#include <mutex>
41#include <future>
42#include <condition_variable>
43#include <iostream>
44#include <fstream>
45#include <algorithm>
46
47 extern "C" {
48 void set_report_callback(void (*callback)(int, float, float, int64_t, double, double, double));
49 void cancel_operation(long id);
50}
51
55 static std::atomic<long> pipeIndexGenerator(1);
56
57/* Session history variables */
58 static int sessionHistorySize;
59 static std::map<long, std::shared_ptr<ffmpegkit::Session>> sessionHistoryMap;
60 static std::list<std::shared_ptr<ffmpegkit::Session>> sessionHistoryList;
61 static std::recursive_mutex sessionMutex;
62
64#define SESSION_MAP_SIZE 1000
65 static std::atomic<short> sessionMap[SESSION_MAP_SIZE];
66 static std::atomic<int> sessionInTransitMessageCountMap[SESSION_MAP_SIZE];
67
69 static ffmpegkit::LogCallback logCallback;
70
72 static ffmpegkit::StatisticsCallback statisticsCallback;
73
75 static ffmpegkit::FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback;
76 static ffmpegkit::FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback;
77 static ffmpegkit::MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback;
78
79 static ffmpegkit::LogRedirectionStrategy globalLogRedirectionStrategy;
80
82 static int redirectionEnabled;
83 static std::recursive_mutex callbackDataMutex;
84 static std::mutex callbackMutex;
85 static std::condition_variable callbackMonitor;
86 class CallbackData;
87 static std::list<CallbackData*> callbackDataList;
88
90 volatile int handleSIGQUIT = 1;
91 volatile int handleSIGINT = 1;
92 volatile int handleSIGTERM = 1;
93 volatile int handleSIGXCPU = 1;
94 volatile int handleSIGPIPE = 1;
95
97__thread long globalSessionId = 0;
98
100 int configuredLogLevel = ffmpegkit::LevelAVLogInfo;
101
102#ifdef __cplusplus
103 extern "C" {
104#endif
105
107 int ffmpeg_execute(int argc, char **argv);
108
110 int ffprobe_execute(int argc, char **argv);
111
112 void ffmpegkit_log_callback_function(void *ptr, int level, const char* format, va_list vargs);
113
114#ifdef __cplusplus
115}
116#endif
117
118 static std::once_flag ffmpegKitInitializerFlag;
119 static pthread_t callbackThread;
120
121 void* ffmpegKitInitialize();
122
123 const void* _ffmpegKitConfigInitializer{ffmpegKitInitialize()};
124
125 enum CallbackType {
126 LogType,
127 StatisticsType
128};
129
130 static bool fs_exists(const std::string& s, const bool isFile, const bool isDirectory) {
131 struct stat dir_info;
132
133 if (stat(s.c_str(), &dir_info) == 0) {
134 if (isFile && S_ISREG(dir_info.st_mode)) {
135 return true;
136 }
137 if (isDirectory && S_ISDIR(dir_info.st_mode)) {
138 return true;
139 }
140 }
141
142 return false;
143}
144
145 static bool fs_create_dir(const std::string& s) {
146 if (!fs_exists(s, false, true)) {
147 if (mkdir(s.c_str(), S_IRWXU | S_IRWXG | S_IROTH) != 0) {
148 std::cout << "Failed to create directory: " << s << ". Operation failed with " << errno << "." << std::endl;
149 return false;
150 }
151 }
152 return true;
153}
154
155 void deleteExpiredSessions() {
156 while (sessionHistoryList.size() > sessionHistorySize) {
157 auto first = sessionHistoryList.front();
158 if (first != nullptr) {
159 sessionHistoryList.pop_front();
160 sessionHistoryMap.erase(first->getSessionId());
161 }
162 }
163}
164
165 void addSessionToSessionHistory(const std::shared_ptr<ffmpegkit::Session> session) {
166 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
167
168 const long sessionId = session->getSessionId();
169
170 lock.lock();
171
172 /*
173 * ASYNC SESSIONS CALL THIS METHOD TWICE
174 * THIS CHECK PREVENTS ADDING THE SAME SESSION AGAIN
175 */
176 if (sessionHistoryMap.count(sessionId) == 0) {
177 sessionHistoryMap.insert({sessionId, session});
178 sessionHistoryList.push_back(session);
179 deleteExpiredSessions();
180 }
181
182 lock.unlock();
183}
184
188 class CallbackData {
189 public:
190 CallbackData(const long sessionId, const int logLevel, const AVBPrint* data) :
191 _type{LogType}, _sessionId{sessionId}, _logLevel{logLevel} {
192 av_bprint_init(&_logData, 0, AV_BPRINT_SIZE_UNLIMITED);
193 av_bprintf(&_logData, "%s", data->str);
194 }
195
196 CallbackData(const long sessionId,
197 const int videoFrameNumber,
198 const float videoFps,
199 const float videoQuality,
200 const int64_t size,
201 const double time,
202 const double bitrate,
203 const double speed) :
204 _type{StatisticsType},
205 _sessionId{sessionId},
206 _statisticsFrameNumber{videoFrameNumber},
207 _statisticsFps{videoFps},
208 _statisticsQuality{videoQuality},
209 _statisticsSize{size},
210 _statisticsTime{time},
211 _statisticsBitrate{bitrate},
212 _statisticsSpeed{speed} {
213 }
214
215 CallbackType getType() {
216 return _type;
217 }
218
219 long getSessionId() {
220 return _sessionId;
221 }
222
223 int getLogLevel() {
224 return _logLevel;
225 }
226
227 AVBPrint* getLogData() {
228 return &_logData;
229 }
230
231 int getStatisticsFrameNumber() {
232 return _statisticsFrameNumber;
233 }
234
235 float getStatisticsFps() {
236 return _statisticsFps;
237 }
238
239 float getStatisticsQuality() {
240 return _statisticsQuality;
241 }
242
243 int64_t getStatisticsSize() {
244 return _statisticsSize;
245 }
246
247 double getStatisticsTime() {
248 return _statisticsTime;
249 }
250
251 double getStatisticsBitrate() {
252 return _statisticsBitrate;
253 }
254
255 double getStatisticsSpeed() {
256 return _statisticsSpeed;
257 }
258
259 private:
260 CallbackType _type;
261 long _sessionId; // session id
262
263 int _logLevel; // log level
264 AVBPrint _logData; // log data
265
266 int _statisticsFrameNumber; // statistics frame number
267 float _statisticsFps; // statistics fps
268 float _statisticsQuality; // statistics quality
269 int64_t _statisticsSize; // statistics size
270 double _statisticsTime; // statistics time
271 double _statisticsBitrate; // statistics bitrate
272 double _statisticsSpeed; // statistics speed
273};
274
280 static void callbackWait(int milliSeconds) {
281 std::unique_lock<std::mutex> callbackLock{callbackMutex};
282 callbackMonitor.wait_for(callbackLock, std::chrono::milliseconds(milliSeconds));
283}
284
288 static void callbackNotify() {
289 callbackMonitor.notify_one();
290}
291
292 static const char *avutil_log_get_level_str(int level) {
293 switch (level) {
294 case AV_LOG_STDERR:
295 return "stderr";
296 case AV_LOG_QUIET:
297 return "quiet";
298 case AV_LOG_DEBUG:
299 return "debug";
300 case AV_LOG_VERBOSE:
301 return "verbose";
302 case AV_LOG_INFO:
303 return "info";
304 case AV_LOG_WARNING:
305 return "warning";
306 case AV_LOG_ERROR:
307 return "error";
308 case AV_LOG_FATAL:
309 return "fatal";
310 case AV_LOG_PANIC:
311 return "panic";
312 default:
313 return "";
314 }
315}
316
317 static void avutil_log_format_line(void *avcl, int level, const char *fmt, va_list vl, AVBPrint part[4], int *print_prefix) {
318 int flags = av_log_get_flags();
319 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
320 av_bprint_init(part+0, 0, 1);
321 av_bprint_init(part+1, 0, 1);
322 av_bprint_init(part+2, 0, 1);
323 av_bprint_init(part+3, 0, 65536);
324
325 if (*print_prefix && avc) {
326 if (avc->parent_log_context_offset) {
327 AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
328 avc->parent_log_context_offset);
329 if (parent && *parent) {
330 av_bprintf(part+0, "[%s @ %p] ",
331 (*parent)->item_name(parent), parent);
332 }
333 }
334 av_bprintf(part+1, "[%s @ %p] ",
335 avc->item_name(avcl), avcl);
336 }
337
338 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL))
339 av_bprintf(part+2, "[%s] ", avutil_log_get_level_str(level));
340
341 av_vbprintf(part+3, fmt, vl);
342
343 if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) {
344 char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0;
345 *print_prefix = lastc == '\n' || lastc == '\r';
346 }
347}
348
349 static void avutil_log_sanitize(char *line) {
350 while(*line){
351 if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
352 *line='?';
353 line++;
354 }
355}
356
363 static void logCallbackDataAdd(int level, AVBPrint *data) {
364 std::unique_lock<std::recursive_mutex> lock(callbackDataMutex, std::defer_lock);
365 CallbackData* callbackData = new CallbackData(globalSessionId, level, data);
366
367 lock.lock();
368 callbackDataList.push_back(callbackData);
369 lock.unlock();
370
371 callbackNotify();
372
373 std::atomic_fetch_add(&sessionInTransitMessageCountMap[globalSessionId % SESSION_MAP_SIZE], 1);
374}
375
379 static void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_t size, int time, double bitrate, double speed) {
380 std::unique_lock<std::recursive_mutex> lock(callbackDataMutex, std::defer_lock);
381 CallbackData* callbackData = new CallbackData(globalSessionId, frameNumber, fps, quality, size, time, bitrate, speed);
382
383 lock.lock();
384 callbackDataList.push_back(callbackData);
385 lock.unlock();
386
387 callbackNotify();
388
389 std::atomic_fetch_add(&sessionInTransitMessageCountMap[globalSessionId % SESSION_MAP_SIZE], 1);
390}
391
395 static CallbackData *callbackDataRemove() {
396 std::unique_lock<std::recursive_mutex> lock(callbackDataMutex, std::defer_lock);
397 CallbackData* newData = nullptr;
398
399 lock.lock();
400 if (callbackDataList.size() > 0) {
401 newData = callbackDataList.front();
402 callbackDataList.pop_front();
403 }
404 lock.unlock();
405
406 return newData;
407}
408
414 static void registerSessionId(long sessionId) {
415 std::atomic_store(&sessionMap[sessionId % SESSION_MAP_SIZE], (short)1);
416}
417
423 static void removeSession(long sessionId) {
424 std::atomic_store(&sessionMap[sessionId % SESSION_MAP_SIZE], (short)0);
425}
426
427#ifdef __cplusplus
428 extern "C" {
429#endif
430
436 void cancelSession(long sessionId) {
437 std::atomic_store(&sessionMap[sessionId % SESSION_MAP_SIZE], (short)2);
438}
439
446 int cancelRequested(long sessionId) {
447 if (std::atomic_load(&sessionMap[sessionId % SESSION_MAP_SIZE]) == 2) {
448 return 1;
449 } else {
450 return 0;
451 }
452}
453
454#ifdef __cplusplus
455}
456#endif
457
463 static void resetMessagesInTransmit(long sessionId) {
464 std::atomic_store(&sessionInTransitMessageCountMap[sessionId % SESSION_MAP_SIZE], 0);
465}
466
475 void ffmpegkit_log_callback_function(void *ptr, int level, const char* format, va_list vargs) {
476 AVBPrint fullLine;
477 AVBPrint part[4];
478 int print_prefix = 1;
479
480 // DO NOT PROCESS UNWANTED LOGS
481 if (level >= 0) {
482 level &= 0xff;
483 }
484 int activeLogLevel = av_log_get_level();
485
486 // LevelAVLogStdErr logs are always redirected
487 if ((activeLogLevel == ffmpegkit::LevelAVLogQuiet && level != ffmpegkit::LevelAVLogStdErr) || (level > activeLogLevel)) {
488 return;
489 }
490
491 av_bprint_init(&fullLine, 0, AV_BPRINT_SIZE_UNLIMITED);
492
493 avutil_log_format_line(ptr, level, format, vargs, part, &print_prefix);
494 avutil_log_sanitize(part[0].str);
495 avutil_log_sanitize(part[1].str);
496 avutil_log_sanitize(part[2].str);
497 avutil_log_sanitize(part[3].str);
498
499 // COMBINE ALL 4 LOG PARTS
500 av_bprintf(&fullLine, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
501
502 if (fullLine.len > 0) {
503 logCallbackDataAdd(level, &fullLine);
504 }
505
506 av_bprint_finalize(part, NULL);
507 av_bprint_finalize(part+1, NULL);
508 av_bprint_finalize(part+2, NULL);
509 av_bprint_finalize(part+3, NULL);
510 av_bprint_finalize(&fullLine, NULL);
511}
512
524 void ffmpegkit_statistics_callback_function(int frameNumber, float fps, float quality, int64_t size, double time, double bitrate, double speed) {
525 statisticsCallbackDataAdd(frameNumber, fps, quality, size, time, bitrate, speed);
526}
527
528 static void process_log(long sessionId, int levelValueInt, AVBPrint* logMessage) {
529 int activeLogLevel = av_log_get_level();
530 ffmpegkit::Level levelValue = static_cast<ffmpegkit::Level>(levelValueInt);
531 std::shared_ptr<ffmpegkit::Log> log = std::make_shared<ffmpegkit::Log>(sessionId, levelValue, logMessage->str);
532 bool globalCallbackDefined = false;
533 bool sessionCallbackDefined = false;
534 ffmpegkit::LogRedirectionStrategy activeLogRedirectionStrategy = globalLogRedirectionStrategy;
535
536 // LevelAVLogStdErr logs are always redirected
537 if ((activeLogLevel == ffmpegkit::LevelAVLogQuiet && levelValue != ffmpegkit::LevelAVLogStdErr) || (levelValue > activeLogLevel)) {
538 // LOG NEITHER PRINTED NOR FORWARDED
539 return;
540 }
541
542 auto session = ffmpegkit::FFmpegKitConfig::getSession(sessionId);
543 if (session != nullptr) {
544 activeLogRedirectionStrategy = session->getLogRedirectionStrategy();
545 session->addLog(log);
546
547 ffmpegkit::LogCallback sessionLogCallback = session->getLogCallback();
548 if (sessionLogCallback != nullptr) {
549 sessionCallbackDefined = true;
550
551 try {
552 // NOTIFY SESSION CALLBACK DEFINED
553 sessionLogCallback(log);
554 } catch(const std::exception& exception) {
555 std::cout << "Exception thrown inside session log callback. " << exception.what() << std::endl;
556 }
557 }
558 }
559
560 ffmpegkit::LogCallback globalLogCallback = logCallback;
561 if (globalLogCallback != nullptr) {
562 globalCallbackDefined = true;
563
564 try {
565 // NOTIFY GLOBAL CALLBACK DEFINED
566 globalLogCallback(log);
567 } catch(const std::exception& exception) {
568 std::cout << "Exception thrown inside global log callback. " << exception.what() << std::endl;
569 }
570 }
571
572 // EXECUTE THE LOG STRATEGY
573 switch (activeLogRedirectionStrategy) {
574 case ffmpegkit::LogRedirectionStrategyNeverPrintLogs: {
575 return;
576 }
577 case ffmpegkit::LogRedirectionStrategyPrintLogsWhenGlobalCallbackNotDefined: {
578 if (globalCallbackDefined) {
579 return;
580 }
581 }
582 break;
583 case ffmpegkit::LogRedirectionStrategyPrintLogsWhenSessionCallbackNotDefined: {
584 if (sessionCallbackDefined) {
585 return;
586 }
587 }
588 break;
589 case ffmpegkit::LogRedirectionStrategyPrintLogsWhenNoCallbacksDefined: {
590 if (globalCallbackDefined || sessionCallbackDefined) {
591 return;
592 }
593 }
594 break;
595 case ffmpegkit::LogRedirectionStrategyAlwaysPrintLogs: {
596 }
597 break;
598 }
599
600 // PRINT LOGS
601 switch (levelValue) {
602 case ffmpegkit::LevelAVLogQuiet:
603 // PRINT NO OUTPUT
604 break;
605 default:
606 // WRITE TO STDOUT
607 std::cout << ffmpegkit::FFmpegKitConfig::logLevelToString(levelValue) << ": " << logMessage->str;
608 break;
609 }
610}
611
612 void process_statistics(long sessionId, int videoFrameNumber, float videoFps, float videoQuality, long size, double time, double bitrate, double speed) {
613 std::shared_ptr<ffmpegkit::Statistics> statistics = std::make_shared<ffmpegkit::Statistics>(sessionId, videoFrameNumber, videoFps, videoQuality, size, time, bitrate, speed);
614
615 auto session = ffmpegkit::FFmpegKitConfig::getSession(sessionId);
616 if (session != nullptr && session->isFFmpeg()) {
617 std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegSession = std::static_pointer_cast<ffmpegkit::FFmpegSession>(session);
618 ffmpegSession->addStatistics(statistics);
619
620 ffmpegkit::StatisticsCallback sessionStatisticsCallback = ffmpegSession->getStatisticsCallback();
621 if (sessionStatisticsCallback != nullptr) {
622 try {
623 sessionStatisticsCallback(statistics);
624 } catch(const std::exception& exception) {
625 std::cout << "Exception thrown inside session statistics callback. " << exception.what() << std::endl;
626 }
627 }
628 }
629
630 ffmpegkit::StatisticsCallback globalStatisticsCallback = statisticsCallback;
631 if (globalStatisticsCallback != nullptr) {
632 try {
633 globalStatisticsCallback(statistics);
634 } catch(const std::exception& exception) {
635 std::cout << "Exception thrown inside global statistics callback. " << exception.what() << std::endl;
636 }
637 }
638}
639
643 void *callbackThreadFunction(void *pointer) {
644 int activeLogLevel = av_log_get_level();
645 if ((activeLogLevel != ffmpegkit::LevelAVLogQuiet) && (ffmpegkit::LevelAVLogDebug <= activeLogLevel)) {
646 std::cout << "Async callback block started." << std::endl;
647 }
648
649 while(redirectionEnabled) {
650 try {
651 CallbackData* callbackData = callbackDataRemove();
652
653 if (callbackData != nullptr) {
654
655 if (callbackData->getType() == LogType) {
656 process_log(callbackData->getSessionId(), callbackData->getLogLevel(), callbackData->getLogData());
657 av_bprint_finalize(callbackData->getLogData(), NULL);
658 } else {
659 process_statistics(callbackData->getSessionId(),
660 callbackData->getStatisticsFrameNumber(),
661 callbackData->getStatisticsFps(),
662 callbackData->getStatisticsQuality(),
663 callbackData->getStatisticsSize(),
664 callbackData->getStatisticsTime(),
665 callbackData->getStatisticsBitrate(),
666 callbackData->getStatisticsSpeed());
667 }
668
669 std::atomic_fetch_sub(&sessionInTransitMessageCountMap[callbackData->getSessionId() % SESSION_MAP_SIZE], 1);
670
671 } else {
672 callbackWait(100);
673 }
674
675 } catch(const std::exception& exception) {
676 activeLogLevel = av_log_get_level();
677 if ((activeLogLevel != ffmpegkit::LevelAVLogQuiet) && (ffmpegkit::LevelAVLogWarning <= activeLogLevel)) {
678 std::cout << "Async callback block received error: " << exception.what() << std::endl;
679 }
680 }
681 }
682
683 activeLogLevel = av_log_get_level();
684 if ((activeLogLevel != ffmpegkit::LevelAVLogQuiet) && (ffmpegkit::LevelAVLogDebug <= activeLogLevel)) {
685 std::cout << "Async callback block stopped." << std::endl;
686 }
687
688 return NULL;
689}
690
691 static int executeFFmpeg(const long sessionId, const std::shared_ptr<std::list<std::string>> arguments) {
692 const char* LIB_NAME = "ffmpeg";
693
694 // SETS DEFAULT LOG LEVEL BEFORE STARTING A NEW RUN
695 av_log_set_level(configuredLogLevel);
696
697 char **commandCharPArray = (char **)av_malloc(sizeof(char*) * (arguments->size() + 1));
698
699 /* PRESERVE USAGE FORMAT
700 *
701 * ffmpeg <arguments>
702 */
703 commandCharPArray[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1));
704 strcpy(commandCharPArray[0], LIB_NAME);
705
706 // PREPARE ARRAY ELEMENTS
707 int i = 0;
708 for (auto it=arguments->begin(); it != arguments->end(); it++, i++) {
709 commandCharPArray[i + 1] = (char*)it->c_str();
710 }
711
712 // REGISTER THE ID BEFORE STARTING THE SESSION
713 globalSessionId = sessionId;
714 registerSessionId(sessionId);
715
716 resetMessagesInTransmit(sessionId);
717
718 // RUN
719 int returnCode = ffmpeg_execute((arguments->size() + 1), commandCharPArray);
720
721 // ALWAYS REMOVE THE ID FROM THE MAP
722 removeSession(sessionId);
723
724 // CLEANUP
725 av_free(commandCharPArray[0]);
726 av_free(commandCharPArray);
727
728 return returnCode;
729}
730
731 int executeFFprobe(const long sessionId, const std::shared_ptr<std::list<std::string>> arguments) {
732 const char* LIB_NAME = "ffprobe";
733
734 // SETS DEFAULT LOG LEVEL BEFORE STARTING A NEW RUN
735 av_log_set_level(configuredLogLevel);
736
737 char **commandCharPArray = (char **)av_malloc(sizeof(char*) * (arguments->size() + 1));
738
739 /* PRESERVE USAGE FORMAT
740 *
741 * ffprobe <arguments>
742 */
743 commandCharPArray[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1));
744 strcpy(commandCharPArray[0], LIB_NAME);
745
746 // PREPARE ARRAY ELEMENTS
747 int i = 0;
748 for (auto it=arguments->begin(); it != arguments->end(); it++, i++) {
749 commandCharPArray[i + 1] = (char*)it->c_str();
750 }
751
752 // REGISTER THE ID BEFORE STARTING THE SESSION
753 globalSessionId = sessionId;
754 registerSessionId(sessionId);
755
756 resetMessagesInTransmit(sessionId);
757
758 // RUN
759 int returnCode = ffprobe_execute((arguments->size() + 1), commandCharPArray);
760
761 // ALWAYS REMOVE THE ID FROM THE MAP
762 removeSession(sessionId);
763
764 // CLEANUP
765 av_free(commandCharPArray[0]);
766 av_free(commandCharPArray);
767
768 return returnCode;
769}
770
771 void* ffmpegKitInitialize() {
772 std::call_once(ffmpegKitInitializerFlag, [](){
773 std::cout << "Loading ffmpeg-kit." << std::endl;
774
775 sessionHistorySize = 10;
776
777 for(int i = 0; i<SESSION_MAP_SIZE; i++) {
778 std::atomic_init(&sessionMap[i], (short)0);
779 std::atomic_init(&sessionInTransitMessageCountMap[i], 0);
780 }
781
782 logCallback = nullptr;
783 statisticsCallback = nullptr;
784 ffmpegSessionCompleteCallback = nullptr;
785 ffprobeSessionCompleteCallback = nullptr;
786 mediaInformationSessionCompleteCallback = nullptr;
787
788 globalLogRedirectionStrategy = ffmpegkit::LogRedirectionStrategyPrintLogsWhenNoCallbacksDefined;
789
790 redirectionEnabled = 0;
791
792 ffmpegkit::FFmpegKitConfig::enableRedirection();
793
794 std::cout << "Loaded ffmpeg-kit-" << ffmpegkit::Packages::getPackageName() << "-" << ffmpegkit::ArchDetect::getArch() << "-" << ffmpegkit::FFmpegKitConfig::getVersion() << "-" << ffmpegkit::FFmpegKitConfig::getBuildDate() << "." << std::endl;
795 });
796
797 return NULL;
798}
799
800 void ffmpegkit::FFmpegKitConfig::enableRedirection() {
801 std::unique_lock<std::recursive_mutex> lock(callbackDataMutex, std::defer_lock);
802 lock.lock();
803
804 if (redirectionEnabled != 0) {
805 lock.unlock();
806 return;
807 }
808 redirectionEnabled = 1;
809
810 lock.unlock();
811
812 int rc = pthread_create(&callbackThread, NULL, callbackThreadFunction, NULL);
813 if (rc != 0) {
814 std::cout << "Failed to create async callback block: %d" << rc << std::endl;
815 lock.unlock();
816 return;
817 }
818
819 av_log_set_callback(ffmpegkit_log_callback_function);
820 set_report_callback(ffmpegkit_statistics_callback_function);
821}
822
823 void ffmpegkit::FFmpegKitConfig::disableRedirection() {
824 std::unique_lock<std::recursive_mutex> lock(callbackDataMutex, std::defer_lock);
825
826 lock.lock();
827
828 if (redirectionEnabled != 1) {
829 lock.unlock();
830 return;
831 }
832 redirectionEnabled = 0;
833
834 lock.unlock();
835
836 callbackNotify();
837
838 pthread_detach(callbackThread);
839
840 av_log_set_callback(av_log_default_callback);
841 set_report_callback(NULL);
842}
843
844 int ffmpegkit::FFmpegKitConfig::setFontconfigConfigurationPath(const std::string& path) {
845 return ffmpegkit::FFmpegKitConfig::setEnvironmentVariable("FONTCONFIG_PATH", path);
846}
847
848 void ffmpegkit::FFmpegKitConfig::setFontDirectory(const std::string& fontDirectoryPath, const std::map<std::string,std::string>& fontNameMapping) {
849 ffmpegkit::FFmpegKitConfig::setFontDirectoryList(std::list<std::string>{fontDirectoryPath}, fontNameMapping);
850}
851
852 void ffmpegkit::FFmpegKitConfig::setFontDirectoryList(const std::list<std::string>& fontDirectoryList, const std::map<std::string,std::string>& fontNameMapping) {
853 int validFontNameMappingCount = 0;
854
855 const char *parentDirectory = std::getenv("HOME");
856 if (parentDirectory == NULL) {
857 parentDirectory = std::getenv("TMPDIR");
858 if (parentDirectory == NULL) {
859 parentDirectory = ".";
860 }
861 }
862
863 std::string cacheDir = std::string(parentDirectory) + "/.cache";
864 std::string ffmpegKitDir = cacheDir + "/ffmpegkit";
865 auto tempConfigurationDirectory = ffmpegKitDir + "/fontconfig";
866 auto fontConfigurationFile = std::string(tempConfigurationDirectory) + "/fonts.conf";
867
868 if (!fs_create_dir(cacheDir) || !fs_create_dir(ffmpegKitDir) || !fs_create_dir(tempConfigurationDirectory)) {
869 return;
870 }
871 std::cout << "Created temporary font conf directory: TRUE." << std::endl;
872
873 if (fs_exists(fontConfigurationFile, true, false)) {
874 bool fontConfigurationDeleted = std::remove(fontConfigurationFile.c_str());
875 std::cout << "Deleted old temporary font configuration: " << (fontConfigurationDeleted == 0?"TRUE":"FALSE") << "." << std::endl;
876 }
877
878 /* PROCESS MAPPINGS FIRST */
879 std::string fontNameMappingBlock = "";
880 for (auto const& pair : fontNameMapping) {
881 if ((pair.first.size() > 0) && (pair.second.size() > 0)) {
882
883 fontNameMappingBlock += " <match target=\"pattern\">\n";
884 fontNameMappingBlock += " <test qual=\"any\" name=\"family\">\n";
885 fontNameMappingBlock += " <string>";
886 fontNameMappingBlock += pair.first;
887 fontNameMappingBlock += "</string>\n";
888 fontNameMappingBlock += " </test>\n";
889 fontNameMappingBlock += " <edit name=\"family\" mode=\"assign\" binding=\"same\">\n";
890 fontNameMappingBlock += " <string>";
891 fontNameMappingBlock += pair.second;
892 fontNameMappingBlock += "</string>\n";
893 fontNameMappingBlock += " </edit>\n";
894 fontNameMappingBlock += " </match>\n";
895
896 validFontNameMappingCount++;
897 }
898 }
899
900 std::string fontConfiguration;
901 fontConfiguration += "<?xml version=\"1.0\"?>\n";
902 fontConfiguration += "<!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">\n";
903 fontConfiguration += "<fontconfig>\n";
904 fontConfiguration += " <dir prefix=\"cwd\">.</dir>\n";
905
906 for (const auto& fontDirectoryPath : fontDirectoryList) {
907 fontConfiguration += " <dir>";
908 fontConfiguration += fontDirectoryPath;
909 fontConfiguration += "</dir>\n";
910 }
911 fontConfiguration += fontNameMappingBlock;
912 fontConfiguration += "</fontconfig>\n";
913
914 std::ofstream fontConfigurationStream(fontConfigurationFile, std::ios::out | std::ios::trunc);
915 if (fontConfigurationStream) {
916 fontConfigurationStream << fontConfiguration;
917 }
918 if (fontConfigurationStream.bad()) {
919 std::cout << "Failed to set font directory. Error received while saving font configuration: " << fontConfigurationStream.rdbuf() << "." << std::endl;
920 }
921 fontConfigurationStream.close();
922
923 std::cout << "Saved new temporary font configuration with " << validFontNameMappingCount << " font name mappings." << std::endl;
924
925 ffmpegkit::FFmpegKitConfig::setFontconfigConfigurationPath(tempConfigurationDirectory.c_str());
926
927 for (const auto& fontDirectoryPath : fontDirectoryList) {
928 std::cout << "Font directory " << fontDirectoryPath << " registered successfully." << std::endl;
929 }
930}
931
932std::shared_ptr<std::string> ffmpegkit::FFmpegKitConfig::registerNewFFmpegPipe() {
933 const char *parentDirectory = std::getenv("HOME");
934 if (parentDirectory == NULL) {
935 parentDirectory = std::getenv("TMPDIR");
936 if (parentDirectory == NULL) {
937 parentDirectory = ".";
938 }
939 }
940
941 // PIPES ARE CREATED UNDER THE PIPES DIRECTORY
942 std::string cacheDir = std::string(parentDirectory) + "/.cache";
943 std::string ffmpegKitDir = cacheDir + "/ffmpegkit";
944 std::string pipesDir = ffmpegKitDir + "/pipes";
945
946 if (!fs_create_dir(cacheDir) || !fs_create_dir(ffmpegKitDir) || !fs_create_dir(pipesDir)) {
947 return nullptr;
948 }
949
950 std::shared_ptr<std::string> newFFmpegPipePath = std::make_shared<std::string>(pipesDir + "/" + FFmpegKitNamedPipePrefix + std::to_string(pipeIndexGenerator++));
951
952 // FIRST CLOSE OLD PIPES WITH THE SAME NAME
953 ffmpegkit::FFmpegKitConfig::closeFFmpegPipe(newFFmpegPipePath->c_str());
954
955 int rc = mkfifo(newFFmpegPipePath->c_str(), S_IRWXU | S_IRWXG | S_IROTH);
956 if (rc == 0) {
957 return newFFmpegPipePath;
958 } else {
959 std::cout << "Failed to register new FFmpeg pipe " << newFFmpegPipePath << ". Operation failed with rc=" << rc << "." << std::endl;
960 return nullptr;
961 }
962}
963
964 void ffmpegkit::FFmpegKitConfig::closeFFmpegPipe(const std::string& ffmpegPipePath) {
965 std::remove(ffmpegPipePath.c_str());
966}
967
968std::string ffmpegkit::FFmpegKitConfig::getFFmpegVersion() {
969 return FFMPEG_VERSION;
970}
971
972std::string ffmpegkit::FFmpegKitConfig::getVersion() {
973 if (FFmpegKitConfig::isLTSBuild()) {
974 return std::string("").append(FFmpegKitVersion).append("-lts");
975 } else {
976 return FFmpegKitVersion;
977 }
978}
979
980 bool ffmpegkit::FFmpegKitConfig::isLTSBuild() {
981 #if defined(FFMPEG_KIT_LTS)
982 return true;
983 #else
984 return false;
985 #endif
986}
987
988std::string ffmpegkit::FFmpegKitConfig::getBuildDate() {
989 char buildDate[10];
990 sprintf(buildDate, "%d", FFMPEG_KIT_BUILD_DATE);
991 return std::string(buildDate);
992}
993
994 int ffmpegkit::FFmpegKitConfig::setEnvironmentVariable(const std::string& variableName, const std::string& variableValue) {
995 return setenv(variableName.c_str(), variableValue.c_str(), true);
996}
997
998 void ffmpegkit::FFmpegKitConfig::ignoreSignal(const ffmpegkit::Signal signal) {
999 if (signal == ffmpegkit::SignalQuit) {
1000 handleSIGQUIT = 0;
1001 } else if (signal == ffmpegkit::SignalInt) {
1002 handleSIGINT = 0;
1003 } else if (signal == ffmpegkit::SignalTerm) {
1004 handleSIGTERM = 0;
1005 } else if (signal == ffmpegkit::SignalXcpu) {
1006 handleSIGXCPU = 0;
1007 } else if (signal == ffmpegkit::SignalPipe) {
1008 handleSIGPIPE = 0;
1009 }
1010}
1011
1012 void ffmpegkit::FFmpegKitConfig::ffmpegExecute(const std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegSession) {
1013 ffmpegSession->startRunning();
1014
1015 try {
1016 int returnCode = executeFFmpeg(ffmpegSession->getSessionId(), ffmpegSession->getArguments());
1017 ffmpegSession->complete(std::make_shared<ffmpegkit::ReturnCode>(returnCode));
1018 } catch(const std::exception& exception) {
1019 ffmpegSession->fail(exception.what());
1020 std::cout << "FFmpeg execute failed: " << ffmpegkit::FFmpegKitConfig::argumentsToString(ffmpegSession->getArguments()) << "." << exception.what() << std::endl;
1021 }
1022}
1023
1024 void ffmpegkit::FFmpegKitConfig::ffprobeExecute(const std::shared_ptr<ffmpegkit::FFprobeSession> ffprobeSession) {
1025 ffprobeSession->startRunning();
1026
1027 try {
1028 int returnCode = executeFFprobe(ffprobeSession->getSessionId(), ffprobeSession->getArguments());
1029 ffprobeSession->complete(std::make_shared<ffmpegkit::ReturnCode>(returnCode));
1030 } catch(const std::exception& exception) {
1031 ffprobeSession->fail(exception.what());
1032 std::cout << "FFprobe execute failed: " << ffmpegkit::FFmpegKitConfig::argumentsToString(ffprobeSession->getArguments()) << "." << exception.what() << std::endl;
1033 }
1034}
1035
1036 void ffmpegkit::FFmpegKitConfig::getMediaInformationExecute(const std::shared_ptr<ffmpegkit::MediaInformationSession> mediaInformationSession, const int waitTimeout) {
1037 mediaInformationSession->startRunning();
1038
1039 try {
1040 int returnCodeValue = executeFFprobe(mediaInformationSession->getSessionId(), mediaInformationSession->getArguments());
1041 auto returnCode = std::make_shared<ffmpegkit::ReturnCode>(returnCodeValue);
1042 mediaInformationSession->complete(returnCode);
1043 if (returnCode->isValueSuccess()) {
1044 auto allLogs = mediaInformationSession->getAllLogsWithTimeout(waitTimeout);
1045 std::string ffprobeJsonOutput;
1046 std::for_each(allLogs->cbegin(), allLogs->cend(), [&](std::shared_ptr<ffmpegkit::Log> log) {
1047 if (log->getLevel() == LevelAVLogStdErr) {
1048 ffprobeJsonOutput.append(log->getMessage());
1049 }
1050 });
1051 auto mediaInformation = ffmpegkit::MediaInformationJsonParser::fromWithError(ffprobeJsonOutput.c_str());
1052 mediaInformationSession->setMediaInformation(mediaInformation);
1053 }
1054 } catch(const std::exception& exception) {
1055 mediaInformationSession->fail(exception.what());
1056 std::cout << "Get media information execute failed: " << ffmpegkit::FFmpegKitConfig::argumentsToString(mediaInformationSession->getArguments()) << "." << exception.what() << std::endl;
1057 }
1058}
1059
1060 void ffmpegkit::FFmpegKitConfig::asyncFFmpegExecute(const std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegSession) {
1061 auto thread = std::thread([ffmpegSession]() {
1062 ffmpegkit::FFmpegKitConfig::ffmpegExecute(ffmpegSession);
1063
1064 ffmpegkit::FFmpegSessionCompleteCallback completeCallback = ffmpegSession->getCompleteCallback();
1065 if (completeCallback != nullptr) {
1066 try {
1067 // NOTIFY SESSION CALLBACK DEFINED
1068 completeCallback(ffmpegSession);
1069 } catch(const std::exception& exception) {
1070 std::cout << "Exception thrown inside session complete callback. " << exception.what() << std::endl;
1071 }
1072 }
1073
1074 ffmpegkit::FFmpegSessionCompleteCallback globalFFmpegSessionCompleteCallback = ffmpegkit::FFmpegKitConfig::getFFmpegSessionCompleteCallback();
1075 if (globalFFmpegSessionCompleteCallback != nullptr) {
1076 try {
1077 // NOTIFY SESSION CALLBACK DEFINED
1078 globalFFmpegSessionCompleteCallback(ffmpegSession);
1079 } catch(const std::exception& exception) {
1080 std::cout << "Exception thrown inside global complete callback. " << exception.what() << std::endl;
1081 }
1082 }
1083 });
1084
1085 thread.detach();
1086}
1087
1088 void ffmpegkit::FFmpegKitConfig::asyncFFprobeExecute(const std::shared_ptr<ffmpegkit::FFprobeSession> ffprobeSession) {
1089 auto thread = std::thread([ffprobeSession]() {
1090 ffmpegkit::FFmpegKitConfig::ffprobeExecute(ffprobeSession);
1091
1092 ffmpegkit::FFprobeSessionCompleteCallback completeCallback = ffprobeSession->getCompleteCallback();
1093 if (completeCallback != nullptr) {
1094 try {
1095 // NOTIFY SESSION CALLBACK DEFINED
1096 completeCallback(ffprobeSession);
1097 } catch(const std::exception& exception) {
1098 std::cout << "Exception thrown inside session complete callback. " << exception.what() << std::endl;
1099 }
1100 }
1101
1102 ffmpegkit::FFprobeSessionCompleteCallback globalFFprobeSessionCompleteCallback = ffmpegkit::FFmpegKitConfig::getFFprobeSessionCompleteCallback();
1103 if (globalFFprobeSessionCompleteCallback != nullptr) {
1104 try {
1105 // NOTIFY SESSION CALLBACK DEFINED
1106 globalFFprobeSessionCompleteCallback(ffprobeSession);
1107 } catch(const std::exception& exception) {
1108 std::cout << "Exception thrown inside global complete callback. " << exception.what() << std::endl;
1109 }
1110 }
1111 });
1112
1113 thread.detach();
1114}
1115
1116 void ffmpegkit::FFmpegKitConfig::asyncGetMediaInformationExecute(const std::shared_ptr<ffmpegkit::MediaInformationSession> mediaInformationSession, const int waitTimeout) {
1117 auto thread = std::thread([mediaInformationSession,waitTimeout]() {
1118 ffmpegkit::FFmpegKitConfig::getMediaInformationExecute(mediaInformationSession, waitTimeout);
1119
1120 ffmpegkit::MediaInformationSessionCompleteCallback completeCallback = mediaInformationSession->getCompleteCallback();
1121 if (completeCallback != nullptr) {
1122 try {
1123 // NOTIFY SESSION CALLBACK DEFINED
1124 completeCallback(mediaInformationSession);
1125 } catch(const std::exception& exception) {
1126 std::cout << "Exception thrown inside session complete callback. " << exception.what() << std::endl;
1127 }
1128 }
1129
1130 ffmpegkit::MediaInformationSessionCompleteCallback globalMediaInformationSessionCompleteCallback = ffmpegkit::FFmpegKitConfig::getMediaInformationSessionCompleteCallback();
1131 if (globalMediaInformationSessionCompleteCallback != nullptr) {
1132 try {
1133 // NOTIFY SESSION CALLBACK DEFINED
1134 globalMediaInformationSessionCompleteCallback(mediaInformationSession);
1135 } catch(const std::exception& exception) {
1136 std::cout << "Exception thrown inside global complete callback. " << exception.what() << std::endl;
1137 }
1138 }
1139 });
1140
1141 thread.detach();
1142}
1143
1144 void ffmpegkit::FFmpegKitConfig::enableLogCallback(const ffmpegkit::LogCallback callback) {
1145 logCallback = callback;
1146}
1147
1148 void ffmpegkit::FFmpegKitConfig::enableStatisticsCallback(const ffmpegkit::StatisticsCallback callback) {
1149 statisticsCallback = callback;
1150}
1151
1152 void ffmpegkit::FFmpegKitConfig::enableFFmpegSessionCompleteCallback(const FFmpegSessionCompleteCallback completeCallback) {
1153 ffmpegSessionCompleteCallback = completeCallback;
1154}
1155
1156 ffmpegkit::FFmpegSessionCompleteCallback ffmpegkit::FFmpegKitConfig::getFFmpegSessionCompleteCallback() {
1157 return ffmpegSessionCompleteCallback;
1158}
1159
1160 void ffmpegkit::FFmpegKitConfig::enableFFprobeSessionCompleteCallback(const FFprobeSessionCompleteCallback completeCallback) {
1161 ffprobeSessionCompleteCallback = completeCallback;
1162}
1163
1164 ffmpegkit::FFprobeSessionCompleteCallback ffmpegkit::FFmpegKitConfig::getFFprobeSessionCompleteCallback() {
1165 return ffprobeSessionCompleteCallback;
1166}
1167
1168 void ffmpegkit::FFmpegKitConfig::enableMediaInformationSessionCompleteCallback(const MediaInformationSessionCompleteCallback completeCallback) {
1169 mediaInformationSessionCompleteCallback = completeCallback;
1170}
1171
1172 ffmpegkit::MediaInformationSessionCompleteCallback ffmpegkit::FFmpegKitConfig::getMediaInformationSessionCompleteCallback() {
1173 return mediaInformationSessionCompleteCallback;
1174}
1175
1176 ffmpegkit::Level ffmpegkit::FFmpegKitConfig::getLogLevel() {
1177 return static_cast<ffmpegkit::Level>(configuredLogLevel);
1178}
1179
1180 void ffmpegkit::FFmpegKitConfig::setLogLevel(const ffmpegkit::Level level) {
1181 configuredLogLevel = level;
1182}
1183
1184std::string ffmpegkit::FFmpegKitConfig::logLevelToString(const ffmpegkit::Level level) {
1185 switch (level) {
1186 case ffmpegkit::LevelAVLogStdErr: return "STDERR";
1187 case ffmpegkit::LevelAVLogTrace: return "TRACE";
1188 case ffmpegkit::LevelAVLogDebug: return "DEBUG";
1189 case ffmpegkit::LevelAVLogVerbose: return "VERBOSE";
1190 case ffmpegkit::LevelAVLogInfo: return "INFO";
1191 case ffmpegkit::LevelAVLogWarning: return "WARNING";
1192 case ffmpegkit::LevelAVLogError: return "ERROR";
1193 case ffmpegkit::LevelAVLogFatal: return "FATAL";
1194 case ffmpegkit::LevelAVLogPanic: return "PANIC";
1195 case ffmpegkit::LevelAVLogQuiet: return "QUIET";
1196 default: return "";
1197 }
1198}
1199
1200 int ffmpegkit::FFmpegKitConfig::getSessionHistorySize() {
1201 return sessionHistorySize;
1202}
1203
1204 void ffmpegkit::FFmpegKitConfig::setSessionHistorySize(const int newSessionHistorySize) {
1205 if (newSessionHistorySize >= SESSION_MAP_SIZE) {
1206
1207 /*
1208 * THERE IS A HARD LIMIT ON THE NATIVE SIDE. HISTORY SIZE MUST BE SMALLER THAN SESSION_MAP_SIZE
1209 */
1210 throw std::runtime_error("Session history size must not exceed the hard limit!");
1211 } else if (newSessionHistorySize > 0) {
1212 sessionHistorySize = newSessionHistorySize;
1213 deleteExpiredSessions();
1214 }
1215}
1216
1217std::shared_ptr<ffmpegkit::Session> ffmpegkit::FFmpegKitConfig::getSession(const long sessionId) {
1218 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1219 lock.lock();
1220
1221 auto session = sessionHistoryMap.find(sessionId);
1222 if (session != sessionHistoryMap.end()) {
1223 return session->second;
1224 } else {
1225 return nullptr;
1226 }
1227}
1228
1229std::shared_ptr<ffmpegkit::Session> ffmpegkit::FFmpegKitConfig::getLastSession() {
1230 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1231 lock.lock();
1232
1233 return sessionHistoryList.front();
1234}
1235
1236std::shared_ptr<ffmpegkit::Session> ffmpegkit::FFmpegKitConfig::getLastCompletedSession() {
1237 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1238
1239 lock.lock();
1240
1241 for(auto rit=sessionHistoryList.rbegin(); rit != sessionHistoryList.rend(); ++rit) {
1242 auto session = *rit;
1243 if (session->getState() == SessionStateCompleted) {
1244 return session;
1245 }
1246 }
1247
1248 return nullptr;
1249}
1250
1251std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::Session>>> ffmpegkit::FFmpegKitConfig::getSessions() {
1252 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1253 lock.lock();
1254
1255 auto sessionHistoryListCopy = std::make_shared<std::list<std::shared_ptr<ffmpegkit::Session>>>(sessionHistoryList);
1256
1257 lock.unlock();
1258
1259 return sessionHistoryListCopy;
1260}
1261
1262 void ffmpegkit::FFmpegKitConfig::clearSessions() {
1263 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1264 lock.lock();
1265
1266 sessionHistoryList.clear();
1267 sessionHistoryMap.clear();
1268
1269 lock.unlock();
1270}
1271
1272std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::FFmpegSession>>> ffmpegkit::FFmpegKitConfig::getFFmpegSessions() {
1273 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1274 const auto ffmpegSessions = std::make_shared<std::list<std::shared_ptr<ffmpegkit::FFmpegSession>>>();
1275
1276 lock.lock();
1277
1278 for(auto it=sessionHistoryList.begin(); it != sessionHistoryList.end(); ++it) {
1279 auto session = *it;
1280 if (session->isFFmpeg()) {
1281 ffmpegSessions->push_back(std::static_pointer_cast<ffmpegkit::FFmpegSession>(session));
1282 }
1283 }
1284
1285 lock.unlock();
1286
1287 return ffmpegSessions;
1288}
1289
1290std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::FFprobeSession>>> ffmpegkit::FFmpegKitConfig::getFFprobeSessions() {
1291 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1292 const auto ffprobeSessions = std::make_shared<std::list<std::shared_ptr<ffmpegkit::FFprobeSession>>>();
1293
1294 lock.lock();
1295
1296 for(auto it=sessionHistoryList.begin(); it != sessionHistoryList.end(); ++it) {
1297 auto session = *it;
1298 if (session->isFFprobe()) {
1299 ffprobeSessions->push_back(std::static_pointer_cast<ffmpegkit::FFprobeSession>(session));
1300 }
1301 }
1302
1303 lock.unlock();
1304
1305 return ffprobeSessions;
1306}
1307
1308std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::MediaInformationSession>>> ffmpegkit::FFmpegKitConfig::getMediaInformationSessions() {
1309 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1310 const auto mediaInformationSessions = std::make_shared<std::list<std::shared_ptr<ffmpegkit::MediaInformationSession>>>();
1311
1312 lock.lock();
1313
1314 for(auto it=sessionHistoryList.begin(); it != sessionHistoryList.end(); ++it) {
1315 auto session = *it;
1316 if (session->isMediaInformation()) {
1317 mediaInformationSessions->push_back(std::static_pointer_cast<ffmpegkit::MediaInformationSession>(session));
1318 }
1319 }
1320
1321 lock.unlock();
1322
1323 return mediaInformationSessions;
1324}
1325
1326std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::Session>>> ffmpegkit::FFmpegKitConfig::getSessionsByState(const SessionState state) {
1327 std::unique_lock<std::recursive_mutex> lock(sessionMutex, std::defer_lock);
1328 auto sessions = std::make_shared<std::list<std::shared_ptr<ffmpegkit::Session>>>();
1329
1330 lock.lock();
1331
1332 for(auto it=sessionHistoryList.begin(); it != sessionHistoryList.end(); ++it) {
1333 auto session = *it;
1334 if (session->getState() == state) {
1335 sessions->push_back(session);
1336 }
1337 }
1338
1339 lock.unlock();
1340
1341 return sessions;
1342}
1343
1344 ffmpegkit::LogRedirectionStrategy ffmpegkit::FFmpegKitConfig::getLogRedirectionStrategy() {
1345 return globalLogRedirectionStrategy;
1346}
1347
1348 void ffmpegkit::FFmpegKitConfig::setLogRedirectionStrategy(const LogRedirectionStrategy logRedirectionStrategy) {
1349 globalLogRedirectionStrategy = logRedirectionStrategy;
1350}
1351
1352 int ffmpegkit::FFmpegKitConfig::messagesInTransmit(const long sessionId) {
1353 return std::atomic_load(&sessionInTransitMessageCountMap[sessionId % SESSION_MAP_SIZE]);
1354}
1355
1356std::string ffmpegkit::FFmpegKitConfig::sessionStateToString(SessionState state) {
1357 switch (state) {
1358 case SessionStateCreated: return "CREATED";
1359 case SessionStateRunning: return "RUNNING";
1360 case SessionStateFailed: return "FAILED";
1361 case SessionStateCompleted: return "COMPLETED";
1362 default: return "";
1363 }
1364}
1365
1366std::list<std::string> ffmpegkit::FFmpegKitConfig::parseArguments(const std::string& command) {
1367 std::list<std::string> argumentList;
1368 std::string currentArgument;
1369
1370 bool singleQuoteStarted = false;
1371 bool doubleQuoteStarted = false;
1372
1373 for (int i = 0; i < command.size(); i++) {
1374 char previousChar;
1375 if (i > 0) {
1376 previousChar = command[i - 1];
1377 } else {
1378 previousChar = 0;
1379 }
1380 char currentChar = command[i];
1381
1382 if (currentChar == ' ') {
1383 if (singleQuoteStarted || doubleQuoteStarted) {
1384 currentArgument += currentChar;
1385 } else if (currentArgument.size() > 0) {
1386 argumentList.push_back(currentArgument);
1387 currentArgument = "";
1388 }
1389 } else if (currentChar == '\'' && (previousChar == 0 || previousChar != '\\')) {
1390 if (singleQuoteStarted) {
1391 singleQuoteStarted = false;
1392 } else if (doubleQuoteStarted) {
1393 currentArgument += currentChar;
1394 } else {
1395 singleQuoteStarted = true;
1396 }
1397 } else if (currentChar == '\"' && (previousChar == 0 || previousChar != '\\')) {
1398 if (doubleQuoteStarted) {
1399 doubleQuoteStarted = false;
1400 } else if (singleQuoteStarted) {
1401 currentArgument += currentChar;
1402 } else {
1403 doubleQuoteStarted = true;
1404 }
1405 } else {
1406 currentArgument += currentChar;
1407 }
1408 }
1409
1410 if (currentArgument.size() > 0) {
1411 argumentList.push_back(currentArgument);
1412 }
1413
1414 return argumentList;
1415}
1416
1417std::string ffmpegkit::FFmpegKitConfig::argumentsToString(std::shared_ptr<std::list<std::string>> arguments) {
1418 if (arguments == nullptr) {
1419 return "null";
1420 }
1421
1422 std::string string;
1423 for(auto it=arguments->begin(); it != arguments->end(); ++it) {
1424 auto argument = *it;
1425 if (it != arguments->begin()) {
1426 string += " ";
1427 }
1428 string += argument;
1429 }
1430
1431 return string;
1432}
ArchDetect.h
FFmpegKit.h
callbackMutex
static std::mutex callbackMutex
Definition FFmpegKitConfig.cpp:84
ffmpegkit_log_callback_function
void ffmpegkit_log_callback_function(void *ptr, int level, const char *format, va_list vargs)
Definition FFmpegKitConfig.cpp:475
process_log
static void process_log(long sessionId, int levelValueInt, AVBPrint *logMessage)
Definition FFmpegKitConfig.cpp:528
callbackThreadFunction
void * callbackThreadFunction(void *pointer)
Definition FFmpegKitConfig.cpp:643
executeFFprobe
int executeFFprobe(const long sessionId, const std::shared_ptr< std::list< std::string > > arguments)
Definition FFmpegKitConfig.cpp:731
pipeIndexGenerator
static std::atomic< long > pipeIndexGenerator(1)
statisticsCallbackDataAdd
static void statisticsCallbackDataAdd(int frameNumber, float fps, float quality, int64_t size, int time, double bitrate, double speed)
Definition FFmpegKitConfig.cpp:379
cancelSession
void cancelSession(long sessionId)
Definition FFmpegKitConfig.cpp:436
SESSION_MAP_SIZE
#define SESSION_MAP_SIZE
Definition FFmpegKitConfig.cpp:64
sessionHistorySize
static int sessionHistorySize
Definition FFmpegKitConfig.cpp:58
fs_exists
static bool fs_exists(const std::string &s, const bool isFile, const bool isDirectory)
Definition FFmpegKitConfig.cpp:130
callbackDataList
static std::list< CallbackData * > callbackDataList
Definition FFmpegKitConfig.cpp:87
CallbackType
CallbackType
Definition FFmpegKitConfig.cpp:125
StatisticsType
@ StatisticsType
Definition FFmpegKitConfig.cpp:127
LogType
@ LogType
Definition FFmpegKitConfig.cpp:126
callbackDataMutex
static std::recursive_mutex callbackDataMutex
Definition FFmpegKitConfig.cpp:83
logCallbackDataAdd
static void logCallbackDataAdd(int level, AVBPrint *data)
Definition FFmpegKitConfig.cpp:363
avutil_log_sanitize
static void avutil_log_sanitize(char *line)
Definition FFmpegKitConfig.cpp:349
handleSIGINT
volatile int handleSIGINT
Definition FFmpegKitConfig.cpp:91
registerSessionId
static void registerSessionId(long sessionId)
Definition FFmpegKitConfig.cpp:414
ffprobe_execute
int ffprobe_execute(int argc, char **argv)
Definition fftools_ffprobe.c:4096
handleSIGTERM
volatile int handleSIGTERM
Definition FFmpegKitConfig.cpp:92
set_report_callback
void set_report_callback(void(*callback)(int, float, float, int64_t, double, double, double))
Definition fftools_ffmpeg.c:4362
ffmpegSessionCompleteCallback
static ffmpegkit::FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback
Definition FFmpegKitConfig.cpp:75
ffmpegkit_statistics_callback_function
void ffmpegkit_statistics_callback_function(int frameNumber, float fps, float quality, int64_t size, double time, double bitrate, double speed)
Definition FFmpegKitConfig.cpp:524
sessionInTransitMessageCountMap
static std::atomic< int > sessionInTransitMessageCountMap[SESSION_MAP_SIZE]
Definition FFmpegKitConfig.cpp:66
avutil_log_get_level_str
static const char * avutil_log_get_level_str(int level)
Definition FFmpegKitConfig.cpp:292
avutil_log_format_line
static void avutil_log_format_line(void *avcl, int level, const char *fmt, va_list vl, AVBPrint part[4], int *print_prefix)
Definition FFmpegKitConfig.cpp:317
sessionMutex
static std::recursive_mutex sessionMutex
Definition FFmpegKitConfig.cpp:61
sessionMap
static std::atomic< short > sessionMap[SESSION_MAP_SIZE]
Definition FFmpegKitConfig.cpp:65
addSessionToSessionHistory
void addSessionToSessionHistory(const std::shared_ptr< ffmpegkit::Session > session)
Definition FFmpegKitConfig.cpp:165
resetMessagesInTransmit
static void resetMessagesInTransmit(long sessionId)
Definition FFmpegKitConfig.cpp:463
logCallback
static ffmpegkit::LogCallback logCallback
Definition FFmpegKitConfig.cpp:69
cancel_operation
void cancel_operation(long id)
Definition fftools_ffmpeg.c:4367
callbackNotify
static void callbackNotify()
Definition FFmpegKitConfig.cpp:288
callbackThread
static pthread_t callbackThread
Definition FFmpegKitConfig.cpp:119
callbackMonitor
static std::condition_variable callbackMonitor
Definition FFmpegKitConfig.cpp:85
sessionHistoryList
static std::list< std::shared_ptr< ffmpegkit::Session > > sessionHistoryList
Definition FFmpegKitConfig.cpp:60
sessionHistoryMap
static std::map< long, std::shared_ptr< ffmpegkit::Session > > sessionHistoryMap
Definition FFmpegKitConfig.cpp:59
statisticsCallback
static ffmpegkit::StatisticsCallback statisticsCallback
Definition FFmpegKitConfig.cpp:72
globalLogRedirectionStrategy
static ffmpegkit::LogRedirectionStrategy globalLogRedirectionStrategy
Definition FFmpegKitConfig.cpp:79
ffmpegKitInitializerFlag
static std::once_flag ffmpegKitInitializerFlag
Definition FFmpegKitConfig.cpp:118
ffmpegKitInitialize
void * ffmpegKitInitialize()
Definition FFmpegKitConfig.cpp:771
executeFFmpeg
static int executeFFmpeg(const long sessionId, const std::shared_ptr< std::list< std::string > > arguments)
Definition FFmpegKitConfig.cpp:691
deleteExpiredSessions
void deleteExpiredSessions()
Definition FFmpegKitConfig.cpp:155
globalSessionId
__thread long globalSessionId
Definition FFmpegKitConfig.cpp:97
redirectionEnabled
static int redirectionEnabled
Definition FFmpegKitConfig.cpp:82
callbackWait
static void callbackWait(int milliSeconds)
Definition FFmpegKitConfig.cpp:280
cancelRequested
int cancelRequested(long sessionId)
Definition FFmpegKitConfig.cpp:446
handleSIGPIPE
volatile int handleSIGPIPE
Definition FFmpegKitConfig.cpp:94
callbackDataRemove
static CallbackData * callbackDataRemove()
Definition FFmpegKitConfig.cpp:395
process_statistics
void process_statistics(long sessionId, int videoFrameNumber, float videoFps, float videoQuality, long size, double time, double bitrate, double speed)
Definition FFmpegKitConfig.cpp:612
handleSIGXCPU
volatile int handleSIGXCPU
Definition FFmpegKitConfig.cpp:93
ffprobeSessionCompleteCallback
static ffmpegkit::FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback
Definition FFmpegKitConfig.cpp:76
removeSession
static void removeSession(long sessionId)
Definition FFmpegKitConfig.cpp:423
fs_create_dir
static bool fs_create_dir(const std::string &s)
Definition FFmpegKitConfig.cpp:145
configuredLogLevel
int configuredLogLevel
Definition FFmpegKitConfig.cpp:100
mediaInformationSessionCompleteCallback
static ffmpegkit::MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback
Definition FFmpegKitConfig.cpp:77
ffmpeg_execute
int ffmpeg_execute(int argc, char **argv)
Definition fftools_ffmpeg.c:4378
_ffmpegKitConfigInitializer
const void * _ffmpegKitConfigInitializer
Definition FFmpegKitConfig.cpp:123
handleSIGQUIT
volatile int handleSIGQUIT
Definition FFmpegKitConfig.cpp:90
FFmpegKitConfig.h
FFmpegSession.h
FFprobeKit.h
FFprobeSession.h
Level.h
LogRedirectionStrategy.h
MediaInformationSession.h
Packages.h
SessionState.h
CallbackData
Definition FFmpegKitConfig.cpp:188
CallbackData::_statisticsSize
int64_t _statisticsSize
Definition FFmpegKitConfig.cpp:269
CallbackData::_statisticsTime
double _statisticsTime
Definition FFmpegKitConfig.cpp:270
CallbackData::getStatisticsQuality
float getStatisticsQuality()
Definition FFmpegKitConfig.cpp:239
CallbackData::getLogData
AVBPrint * getLogData()
Definition FFmpegKitConfig.cpp:227
CallbackData::_statisticsBitrate
double _statisticsBitrate
Definition FFmpegKitConfig.cpp:271
CallbackData::_statisticsSpeed
double _statisticsSpeed
Definition FFmpegKitConfig.cpp:272
CallbackData::getStatisticsSpeed
double getStatisticsSpeed()
Definition FFmpegKitConfig.cpp:255
CallbackData::_logLevel
int _logLevel
Definition FFmpegKitConfig.cpp:263
CallbackData::_statisticsFps
float _statisticsFps
Definition FFmpegKitConfig.cpp:267
CallbackData::_logData
AVBPrint _logData
Definition FFmpegKitConfig.cpp:264
CallbackData::getStatisticsFrameNumber
int getStatisticsFrameNumber()
Definition FFmpegKitConfig.cpp:231
CallbackData::CallbackData
CallbackData(const long sessionId, const int videoFrameNumber, const float videoFps, const float videoQuality, const int64_t size, const double time, const double bitrate, const double speed)
Definition FFmpegKitConfig.cpp:196
CallbackData::_statisticsQuality
float _statisticsQuality
Definition FFmpegKitConfig.cpp:268
CallbackData::_sessionId
long _sessionId
Definition FFmpegKitConfig.cpp:261
CallbackData::getStatisticsSize
int64_t getStatisticsSize()
Definition FFmpegKitConfig.cpp:243
CallbackData::CallbackData
CallbackData(const long sessionId, const int logLevel, const AVBPrint *data)
Definition FFmpegKitConfig.cpp:190
CallbackData::_statisticsFrameNumber
int _statisticsFrameNumber
Definition FFmpegKitConfig.cpp:266
CallbackData::getStatisticsBitrate
double getStatisticsBitrate()
Definition FFmpegKitConfig.cpp:251
CallbackData::getLogLevel
int getLogLevel()
Definition FFmpegKitConfig.cpp:223
CallbackData::getType
CallbackType getType()
Definition FFmpegKitConfig.cpp:215
CallbackData::_type
CallbackType _type
Definition FFmpegKitConfig.cpp:260
CallbackData::getStatisticsTime
double getStatisticsTime()
Definition FFmpegKitConfig.cpp:247
CallbackData::getStatisticsFps
float getStatisticsFps()
Definition FFmpegKitConfig.cpp:235
CallbackData::getSessionId
long getSessionId()
Definition FFmpegKitConfig.cpp:219
ffmpegkit::ArchDetect::getArch
static std::string getArch()
Definition ArchDetect.cpp:26
ffmpegkit::FFmpegKitConfig::getVersion
static std::string getVersion()
Definition FFmpegKitConfig.cpp:972
ffmpegkit::FFmpegKitConfig::disableRedirection
static void disableRedirection()
Definition FFmpegKitConfig.cpp:823
ffmpegkit::FFmpegKitConfig::getMediaInformationSessions
static std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::MediaInformationSession > > > getMediaInformationSessions()
Definition FFmpegKitConfig.cpp:1308
ffmpegkit::FFmpegKitConfig::enableFFmpegSessionCompleteCallback
static void enableFFmpegSessionCompleteCallback(const FFmpegSessionCompleteCallback ffmpegSessionCompleteCallback)
Definition FFmpegKitConfig.cpp:1152
ffmpegkit::FFmpegKitConfig::getSessionHistorySize
static int getSessionHistorySize()
Definition FFmpegKitConfig.cpp:1200
ffmpegkit::FFmpegKitConfig::getLastSession
static std::shared_ptr< ffmpegkit::Session > getLastSession()
Definition FFmpegKitConfig.cpp:1229
ffmpegkit::FFmpegKitConfig::enableRedirection
static void enableRedirection()
Definition FFmpegKitConfig.cpp:800
ffmpegkit::FFmpegKitConfig::enableLogCallback
static void enableLogCallback(const ffmpegkit::LogCallback logCallback)
Definition FFmpegKitConfig.cpp:1144
ffmpegkit::FFmpegKitConfig::registerNewFFmpegPipe
static std::shared_ptr< std::string > registerNewFFmpegPipe()
Definition FFmpegKitConfig.cpp:932
ffmpegkit::FFmpegKitConfig::getLogRedirectionStrategy
static LogRedirectionStrategy getLogRedirectionStrategy()
Definition FFmpegKitConfig.cpp:1344
ffmpegkit::FFmpegKitConfig::getFFprobeSessions
static std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::FFprobeSession > > > getFFprobeSessions()
Definition FFmpegKitConfig.cpp:1290
ffmpegkit::FFmpegKitConfig::messagesInTransmit
static int messagesInTransmit(const long sessionId)
Definition FFmpegKitConfig.cpp:1352
ffmpegkit::FFmpegKitConfig::closeFFmpegPipe
static void closeFFmpegPipe(const std::string &ffmpegPipePath)
Definition FFmpegKitConfig.cpp:964
ffmpegkit::FFmpegKitConfig::asyncFFprobeExecute
static void asyncFFprobeExecute(const std::shared_ptr< ffmpegkit::FFprobeSession > ffprobeSession)
Definition FFmpegKitConfig.cpp:1088
ffmpegkit::FFmpegKitConfig::getLogLevel
static ffmpegkit::Level getLogLevel()
Definition FFmpegKitConfig.cpp:1176
ffmpegkit::FFmpegKitConfig::getSession
static std::shared_ptr< ffmpegkit::Session > getSession(const long sessionId)
Definition FFmpegKitConfig.cpp:1217
ffmpegkit::FFmpegKitConfig::asyncGetMediaInformationExecute
static void asyncGetMediaInformationExecute(const std::shared_ptr< ffmpegkit::MediaInformationSession > mediaInformationSession, int waitTimeout)
Definition FFmpegKitConfig.cpp:1116
ffmpegkit::FFmpegKitConfig::setLogRedirectionStrategy
static void setLogRedirectionStrategy(const LogRedirectionStrategy logRedirectionStrategy)
Definition FFmpegKitConfig.cpp:1348
ffmpegkit::FFmpegKitConfig::getMediaInformationExecute
static void getMediaInformationExecute(const std::shared_ptr< ffmpegkit::MediaInformationSession > mediaInformationSession, const int waitTimeout)
Definition FFmpegKitConfig.cpp:1036
ffmpegkit::FFmpegKitConfig::setEnvironmentVariable
static int setEnvironmentVariable(const std::string &variableName, const std::string &variableValue)
Definition FFmpegKitConfig.cpp:994
ffmpegkit::FFmpegKitConfig::getSessionsByState
static std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::Session > > > getSessionsByState(const SessionState state)
Definition FFmpegKitConfig.cpp:1326
ffmpegkit::FFmpegKitConfig::enableStatisticsCallback
static void enableStatisticsCallback(const ffmpegkit::StatisticsCallback statisticsCallback)
Definition FFmpegKitConfig.cpp:1148
ffmpegkit::FFmpegKitConfig::parseArguments
static std::list< std::string > parseArguments(const std::string &command)
Definition FFmpegKitConfig.cpp:1366
ffmpegkit::FFmpegKitConfig::ffprobeExecute
static void ffprobeExecute(const std::shared_ptr< ffmpegkit::FFprobeSession > ffprobeSession)
Definition FFmpegKitConfig.cpp:1024
ffmpegkit::FFmpegKitConfig::setSessionHistorySize
static void setSessionHistorySize(const int sessionHistorySize)
Definition FFmpegKitConfig.cpp:1204
ffmpegkit::FFmpegKitConfig::setLogLevel
static void setLogLevel(const ffmpegkit::Level level)
Definition FFmpegKitConfig.cpp:1180
ffmpegkit::FFmpegKitConfig::setFontDirectory
static void setFontDirectory(const std::string &fontDirectoryPath, const std::map< std::string, std::string > &fontNameMapping)
Definition FFmpegKitConfig.cpp:848
ffmpegkit::FFmpegKitConfig::asyncFFmpegExecute
static void asyncFFmpegExecute(const std::shared_ptr< ffmpegkit::FFmpegSession > ffmpegSession)
Definition FFmpegKitConfig.cpp:1060
ffmpegkit::FFmpegKitConfig::getFFmpegSessionCompleteCallback
static FFmpegSessionCompleteCallback getFFmpegSessionCompleteCallback()
Definition FFmpegKitConfig.cpp:1156
ffmpegkit::FFmpegKitConfig::ignoreSignal
static void ignoreSignal(const ffmpegkit::Signal signal)
Definition FFmpegKitConfig.cpp:998
ffmpegkit::FFmpegKitConfig::getFFprobeSessionCompleteCallback
static FFprobeSessionCompleteCallback getFFprobeSessionCompleteCallback()
Definition FFmpegKitConfig.cpp:1164
ffmpegkit::FFmpegKitConfig::getLastCompletedSession
static std::shared_ptr< ffmpegkit::Session > getLastCompletedSession()
Definition FFmpegKitConfig.cpp:1236
ffmpegkit::FFmpegKitConfig::clearSessions
static void clearSessions()
Definition FFmpegKitConfig.cpp:1262
ffmpegkit::FFmpegKitConfig::isLTSBuild
static bool isLTSBuild()
Definition FFmpegKitConfig.cpp:980
ffmpegkit::FFmpegKitConfig::sessionStateToString
static std::string sessionStateToString(SessionState state)
Definition FFmpegKitConfig.cpp:1356
ffmpegkit::FFmpegKitConfig::getFFmpegSessions
static std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::FFmpegSession > > > getFFmpegSessions()
Definition FFmpegKitConfig.cpp:1272
ffmpegkit::FFmpegKitConfig::setFontconfigConfigurationPath
static int setFontconfigConfigurationPath(const std::string &path)
Definition FFmpegKitConfig.cpp:844
ffmpegkit::FFmpegKitConfig::argumentsToString
static std::string argumentsToString(std::shared_ptr< std::list< std::string > > arguments)
Definition FFmpegKitConfig.cpp:1417
ffmpegkit::FFmpegKitConfig::logLevelToString
static std::string logLevelToString(const ffmpegkit::Level level)
Definition FFmpegKitConfig.cpp:1184
ffmpegkit::FFmpegKitConfig::setFontDirectoryList
static void setFontDirectoryList(const std::list< std::string > &fontDirectoryList, const std::map< std::string, std::string > &fontNameMapping)
Definition FFmpegKitConfig.cpp:852
ffmpegkit::FFmpegKitConfig::enableMediaInformationSessionCompleteCallback
static void enableMediaInformationSessionCompleteCallback(const MediaInformationSessionCompleteCallback mediaInformationSessionCompleteCallback)
Definition FFmpegKitConfig.cpp:1168
ffmpegkit::FFmpegKitConfig::enableFFprobeSessionCompleteCallback
static void enableFFprobeSessionCompleteCallback(const FFprobeSessionCompleteCallback ffprobeSessionCompleteCallback)
Definition FFmpegKitConfig.cpp:1160
ffmpegkit::FFmpegKitConfig::getFFmpegVersion
static std::string getFFmpegVersion()
Definition FFmpegKitConfig.cpp:968
ffmpegkit::FFmpegKitConfig::getSessions
static std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::Session > > > getSessions()
Definition FFmpegKitConfig.cpp:1251
ffmpegkit::FFmpegKitConfig::getBuildDate
static std::string getBuildDate()
Definition FFmpegKitConfig.cpp:988
ffmpegkit::FFmpegKitConfig::ffmpegExecute
static void ffmpegExecute(const std::shared_ptr< ffmpegkit::FFmpegSession > ffmpegSession)
Definition FFmpegKitConfig.cpp:1012
ffmpegkit::FFmpegKitConfig::getMediaInformationSessionCompleteCallback
static MediaInformationSessionCompleteCallback getMediaInformationSessionCompleteCallback()
Definition FFmpegKitConfig.cpp:1172
ffmpegkit::MediaInformationJsonParser::fromWithError
static std::shared_ptr< ffmpegkit::MediaInformation > fromWithError(const std::string &ffprobeJsonOutput)
Definition MediaInformationJsonParser.cpp:40
ffmpegkit::Packages::getPackageName
static std::string getPackageName()
Definition Packages.cpp:25
fftools_cmdutils.h
AV_LOG_STDERR
#define AV_LOG_STDERR
Definition fftools_cmdutils.h:82
ffmpegkit::LogRedirectionStrategy
LogRedirectionStrategy
Definition LogRedirectionStrategy.h:25
ffmpegkit::LogRedirectionStrategyPrintLogsWhenSessionCallbackNotDefined
@ LogRedirectionStrategyPrintLogsWhenSessionCallbackNotDefined
Definition LogRedirectionStrategy.h:29
ffmpegkit::LogRedirectionStrategyAlwaysPrintLogs
@ LogRedirectionStrategyAlwaysPrintLogs
Definition LogRedirectionStrategy.h:26
ffmpegkit::LogRedirectionStrategyNeverPrintLogs
@ LogRedirectionStrategyNeverPrintLogs
Definition LogRedirectionStrategy.h:30
ffmpegkit::LogRedirectionStrategyPrintLogsWhenNoCallbacksDefined
@ LogRedirectionStrategyPrintLogsWhenNoCallbacksDefined
Definition LogRedirectionStrategy.h:27
ffmpegkit::LogRedirectionStrategyPrintLogsWhenGlobalCallbackNotDefined
@ LogRedirectionStrategyPrintLogsWhenGlobalCallbackNotDefined
Definition LogRedirectionStrategy.h:28
ffmpegkit::StatisticsCallback
std::function< void(const std::shared_ptr< ffmpegkit::Statistics > statistics)> StatisticsCallback
Definition StatisticsCallback.h:35
ffmpegkit::Level
Level
Definition Level.h:28
ffmpegkit::LevelAVLogError
@ LevelAVLogError
Definition Level.h:57
ffmpegkit::LevelAVLogDebug
@ LevelAVLogDebug
Definition Level.h:78
ffmpegkit::LevelAVLogStdErr
@ LevelAVLogStdErr
Definition Level.h:34
ffmpegkit::LevelAVLogQuiet
@ LevelAVLogQuiet
Definition Level.h:39
ffmpegkit::LevelAVLogPanic
@ LevelAVLogPanic
Definition Level.h:44
ffmpegkit::LevelAVLogWarning
@ LevelAVLogWarning
Definition Level.h:63
ffmpegkit::LevelAVLogVerbose
@ LevelAVLogVerbose
Definition Level.h:73
ffmpegkit::LevelAVLogTrace
@ LevelAVLogTrace
Definition Level.h:83
ffmpegkit::LevelAVLogInfo
@ LevelAVLogInfo
Definition Level.h:68
ffmpegkit::LevelAVLogFatal
@ LevelAVLogFatal
Definition Level.h:51
ffmpegkit::SessionState
SessionState
Definition SessionState.h:25
ffmpegkit::SessionStateRunning
@ SessionStateRunning
Definition SessionState.h:27
ffmpegkit::SessionStateFailed
@ SessionStateFailed
Definition SessionState.h:28
ffmpegkit::SessionStateCreated
@ SessionStateCreated
Definition SessionState.h:26
ffmpegkit::SessionStateCompleted
@ SessionStateCompleted
Definition SessionState.h:29
ffmpegkit::MediaInformationSessionCompleteCallback
std::function< void(const std::shared_ptr< ffmpegkit::MediaInformationSession > session)> MediaInformationSessionCompleteCallback
Definition MediaInformationSessionCompleteCallback.h:53
ffmpegkit::LogCallback
std::function< void(const std::shared_ptr< ffmpegkit::Log > log)> LogCallback
Definition LogCallback.h:35
ffmpegkit::Signal
Signal
Definition Signal.h:25
ffmpegkit::SignalXcpu
@ SignalXcpu
Definition Signal.h:30
ffmpegkit::SignalQuit
@ SignalQuit
Definition Signal.h:27
ffmpegkit::SignalInt
@ SignalInt
Definition Signal.h:26
ffmpegkit::SignalTerm
@ SignalTerm
Definition Signal.h:29
ffmpegkit::SignalPipe
@ SignalPipe
Definition Signal.h:28
ffmpegkit::FFprobeSessionCompleteCallback
std::function< void(const std::shared_ptr< ffmpegkit::FFprobeSession > session)> FFprobeSessionCompleteCallback
Definition FFprobeSessionCompleteCallback.h:52
ffmpegkit::FFmpegSessionCompleteCallback
std::function< void(const std::shared_ptr< ffmpegkit::FFmpegSession > session)> FFmpegSessionCompleteCallback
Definition FFmpegSessionCompleteCallback.h:52