module_08.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <libavformat/avformat.h>
  6. #define BOLD_GRAY "\033[1;90m"
  7. #define RED "\033[0;31m"
  8. #define WHITE "\033[0;37m"
  9. #define RESET "\033[0m"
  10. int module_08_run(const char *filename) {
  11. char log_msg[1024];
  12. AVFormatContext *fmt_ctx = NULL;
  13. if (avformat_open_input(&fmt_ctx, filename, NULL, NULL) < 0) {
  14. snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Library libavformat: " RED "Error opening file" RESET);
  15. printf("%s\n", log_msg);
  16. return 1;
  17. }
  18. if (avformat_find_stream_info(fmt_ctx, NULL) < 0) {
  19. snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Library libavformat: " RED "Error finding stream info" RESET);
  20. printf("%s\n", log_msg);
  21. avformat_close_input(&fmt_ctx);
  22. return 1;
  23. }
  24. snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Library libavformat: " WHITE "Media format: %s, Duration: %ld seconds, Streams: %d" RESET,
  25. fmt_ctx->iformat->name, fmt_ctx->duration / AV_TIME_BASE, fmt_ctx->nb_streams);
  26. printf("%s\n", log_msg);
  27. avformat_close_input(&fmt_ctx);
  28. return 0;
  29. }