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)} });
Facing the same issue with videos matching perfectly the specs: https://storage.googleapis.com/klap-assets/output_8.mp4
ffprobe version 6.0 Copyright (c) 2007-2023 the FFmpeg developers built with Apple clang version 14.0.0 (clang-1400.0.29.202) configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/6.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon libavutil 58. 2.100 / 58. 2.100 libavcodec 60. 3.100 / 60. 3.100 libavformat 60. 3.100 / 60. 3.100 libavdevice 60. 1.100 / 60. 1.100 libavfilter 9. 3.100 / 9. 3.100 libswscale 7. 1.100 / 7. 1.100 libswresample 4. 10.100 / 4. 10.100 libpostproc 57. 1.100 / 57. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://storage.googleapis.com/klap-assets/output_8.mp4': Metadata: major_brand : mp42 minor_version : 512 compatible_brands: mp42iso2avc1mp41 encoder : Lavf60.3.100 comment : Made with Remotion 4.0.160 Duration: 00:00:59.02, start: 0.000000, bitrate: 4339 kb/s Stream #0:00x1: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown, progressive), 1080x1920 [SAR 1:1 DAR 9:16], 4203 kb/s, 29.99 fps, 30 tbr, 15360 tbn (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0] encoder : Lavc60.3.100 libx264 Stream #0:10x2: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 129 kb/s (default) Metadata: handler_name : SoundHandler vendor_id : [0][0][0][0]
Facing same issue, Here's my video details
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'H4sIAAAAAAAAAxXTBw0AQQwDQUpplwInlT-E1yPwaiTrsdMAkajYSCZ2CZI-azCq0xAHA39ylA9Pd5kmGlb6YfsYDTNFYrxRf-U-GlgaN4PJCTuLjuOCholi7-kruX7RU4cSSo7LYPx0a2A4StDs0KQSQ-9OpeskkEyuXhpgBGczlU27Dwa7qf55wDbhCHZOgMOdnkk0a0nB0geksnUWGLGTVPNaH69oAZe2Hv8lYtEp.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 comment : vid:v12044gd0000cjq6p9jc77u6b3hnu51g aigc_info : {"aigc_label_type": 0} encoder : Lavf58.76.100 Duration: 00:00:58.63, start: 0.000000, bitrate: 991 kb/s Stream #0:00x1: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 576x1024 [SAR 1:1 DAR 9:16], 953 kb/s, 30 fps, 30 tbr, 15360 tbn (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0] Stream #0:10x2: Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 32 kb/s (default) Metadata: handler_name : SoundHandler vendor_id : [0][0][0][0]