Loading...
Searching...
No Matches
LibavMediaInfo.hpp
1#pragma once
2#include <Media/Libav.hpp>
3
4#include <score_plugin_media_export.h>
5
6#if SCORE_HAS_LIBAV
7
8#include <QString>
9
10#include <optional>
11#include <stdexcept>
12#include <string>
13#include <vector>
14
15extern "C" {
16#include <libavformat/avformat.h>
17}
18
19namespace score::libav
20{
21
34struct SCORE_PLUGIN_MEDIA_EXPORT MediaInfo
35{
37 {
38 void operator()(AVFormatContext* ctx) const noexcept
39 {
40 if(ctx)
41 avformat_close_input(&ctx);
42 }
43 };
44 using FormatContextPtr = std::unique_ptr<AVFormatContext, FormatContextDeleter>;
45
46 FormatContextPtr format_context;
47 std::vector<AVMediaType> streams;
48 std::optional<int64_t> duration_av; // in AV_TIME_BASE units; empty == unknown
49
50 std::optional<double> duration_seconds() const noexcept
51 {
52 if(!duration_av)
53 return std::nullopt;
54 return *duration_av / double(AV_TIME_BASE);
55 }
56
57 bool has_video() const noexcept
58 {
59 for(auto t : streams)
60 if(t == AVMEDIA_TYPE_VIDEO)
61 return true;
62 return false;
63 }
64
65 bool has_audio() const noexcept
66 {
67 for(auto t : streams)
68 if(t == AVMEDIA_TYPE_AUDIO)
69 return true;
70 return false;
71 }
72};
73
87SCORE_PLUGIN_MEDIA_EXPORT
88std::optional<MediaInfo> probe(const QString& path);
89
96SCORE_PLUGIN_MEDIA_EXPORT
97MediaInfo probe_or_throw(const QString& path);
98
99} // namespace score::libav
100
101#endif
Definition LibavMediaInfo.hpp:37
Result of probing a media file.
Definition LibavMediaInfo.hpp:35