Unsupported Video format instagram graph API
I Am trying to upload Reels from a business Instagram account for that i already have access token and long lived token.The problem is that whenever i try to publish a reel it gives me "The video file you selected is in a format that we don't support." error code:352 and error_subcode:2207026.I have also converted that video but its saying the same.But I am able to upload a video of "640x480" but not any other resolution like 720x1280 etc. The url of video is aws
I have tried converting video using ffmpeg but it gives me aspect ratio error on 720x1280 whether its 9:16 or 16:9 when i try to upload video of like 1080x1920 it gives me streams error i have also added validation in my uploadReel function and funtion return true but still i am getting video format not supported error
import { Request, Response } from 'express'; import axios from 'axios'; import asyncHandler from '../../../middlewares/asyncHandler'; import ffmpeg from 'fluent-ffmpeg'; import ffmpegInstaller from '@ffmpeg-installer/ffmpeg'; ffmpeg.setFfmpegPath(ffmpegInstaller.path); export const uploadReel = asyncHandler(async (req: Request, res: Response) => { const { longLivedToken, videoUrl }: any = req.body; if (!longLivedToken || !videoUrl) { return res.status(400).json({ error: 'Invalid data' }); } console.log('Checking video format for:', videoUrl); // Check if the video has supported codecs (H.264 for video and AAC for audio) ffmpeg(videoUrl).ffprobe((err, metadata) => { if (err) { console.error('Error reading video metadata:', err.message); return res.status(400).json({ error: 'Unable to check video metadata or invalid file.' }); } console.log('Video metadata:', JSON.stringify(metadata, null, 2)); const hasValidCodec = metadata.streams.some( (stream: any) => stream.codec_name === 'h264' && stream.codec_type === 'video' ) && metadata.streams.some( (stream: any) => stream.codec_name === 'aac' && stream.codec_type === 'audio' ); if (!hasValidCodec) { console.error('Unsupported file format. Expected H.264 video codec and AAC audio codec.'); return res.status(400).json({ error: 'Unsupported file format. Ensure the video is in MP4 format with H.264 video codec and AAC audio codec.', }); } console.log('Video format is supported. Proceeding with upload.'); // If format is supported, proceed to upload the video axios.post( `https://graph.instagram.com/v20.0/me/media`, { media_type: 'REELS', video_url: videoUrl, // Publicly accessible URL of the video file access_token: longLivedToken, }, { headers: { 'Content-Type': 'application/json' }, } ) .then((response) => { console.log('Reel successfully uploaded:', response.data); return res.status(200).json({ mediaId: response.data.id }); }) .catch((error) => { console.error('Error uploading reel:', error.response ? error.response.data : error.message); return res.status(500).json({ error: 'Failed to upload reel' }); }); }); }); export const publishReel = asyncHandler(async (req: Request, res: Response) => { const { mediaId, longLivedToken }: any = req.body; if (!mediaId || !longLivedToken) { return res.status(400).json({ error: 'Invalid data' }); } try { const response = await axios.post( `https://graph.instagram.com/v20.0/me/media_publish`, { creation_id: mediaId, access_token: longLivedToken, }, { headers: { 'Content-Type': 'application/json' } } ); return res.status(200).json({ postId: response.data.id }); // Return post ID } catch (error) { console.error('Error publishing image:', error.response ? error.response.data : error.message)} });