Skip to content

Commit

Permalink
Raise warning instead of error if file has no audio stream
Browse files Browse the repository at this point in the history
Fixes #138
  • Loading branch information
complexlogic committed Feb 8, 2025
1 parent c62a63c commit 909d3fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,20 @@ bool ScanJob::scan(std::mutex *ffmpeg_mutex)
}
}
}
ScanReturn ret;
std::vector<int> remove;
for (Track &track : tracks) {
error = !track.scan(config, ffmpeg_mutex);
if (error)
ret = track.scan(config, ffmpeg_mutex);
if (ret == ScanReturn::ERROR) {
error = true;
return false;
}
else if (ret == ScanReturn::NO_STREAM)
remove.push_back(&track - &tracks[0]);
}
for (auto it = remove.rbegin(); it != remove.rend(); ++it) {
tracks.erase(tracks.begin() + *it);
nb_files--;
}
calculate_loudness();
}
Expand All @@ -189,12 +199,12 @@ bool ScanJob::scan(std::mutex *ffmpeg_mutex)
return true;
}

bool ScanJob::Track::scan(const Config &config, std::mutex *m)
ScanReturn ScanJob::Track::scan(const Config &config, std::mutex *m)
{
ProgressBar progress_bar;
int rc, stream_id = -1;
uint8_t *swr_out_data[1];
bool ret = false;
ScanReturn ret = ScanReturn::ERROR;
bool repeat = false;
int peak_mode;
double time_base;
Expand Down Expand Up @@ -253,7 +263,8 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
stream_id = av_find_best_stream(format_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
if (stream_id < 0) {
if (!multithread)
output_error("Could not find audio stream");
output_warn("Could not find audio stream\n");
ret = ScanReturn::NO_STREAM;
goto end;
}
stream = format_ctx->streams[stream_id];
Expand Down Expand Up @@ -448,7 +459,7 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
if (output_progress)
progress_bar.complete();

ret = true;
ret = ScanReturn::SUCCESS;
end:
av_packet_free(&packet);
av_frame_free(&frame);
Expand Down
8 changes: 7 additions & 1 deletion src/scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ struct ScanResult {
double album_loudness;
};

enum class ScanReturn {
ERROR,
NO_STREAM,
SUCCESS
};

struct ScanData {
size_t files = 0;
size_t skipped = 0;
Expand Down Expand Up @@ -62,7 +68,7 @@ class ScanJob {
bool aclip = false;

Track(const std::filesystem::path &path, FileType type) : path(path), type(type), ebur128(nullptr, free_ebur128) {};
bool scan(const Config &config, std::mutex *ffmpeg_mutex);
ScanReturn scan(const Config &config, std::mutex *ffmpeg_mutex);
void calculate_loudness(const Config &config);
};

Expand Down

0 comments on commit 909d3fa

Please sign in to comment.