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
14extern "C" {
15#include <libavformat/avformat.h>
16}
17
18namespace score::libav
19{
20
33struct SCORE_PLUGIN_MEDIA_EXPORT MediaInfo
34{
36 {
37 void operator()(AVFormatContext* ctx) const noexcept
38 {
39 if(ctx)
40 avformat_close_input(&ctx);
41 }
42 };
43 using FormatContextPtr = std::unique_ptr<AVFormatContext, FormatContextDeleter>;
44
45 FormatContextPtr format_context;
46 std::vector<AVMediaType> streams;
47 std::optional<int64_t> duration_av; // in AV_TIME_BASE units; empty == unknown
48
49 std::optional<double> duration_seconds() const noexcept
50 {
51 if(!duration_av)
52 return std::nullopt;
53 return *duration_av / double(AV_TIME_BASE);
54 }
55
56 bool has_video() const noexcept
57 {
58 for(auto t : streams)
59 if(t == AVMEDIA_TYPE_VIDEO)
60 return true;
61 return false;
62 }
63
64 bool has_audio() const noexcept
65 {
66 for(auto t : streams)
67 if(t == AVMEDIA_TYPE_AUDIO)
68 return true;
69 return false;
70 }
71};
72
86SCORE_PLUGIN_MEDIA_EXPORT
87std::optional<MediaInfo> probe(const QString& path);
88
95SCORE_PLUGIN_MEDIA_EXPORT
96MediaInfo probe_or_throw(const QString& path);
97
98} // namespace score::libav
99
100#endif
Definition LibavMediaInfo.hpp:36
Result of probing a media file.
Definition LibavMediaInfo.hpp:34