Files

35 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libavformat/avformat.h>
#define BOLD_GRAY "\033[1;90m"
#define RED "\033[0;31m"
#define WHITE "\033[0;37m"
#define RESET "\033[0m"
int module_08_run(const char *filename) {
char log_msg[1024];
AVFormatContext *fmt_ctx = NULL;
if (avformat_open_input(&fmt_ctx, filename, NULL, NULL) < 0) {
snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Library libavformat: " RED "Error opening file" RESET);
printf("%s\n", log_msg);
return 1;
}
if (avformat_find_stream_info(fmt_ctx, NULL) < 0) {
snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Library libavformat: " RED "Error finding stream info" RESET);
printf("%s\n", log_msg);
avformat_close_input(&fmt_ctx);
return 1;
}
snprintf(log_msg, sizeof(log_msg), BOLD_GRAY " Library libavformat: " WHITE "Media format: %s, Duration: %ld seconds, Streams: %d" RESET,
fmt_ctx->iformat->name, fmt_ctx->duration / AV_TIME_BASE, fmt_ctx->nb_streams);
printf("%s\n", log_msg);
avformat_close_input(&fmt_ctx);
return 0;
}