我正在通过 instagram api 上传卷轴,图像上传正常,但卷轴发生错误

问题描述 投票:0回答:1

我正在通过 instagram api 上传卷轴,图像上传正常,但卷轴出现错误,不支持视频格式。请检查规格以了解支持的宽高比格式。

我正在使用 ffmpeg 来编译我的视频

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(/^vid\d+\.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);
        }
    });
},


我正在使用 google collab python 检查视频上传,代码没有问题

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.")`

我尝试过将 mp4 更改为 mov ,还有很多事情

我正在使用猫盒来托管我的视频

instagram instagram-api instagram-graph-api instagram-reels
1个回答
0
投票

我找到了, 这是 Instagram api 的问题 相反,使用 Instagram 和 Facebook 登录

© www.soinside.com 2019 - 2024. All rights reserved.