그냥 간단하게 동영상에서 정보를 읽어 보자.
사용한 ffmpeg library는 지난번에 빌드한 것을 사용한다.
2023.01.07 - [놀기/잡스러운 것] - ffmpeg build (Windows 기반, win32 버전)
Project 파일에 경로를 추가하고
QT -= gui
FFMPEG_DEV_PATH = "E:/busyman/Lib/ffmpeg_dev"
CONFIG += c++17 console
CONFIG -= app_bundle
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
INCLUDEPATH += $$FFMPEG_DEV_PATH/include
LIBS += -L$$FFMPEG_DEV_PATH/lib
아래와 같이 예제를 작성한다.
#include <QCoreApplication>
#include <QTimer>
#include <QDebug>
extern "C" {
#include "libavutil/adler32.h"
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
}
#pragma comment(lib, "Secur32.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "bcrypt.lib")
#pragma comment(lib, "Mfplat.lib")
#pragma comment(lib, "Mfuuid.lib")
#pragma comment(lib, "Strmiids.lib")
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "User32.lib")
#pragma comment(lib, "libavcodec.a")
#pragma comment(lib, "libavdevice.a")
#pragma comment(lib, "libavfilter.a")
#pragma comment(lib, "libavformat.a")
#pragma comment(lib, "libavutil.a")
#pragma comment(lib, "libpostproc.a")
#pragma comment(lib, "libswresample.a")
#pragma comment(lib, "libswscale.a")
int run_main(void)
{
int sec = 0;
int result;
int video_stream;
const AVCodec* codec = NULL;
AVFormatContext* fmt_ctx = NULL;
AVCodecParameters* origin_par = NULL;
QString input_filename = QString("E:/_001/test.mkv");
result = avformat_open_input(&fmt_ctx, input_filename.toLocal8Bit().constData(), NULL, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
return result;
}
result = avformat_find_stream_info(fmt_ctx, NULL);
if (result < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
goto end;
}
video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
if (video_stream < 0) {
av_log(NULL, AV_LOG_ERROR, "Can't find video stream in input file\n");
result = video_stream;
goto end;
}
origin_par = fmt_ctx->streams[video_stream]->codecpar;
codec = avcodec_find_decoder(origin_par->codec_id);
if (!codec) {
av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n");
result = AVERROR_DECODER_NOT_FOUND;
goto end;
}
av_log(NULL, AV_LOG_INFO, "input formate = %s\n", fmt_ctx->iformat->name);
av_log(NULL, AV_LOG_INFO, "video codec name = %s\n", codec->name);
av_log(NULL, AV_LOG_INFO, "bit_rate = %dKbps\n", (int) (fmt_ctx->bit_rate/1024));
sec = fmt_ctx->duration/(1000000);
av_log(NULL, AV_LOG_INFO, "duration = %02d:%02d:%02d.%03d\n", (int) (sec/3600), (int) ((sec%3600)/60), (int) ((sec%3600)%60), (int) ((fmt_ctx->duration/1000)%1000));
end:
avformat_close_input(&fmt_ctx);
return result;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTimer::singleShot(0,[](){
run_main();
QCoreApplication::exit(0);
});
return a.exec();
}
실행 결과는 아래와 같다.
input formate = matroska,webm
video codec name = h264
bit_rate = 0Kbps
duration = 01:07:03.040
'놀기 > 잡스러운 것' 카테고리의 다른 글
[Shell Script] 0부터 1씩 증가 시키며 숫자 출력하기 (0) | 2023.03.17 |
---|---|
YUV Viewer (0) | 2023.02.15 |
ffmpeg build (Windows 기반, win32 버전) (0) | 2023.01.07 |
MSYS2 설치 (0) | 2023.01.07 |
[batch] 파일 목록 출력 (이름만, 확장자 제거, 전체 경로) (0) | 2022.05.22 |
댓글