Skip to main content
Glama

get_video_info

Extract technical metadata from video files including format, resolution, duration, codec, and bitrate for analysis and conversion preparation.

Instructions

获取视频文件的详细信息,包括格式、分辨率、时长、编解码器、码率等。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes视频文件的完整路径

Implementation Reference

  • The primary handler function for the 'get_video_info' tool. Validates the input file path, retrieves detailed video information using FFmpegService, formats the output including basic info, video stream, and audio stream details, and returns a structured response.
    export async function handleGetVideoInfo(args: GetVideoInfoArgs): Promise<any> {
      const ffmpegService = FFmpegService.getInstance();
      const validator = ValidatorService.getInstance();
    
      try {
        // 验证输入文件
        const validation = await validator.validateVideoFile(args.filePath);
        if (!validation.isValid) {
          return {
            success: false,
            error: `文件验证失败: ${validation.error}`
          };
        }
    
        // 获取视频信息
        console.log(`正在获取视频信息: ${args.filePath}`);
        const videoInfo = await ffmpegService.getVideoInfo(args.filePath);
    
        // 格式化输出信息
        const formattedInfo = {
          基本信息: {
            文件路径: videoInfo.filePath,
            文件格式: videoInfo.format,
            文件大小: `${(videoInfo.size / (1024 * 1024)).toFixed(2)} MB`,
            时长: formatDuration(videoInfo.duration)
          },
          视频流: videoInfo.video ? {
            编解码器: videoInfo.video.codec,
            分辨率: `${videoInfo.video.width} x ${videoInfo.video.height}`,
            帧率: `${videoInfo.video.frameRate.toFixed(2)} fps`,
            码率: (videoInfo.video.bitrate && videoInfo.video.bitrate > 0) ? `${Math.round(videoInfo.video.bitrate / 1000)} kbps` : '未知'
          } : null,
          音频流: videoInfo.audio ? {
            编解码器: videoInfo.audio.codec,
            采样率: `${videoInfo.audio.sampleRate} Hz`,
            声道数: videoInfo.audio.channels,
            码率: (videoInfo.audio.bitrate && videoInfo.audio.bitrate > 0) ? `${Math.round(videoInfo.audio.bitrate / 1000)} kbps` : '未知'
          } : null
        };
    
        return {
          success: true,
          message: '成功获取视频信息',
          data: {
            原始信息: videoInfo,
            格式化信息: formattedInfo
          }
        };
    
      } catch (error: any) {
        console.error('获取视频信息失败:', error);
        return {
          success: false,
          error: `获取信息失败: ${error.message}`
        };
      }
    }
  • Tool definition object for 'get_video_info' including the inputSchema that defines the expected parameters (filePath: string).
    export const getVideoInfoTool: Tool = {
      name: 'get_video_info',
      description: '获取视频文件的详细信息,包括格式、分辨率、时长、编解码器、码率等。',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: '视频文件的完整路径'
          }
        },
        required: ['filePath']
      }
    };
  • Registration of tool handlers mapping, where 'get_video_info' is mapped to its handleGetVideoInfo function for execution during tool calls.
    export const toolHandlers = {
      convert_video: handleConvertVideo,
      get_video_info: handleGetVideoInfo,
      batch_convert: handleBatchConvert
    };
  • Registration in the tools array used for listing available tools, including getVideoInfoTool.
    export const tools = [
      convertVideoTool,
      getVideoInfoTool,
      batchConvertTool
    ];
  • Core helper method in FFmpegService that uses ffprobe to extract detailed video metadata including format, size, duration, video/audio streams (codec, resolution, framerate, bitrate), with fallback logic for duration calculation.
    async getVideoInfo(filePath: string): Promise<VideoInfo> {
      return new Promise((resolve, reject) => {
        ffmpeg.ffprobe(filePath, (err, metadata) => {
          if (err) {
            reject(new Error(`获取视频信息失败: ${err.message}`));
            return;
          }
    
          try {
            const stats = statSync(filePath);
            const videoStream = metadata.streams.find(s => s.codec_type === 'video');
            const audioStream = metadata.streams.find(s => s.codec_type === 'audio');
    
            // 修复时长获取逻辑,特别是对WMV等格式
            let duration = metadata.format.duration || 0;
            
            // 如果format中没有时长信息,尝试从视频流中获取
            if (!duration || duration === 0) {
              if (videoStream && videoStream.duration) {
                duration = parseFloat(videoStream.duration);
              } else if (audioStream && audioStream.duration) {
                duration = parseFloat(audioStream.duration);
              }
            }
            
            // 如果还是没有时长,尝试通过帧数和帧率计算
            if (!duration || duration === 0) {
              if (videoStream && videoStream.nb_frames && videoStream.r_frame_rate) {
                const frameCount = parseInt(videoStream.nb_frames);
                const frameRate = this.parseFrameRate(videoStream.r_frame_rate);
                if (frameCount > 0 && frameRate > 0) {
                  duration = frameCount / frameRate;
                }
              }
            }
    
            const videoInfo: VideoInfo = {
              filePath,
              format: metadata.format.format_name || '未知',
              size: stats.size,
              duration: duration,
            };
    
            if (videoStream) {
              videoInfo.video = {
                codec: videoStream.codec_name || '未知',
                width: videoStream.width || 0,
                height: videoStream.height || 0,
                frameRate: this.parseFrameRate(videoStream.r_frame_rate),
                bitrate: videoStream.bit_rate ? parseInt(videoStream.bit_rate) : null,
              };
            }
    
            if (audioStream) {
              videoInfo.audio = {
                codec: audioStream.codec_name || '未知',
                sampleRate: audioStream.sample_rate || 0,
                channels: audioStream.channels || 0,
                bitrate: audioStream.bit_rate ? parseInt(audioStream.bit_rate) : null,
              };
            }
    
            resolve(videoInfo);
          } catch (parseError) {
            reject(new Error(`解析视频信息失败: ${parseError}`));
          }
        });
      });
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While it indicates this is an information retrieval operation ('获取' meaning 'get'), it doesn't address important behavioral aspects like whether this requires file system access permissions, what happens if the file doesn't exist or is inaccessible, whether there are rate limits, or what the response format looks like. For a file operation tool with zero annotation coverage, this represents significant gaps in behavioral transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that clearly states the tool's purpose and enumerates the types of information it retrieves. There's no wasted language or unnecessary elaboration. While it could potentially benefit from more context about usage or behavior, what's present is well-structured and front-loaded with the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter read operation with no output schema, the description provides adequate but minimal coverage. It clearly states what information the tool retrieves, which is helpful context given the lack of output schema. However, with no annotations and sibling tools present, it should ideally provide more guidance about when to use this versus alternatives and address behavioral aspects like error conditions or access requirements.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'filePath' clearly documented as '视频文件的完整路径' (complete path to the video file). The description doesn't add any parameter-specific information beyond what the schema already provides, nor does it need to since schema coverage is complete. This meets the baseline expectation when the schema handles parameter documentation effectively.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as retrieving detailed information about video files, specifying the types of information included (format, resolution, duration, codec, bitrate). It uses specific verbs ('获取' meaning 'get/retrieve') and identifies the resource ('视频文件' meaning 'video file'). However, it doesn't explicitly differentiate from sibling tools like batch_convert or convert_video, which appear to be transformation tools rather than information retrieval tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While the purpose suggests it's for retrieving metadata rather than converting videos (which the sibling tools appear to do), there's no explicit comparison or context about when this tool is appropriate versus when other tools might be needed. The description simply states what the tool does without usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pickstar-2002/video-convert-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server