Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to create a set of flow plugins that use a metadata tag to indicate that Tdarr has transcoded a mkv video file. #737

Open
Media588 opened this issue Jan 3, 2025 · 2 comments

Comments

@Media588
Copy link

Media588 commented Jan 3, 2025

I am new to Tdarr and I can’t seem to figure out how to write the flow plugins I need, but I am trying to add a tag to the metadata of a mkv video file to be used as an indicator for Tdarr to show that it has previously transcoded a video file. I have looked in the community plugins folder and I can’t seem to find anything that will perform this task.

I know the status queue keeps track of the videos that Tdarr has transcoded but it can be easily reset if I accidently click “Scan Fresh” in the library or if I reinstall Tdarr on another PC and I have to re-create the library.

I am currently adding “TdarrOptimized” to the end of the video file name as the last step in my transcode flow. My transcode flow also checks for the “TdarrOptimized” phrase in the file name and skips any video file that has already been transcoded. My solution works fine but renaming the file breaks the link to the associated subtitle file in the video folder.

I feel like a better solution would be to have 2 flow plugins that:

  1. Write a keypair similar to “TdarrOptimized=yes” into the metadata of the mkv video file.
  2. Check for the phrase “TdarrOptimized=yes” in the metadata of the mkv video file and return 2 results, true/false.
    The keypair could alternatively reference the codec that was used to transcode the video file. Example: “TdarrOptimized=hevc”.

With these 2 flow plugins, I could be sure that I would not re-transcode a video file even if it was added to a new library. I would also resolve the issue of breaking the subtitle links and would not have to have a separate folder for non-transcoded files as some have suggested.

Please let me know if there are any such plugins available that I may have overlooked.

Thanks,

@quadcom
Copy link

quadcom commented Jan 6, 2025

It is already possible with the available flow nodes. I have one running for this exact purpose.

I have two nodes that add tags to the track0 stream (video stream) to monitor processing and at what settings.

image

The first one in the above SS sets a tag to track the CQ rate I had set at the time.

image

I use a global variable to allow for ease of change and reuse. You can set those on the Tools page.

image

This second node adds a tag to note that the file was reencoded by Tdarr.
image

Then, at the start of the flow, I have a node that looks for these values.
image

Where this gets confusing is the output ports of the nodes. The goal is that if the tag is found, you want the file skipped, so the output port logic needs to be flipped in your head.

image

In this case, if the tag is found, it should be passed out port 2. If it is NOT found, it should go out of port 1 or port 3. It needs both in my flow as the Tdarr tag could be there but has a different value than TRUE. If the tag is missing altogether, it goes out of port 3.

@Media588
Copy link
Author

Media588 commented Jan 10, 2025

Thanks for the information, I will look into it and see if I can improve my hacked solution. A couple of days after I asked the question, I was able to figure out how to create a custom FFmpeg Command that copied the current video file metadata and added my tag. I then created a Custom JS Function to check for the tag. The solution I came up with is outlined below in case anyone else needs this type of metadata tagging.

Here is a simple flow with my two custom elements added. The flow checks for the TDARR-OPTIMIZED = hevc tag and exits the flow if the tag is found and equals hevc. If the tag does not exist, or does not equal hevc, the flow adds the tag using the custom FFmpeg Command and replaces the original file.
image

  1. Below is the custom JS Code placed in this element:
    image
module.exports = async (args) => {
    const { ffProbeData } = args.inputFileObj;  // Extract ffProbeData from the input file object
    let hasTag = false;  // Flag to check if the tag is found and its value is correct
    let errorOccurred = false;  // Flag to track errors

    try {
        // Check if ffProbeData and format exist
        if (ffProbeData && ffProbeData.format && ffProbeData.format.tags) {
            // Check if the 'TDARR-OPTIMIZED' tag exists and its value is 'hevc'
            if (ffProbeData.format.tags['TDARR-OPTIMIZED'] === 'hevc') {
                hasTag = true;  // Tag found and correct value
            }
        }
    } catch (error) {
        errorOccurred = true;  // If an error occurs, set the error flag
    }

    // Return output based on the result
    if (errorOccurred) {
        return {
            outputFileObj: args.inputFileObj,  // Return the input file object unchanged
            outputNumber: 3,  // Option 3: Error
            variables: args.variables,  // Pass through variables
        };
    }

    if (hasTag) {
        return {
            outputFileObj: args.inputFileObj,  // Return the input file object unchanged
            outputNumber: 1,  // Option 1: Tag found and correct value ('hevc')
            variables: args.variables,  // Pass through variables
        };
    }

    return {
        outputFileObj: args.inputFileObj,  // Return the input file object unchanged
        outputNumber: 2,  // Option 2: Tag not found or incorrect value
        variables: args.variables,  // Pass through variables
    };
};
  1. Below is the custom FFmpeg command placed in this element:
    image
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants