node.js – FFmpeg QuickTime to MP4 conversion drastically reduces video duration (6 seconds becomes 1 second)
I’m recording screen content in Safari which generates QuickTime files. I convert these QuickTime files to MP4 format using FFmpeg in Node.js. However, the converted MP4 files have significantly shorter duration than the original QuickTime files.
Original QuickTime file: 6 seconds
Converted MP4 file: 1 second
Environment
- Platform: Node.js with TypeScript
- FFmpeg library: fluent-ffmpeg
- Input format: QuickTime (.quicktime)
- Output format: MP4
- Recording source: Safari screen recording
FFmpeg Setup
import ffmpeg from 'fluent-ffmpeg';
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
ffmpeg.setFfmpegPath(ffmpegPath.path);
const convertToMp4 = (inputPath: string, outputPath: string): Promise => {
return new Promise((resolve, reject) => {
const outputDir = path.dirname(outputPath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
ffmpeg(inputPath)
.videoCodec('libx264')
.size('320x240')
.outputOptions([
'-movflags faststart',
'-pix_fmt yuv420p',
'-vf scale=trunc(iw/2)*2:trunc(ih/2)*2',
'-crf 23',
'-preset ultrafast',
'-profile:v baseline',
'-level 3.0',
'-threads 4',
])
.format('mp4')
.on('end', resolve)
.on('error', reject)
.save(outputPath);
});
};
Input File Details
{
"fieldname": "file",
"originalname": "video.quicktime",
"encoding": "7bit",
"mimetype": "video/quicktime",
"destination": "src\\modules\\common\\.cache",
"filename": "nRgy1758706850824-video.quicktime",
"path": "src\\modules\\common\\.cache\\nRgy1758706850824-video.quicktime",
"size": 6187220
}
What I’ve Tried
- Verified that the original QuickTime file plays correctly for 6 seconds
- Checked that the conversion completes without errors
- Confirmed that the output MP4 file is created but only shows 1 second duration
Questions
- Why is FFmpeg reducing the video duration during QuickTime to MP4 conversion?
- Which FFmpeg settings might be causing this duration loss?
- How can I preserve the original video duration during conversion?
- Are there specific considerations for QuickTime files recorded from Safari?
Expected Result
The converted MP4 file should maintain the same 6-second duration as the original QuickTime file.
Additional Context
This happens consistently with Safari screen recordings. The conversion process completes successfully, but the resulting MP4 files are significantly shorter than expected.
Read more here: Source link
