i am uploading reels via instagram api , the images are getting uploaded fine but for reels an error occurer

  Kiến thức lập trình

i am uploading reels via instagram api , the images are getting uploaded fine but for reels an error occurer The video format is not supported. Please check spec for supported aspect_ratio format.

i am using ffmpeg to compile my vedio

compile: () => {
    return new Promise(async (resolve, reject) => {
        try {
            const videosDir = path.join(__dirname, '../public/images'); // Directory containing video files
            const outputVideoPath = path.join(__dirname, '../public/videos', 'output.mov'); // Output video path
            const audioFilePath = path.join(__dirname, '../voiceOver', 'voiceoverCut.wav'); // Path to the audio file
            // const subtitlesFilePath = path.join(__dirname, '../voiceOver', 'subtitles.srt'); // Path to the subtitles file (using .srt format)
            const subtitlesFilePath = 'D\:/programming/ai/voiceOver/subtitles.srt' // Path to the subtitles file (using .srt format)


            console.log("Audio file path:", audioFilePath);
            console.log("vedio file path:", videosDir);
            console.log("Subtitles file path:", subtitlesFilePath);

            // Get the list of video files
            let videoFiles = fs.readdirSync(videosDir).filter(file => file.match(/^vidd+.mp4$/));

            // Shuffle video files
            videoFiles = module.exports.shuffleArrayVedios(videoFiles);

            // Create a new FFmpeg command
            const command = ffmpeg();

            // Add video inputs
            videoFiles.forEach(video => {
                command.input(path.join(videosDir, video));
            });

            // Add audio input separately
            command.input(audioFilePath);

            // Create the filter_complex command
            const filterComplex = [
                `[0:v][1:v][2:v][3:v][4:v][5:v][6:v][7:v][8:v][9:v][10:v][11:v][12:v]concat=n=${videoFiles.length}:v=1:a=0[outv]`,
                `[outv]eq=brightness=-0.1:contrast=1.1[darkened]`,
                `[darkened]scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2[scaled]`,  // 9:16 aspect ratio
                `[scaled]subtitles='${subtitlesFilePath}':force_style='FontSize=24,Alignment=10,OutlineColour=&H00000000,BorderStyle=1,FontName=Arial,FontWeight=1000'[outv_with_subs]`,
                `[${videoFiles.length}:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1.5[a]`
            ];

            command
                .complexFilter(filterComplex.join(';'))
                .outputOptions([
                    '-map [outv_with_subs]',
                    '-map [a]',
                    '-c:v libx264',  // H264 codec
                    '-profile:v high',  // High profile for better quality
                    '-level 4.2',
                    '-preset slow',
                    '-crf 23',
                    '-c:a aac',
                    '-b:a 128k',
                    '-ar 44100',
                    '-movflags +faststart',
                    '-pix_fmt yuv420p',
                    '-r 30',
                    '-b:v 15M',  // Video bitrate (adjust as needed, max 25Mbps)
                    '-maxrate 20M',
                    '-bufsize 10M',
                    '-t 900',  // Limit duration to 15 minutes (900 seconds)
                    '-shortest',
                    '-max_muxing_queue_size 1024'
                ])// Map adjusted video and audio, and limit to the shortest stream
                .output(outputVideoPath)
                .on('start', (commandLine) => {
                    console.log('Spawned FFmpeg with command: ' + commandLine);
                })
                .on('progress', (progress) => {
                    console.log('Processing: ' + JSON.stringify(progress) + '% done');
                })
                .on('end', () => {
                    console.log('Video compilation finished!');
                    resolve();
                })
                .on('error', (err) => {
                    console.error('Error during video compilation:', err);
                    reject(err);
                })
                .run();

        } catch (err) {
            console.error('Error during processing:', err);
            reject(err);
        }
    });
},


and i am checking the video upload with google collab python , there is no issue with the code

import requests
import time
import json

def print_response(response):
    print(f"Status Code: {response.status_code}")
    print(f"Headers: {json.dumps(dict(response.headers), indent=2)}")
    print(f"Content: {json.dumps(response.json(), indent=2)}")

# Instagram API endpoint to create a media container
endpoint = "https://graph.instagram.com/v20.0/17841468745414388/media"

# Data for the request
data = {
    "media_type": "REELS",
    "video_url": "https://files.catbox.moe/bkn12u.mp4",
    "caption": "Your Reel Title Here",
    "access_token": "IGQWRPRlNwMlBCTk5PcnRUYXJuZAnhKMDF1enZAUQ3ZAkWUFxTFhfSnZAsWk9ka1B2alE5a3ZARdXRiZA3lpODJkbFBfR0lmamVZAMTQxSDhDb0FabjhBcVJhTWYzczhfSF9KVDlKZAzBZAT3RUOUc4VXg2VVRPRFNBcDlydk0ZD"
}

# Send the POST request
response = requests.post(endpoint, data=data)

# Check response
print("Media Container Creation Response:")
print_response(response)

if response.status_code != 200:
    print("Error creating media container. Exiting.")
    exit()

container_id = response.json().get('id')
if not container_id:
    print("No container ID received. Exiting.")
    exit()

print(f"Container ID: {container_id}")

# Wait for processing
print("Waiting for 60 seconds...")
time.sleep(10)

# Instagram API endpoint to publish the media
publish_endpoint = f"https://graph.instagram.com/v20.0/17841468745414388/media_publish"

# Data for the request
publish_data = {
    "creation_id": container_id,
    "access_token": "IGQWRPRlNwMlBCTk5PcnRUYXJuZAnhKMDF1enZAUQ3ZAkWUFxTFhfSnZAsWk9ka1B2alE5a3ZARdXRiZA3lpODJkbFBfR0lmamVZAMTQxSDhDb0FabjhBcVJhTWYzczhfSF9KVDlKZAzBZAT3RUOUc4VXg2VVRPRFNBcDlydk0ZD"
}

# Send the POST request
publish_response = requests.post(publish_endpoint, data=publish_data)

# Check response
print("nMedia Publish Response:")
print_response(publish_response)

if publish_response.status_code == 200:
    print("Reel published successfully!")
else:
    print("Error publishing Reel.")`

i have tried changing mp4 to mov , and many things

i am using cat box to host my video

I found it ,
It was problem of instagram api
Instead do with instagram with facebook login

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT