简体   繁体   中英

Convert a JPG file to MP4 video using Node

I need to convert a JPG to 3-4sec long mp4 using NodeJS. Everywhere I search I find information about ffmpeg but nothing works for me. Currently I'm trying with fluent-ffmpeg. Here is my code:

let ffmpegPath = require('@ffmpeg-installer/ffmpeg').path
let ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfmpegPath(ffmpegPath)
let command = ffmpeg()
command
  .input(imagePath)
  .inputFPS(1 / 5)
  .outputFPS(30)
  .videoCodec('libx264')
  .videoBitrate(1024)
  .size('640x?')
  .loop(5)
  .noAudio()
  .on('end', () => {
    resolve(saveTo)
  }).save(saveTo)

I'm open for other NodeJs solutions as well. I've tried VideoShow library but it throws errors when an image is being uploaded from Android Phone.

I found this working for me:

let ffmpegPath = require('@ffmpeg-installer/ffmpeg').path
    let ffmpeg = require('fluent-ffmpeg')
    ffmpeg.setFfmpegPath(ffmpegPath)
    let command = ffmpeg(imagePath)
    command
      .inputFPS(1)
      .outputFPS(30)
      .videoCodec('libx264')
      .videoBitrate(1024)
      .size('640x?')
      .loop(3.5)
      .noAudio()
      .save(saveTo)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM