public static boolean isTranscodeRequired(TranscodeProfile profile, VideoStream stream) {
    if (!isSupported(profile.getCodecs(), stream.getCodec())) {
      return true;
    }

    // Check bitrate
    if (profile.getMaxBitRate() != null) {
      if (profile.getMediaElement().getBitrate() > profile.getMaxBitRate()) {
        return true;
      }
    }

    // If direct play is not enabled check stream parameters
    if (!profile.isDirectPlayEnabled()) {
      // Check bitrate
      if (profile.getMediaElement().getBitrate()
          > VIDEO_QUALITY_MAX_BITRATE[profile.getQuality()]) {
        return true;
      }

      // Check resolution
      if (compareDimensions(
              new Dimension(stream.getWidth(), stream.getHeight()),
              VIDEO_QUALITY_RESOLUTION[profile.getQuality()])
          == 1) {
        return true;
      }
    }

    return false;
  }
  public static boolean processVideo(TranscodeProfile profile) {
    // Check variables
    if (profile.getMediaElement() == null
        || profile.getCodecs() == null
        || profile.getFormat() == null
        || profile.getQuality() == null) {
      return false;
    }

    // Check this is a video element
    if (profile.getMediaElement().getType() != MediaElementType.VIDEO) {
      return false;
    }

    // Variables
    String codec = null;
    Dimension resolution = null;
    boolean transcodeRequired = false;
    VideoStream stream = profile.getMediaElement().getVideoStream();

    if (stream == null) {
      return false;
    }

    // Check if subtitles require transcode
    if (profile.getSubtitleTrack() != null && profile.getSubtitleTranscodes() != null) {
      if (profile.getSubtitleTranscodes()[profile.getSubtitleTrack()].isHardcoded()) {
        transcodeRequired = true;
      }
    }

    // Test if transcoding is necessary
    if (!transcodeRequired) {
      transcodeRequired = isTranscodeRequired(profile, stream);
    }

    // Test that the codec is supported by the given format
    if (!transcodeRequired) {
      transcodeRequired = !isSupported(getCodecsForFormat(profile.getFormat()), stream.getCodec());
    }

    if (transcodeRequired) {
      // Get suitable codec
      for (String test : profile.getCodecs()) {
        if (isSupported(getCodecsForFormat(profile.getFormat()), test)
            && isSupported(TRANSCODE_VIDEO_CODECS, test)) {
          codec = test;
          break;
        }
      }

      // Check we got a suitable codec
      if (codec == null) {
        return false;
      }

      // Get suitable resolution (use native resolution if direct play is enabled)
      if (!profile.isDirectPlayEnabled()) {
        resolution = getVideoResolution(profile);
      }
    } else {
      codec = "copy";
    }

    // Update profile with video transcode properties
    profile.setVideoTranscode(new VideoTranscode(codec, resolution));

    return true;
  }