Open hoangqwe159 opened 10 months ago
I am also facing this issue with input as a buffer.
// The function return N/A on duration
async convertOggBufferToWavFile(inputBuffer, outputPath, durationLimit = 30) {
const wavFileDestination = outputPath ?? path.join(__dirname, `${uuidv4}.wav`);
const inputStream = new Readable({
// encoding: 'base64',
read() {
this.push(inputBuffer);
this.push(null);
}
});
return new Promise((resolve, reject) => {
let audioData = { 'path': wavFileDestination };
ffmpeg(inputStream)
.outputOptions('-acodec', 'pcm_s16le')
.duration(durationLimit)
.on('codecData', function (data) {
if (data.format && data.audio) { // Check that format and audio codec are present
audioData = { ...audioData, data };
// Convert duration from HH:mm:ss.sss to seconds
if (data.duration) {
const durationRegex = /^(\d+):(\d{2}):(\d{2}\.\d{3})$/;
const matches = durationRegex.exec(data.duration);
if (matches) {
const [_, hours, minutes, secondsAndMillis] = matches;
const totalSeconds = (Number(hours) * 3600) + (Number(minutes) * 60) + Number(secondsAndMillis);
audioData.duration_s = totalSeconds;
} else {
console.warn(`Warning: invalid duration format "${data.duration}"`);
}
}
}
})
.on('error', (error) => reject(error))
.on('end', () => resolve(audioData))
.saveToFile(wavFileDestination);
});
}
// Calling the function from a test case
const inputBuffer = fs.readFileSync(testOggFilePath);
const outputPath = `./tests/${uuidv4()}.wav`;
const result = await convertOggBufferToWavFile(inputBuffer, outputPath);
The .on('codecData', function (data) {
gives data with duration = N/A. I am using the buffer in the test cases because the application processes an audio that comes in as a buffer.
Same issue+1
stream | buffer
input?
Version information
Code to reproduce
Expected results
Related question: https://superuser.com/questions/980272/what-movflags-frag-keyframeempty-moov-flag-means
When encoding video with FFMPEG I am using -movflags frag_keyframe+empty_moov - I found it somewhere on the net - and it allows me to get mp4 video stream (without it I get Could not write header for output file #0 (incorrect codec parameters ?) error if I want to stream output somewhere, but it works if I pass output file name out.mp4 for example). I am asking because this flag also messes with my video somehow and I can't upload it to Twitter for example when using this flag (without it Twitter accepts my video). So it messes up with encoding/format or something else... is there any workaround? Output video has correct 27 seconds duration when open it in Android device or upload to check in https://www.metadata2go.com/view-metadata
Observed results
FFMPEG command
Duration is displayed as 0 second![CleanShot 2023-08-24 at 14 14 24](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/assets/41616812/5df534a4-6e7a-459e-8adc-3193ab5184a4)