FolderBitrate (Columns with average bitrates for video files in folders)

This add-in creates two script columns: AudioBitRateAvg and VideoBitRateAvg.

For folders, these columns display the average audio and video bitrates of the video files within the folder. Subfolders are skipped.

For individual files, the columns show the same values as the standard columns video.mp3bitrate and video.datarate.

How to set up and use

:one: Save ColumnFolderBitrate.js.txt to   

%appdata%\GPSoftware\Directory Opus\Script AddIns

:two: Toggle the columns with

Set COLUMNSTOGGLE="scp:FolderBitrate/AudioBitRateAvg(!,a,0)"
Set COLUMNSTOGGLE="scp:FolderBitrate/VideoBitRateAvg(!,a,0)"

Things you might enjoy reading

How to use buttons and scripts from this forum
Inspired by Average Video Bit Rate column
Similar: DurationAV (Duration columns for folders)

The script's inner workings

JScript
function OnInit(initData) {
    initData.name = 'FolderBitrate';
    initData.version = '2024-11-14';
    initData.url = 'https://resource.dopus.com/t/folderbitrate-columns-with-average-bitrates-for-video-files-in-folders/53491';
    initData.desc = 'Display Average Audio and Bit Rate for folders.';
    initData.default_enable = true;
    initData.min_version = '13.0';
}

function OnAddColumns(addColData) {
    var col = addColData.AddColumn();
    col.name = 'AudioBitRateAvg';
    col.method = 'OnColumn';
    col.justify = 'right';
    col.type = 'double';
    col.multicol = true;

    var col = addColData.AddColumn();
    col.name = 'VideoBitRateAvg';
    col.method = 'OnColumn';
    col.justify = 'right';
    col.type = 'double';
    col.multicol = true;
}

function OnColumn(scriptColData) {
    var item = scriptColData.item;

    var bitrateAudio = 0;
    var bitrateVideo = 0;
    var countAudio = 0;
    var countVideo = 0;

    if (item.is_dir) {
        var folderEnum = DOpus.FSUtil().ReadDir(item);
        while (!folderEnum.complete) {
            var folderItem = folderEnum.Next();
            var meta = folderItem.metadata;
            if (meta != 'video') continue;

            var d = meta.video.mp3bitrate;
            if (typeof d == 'number') {
                bitrateAudio += d;
                countAudio++;
            }

            var d = meta.video.datarate;
            if (typeof d == 'number') {
                bitrateVideo += d;
                countVideo++;
            }
        }
        folderEnum.Close();
    } else {
        var meta = item.metadata;
        if (meta == 'video') {
            bitrateAudio = meta.audio.mp3bitrate;
            if (typeof bitrateAudio != 'number') bitrateAudio = 0;
            countAudio = 1;

            bitrateVideo = meta.video.datarate;
            if (typeof bitrateVideo != 'number') bitrateVideo = 0;
            countVideo = 1;
        }
    }

    scriptColData.columns('AudioBitRateAvg').value = (countAudio ? bitrateAudio / countAudio : 0).toFixed(1);
    scriptColData.columns('VideoBitRateAvg').value = (countVideo ? bitrateVideo / countVideo : 0).toFixed(1);
}
5 Likes

Bro do you machine was or dry clean your cape? True hero my friend. True hero.