为什么FFMPEG无法处理流?

发布于 2025-02-06 05:14:04 字数 1839 浏览 3 评论 0原文

我在FFMPEG媒体转换脚本上挣扎。
我正在使用 fluent-ffmpeg library 带有node.js 代码>。

我的应用程序应该接收流作为输入,使用FFMPEG调整大小,然后输出流。

但是,即使指定输入格式(-f ffmpeg的选项),我也绝对无法使用FFMPEG处理输入流。

但是,当在MP4文件上执行完全相同的FFMPEG命令(无扩展)时,它可以正常运行并正确地转换媒体!

工作代码(无流)

import * as ffmpeg from 'fluent-ffmpeg';

ffmpeg('myMp4File')
  .inputFormat('mp4')
  .audioCodec('aac')
  .videoCodec('libx264')
  .format('avi')
  .size('960x540')
  .save('mySmallAviFile');

失败代码(使用流),

import * as ffmpeg from 'fluent-ffmpeg';
import { createReadStream } from 'fs';

ffmpeg(createReadStream('myMp4File'))
  .inputFormat('mp4')
  .audioCodec('aac')
  .videoCodec('libx264')
  .format('avi')
  .size('960x540')
  .save('mySmallAviFile');

它生成以下FFMPEG的错误:

Error: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Conversion failed!

此错误明确表示FFMPEG无法识别输入格式,尽管有参数-f mp4

我阅读了FFMPEG男人的页面和页面,但我可以找到有关我的问题的任何相关信息。

信息

以下是命令的输出

[
  '-f',                'mp4',      
  '-i',                'pipe:0',       
  '-y',                '-acodec',   
  'aac',               '-vcodec',     
  'libx264',           '-filter:v',    
  'scale=w=960:h=540', '-f',
  'avi',               'mySmallAviFile'
]                                      

互补 0 -y -y -acodec'aac'-vcodec'libx264 -filter:v'scale = w = 960:h = 540'-f'avi'mysmallavifile

I am struggling on a ffmpeg media conversion script.
I am using fluent-ffmpeg library with node.js.

My app is supposed to receive a stream as input, resize it using ffmpeg, and then outputing a stream.

However, I am absolutely unable to process an input stream with ffmpeg, even when specifying the input format (-f ffmpeg's option).

However, when execuyting the exact same ffmpeg command on an mp4 file (without extension), it works and converts properly the media !

Working code (no stream)

import * as ffmpeg from 'fluent-ffmpeg';

ffmpeg('myMp4File')
  .inputFormat('mp4')
  .audioCodec('aac')
  .videoCodec('libx264')
  .format('avi')
  .size('960x540')
  .save('mySmallAviFile');

Failing code (using stream)

import * as ffmpeg from 'fluent-ffmpeg';
import { createReadStream } from 'fs';

ffmpeg(createReadStream('myMp4File'))
  .inputFormat('mp4')
  .audioCodec('aac')
  .videoCodec('libx264')
  .format('avi')
  .size('960x540')
  .save('mySmallAviFile');

It generates the following ffmpeg's error:

Error: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Conversion failed!

This error explicitely says that ffmpeg could not identify the input format, in despite of argument -f mp4.

I read pages and pages of ffmpeg's man but I could find any relevant information concerining my issue.

Complementary information

Here is the output of command._getArguments(), showing the full ffmpeg command baked by the library:

[
  '-f',                'mp4',      
  '-i',                'pipe:0',       
  '-y',                '-acodec',   
  'aac',               '-vcodec',     
  'libx264',           '-filter:v',    
  'scale=w=960:h=540', '-f',
  'avi',               'mySmallAviFile'
]                                      

So the full ffmpeg command is the following:

ffmpeg -f mp4 -i pipe:0 -y -acodec 'aac' -vcodec 'libx264 -filter:v 'scale=w=960:h=540' -f 'avi' mySmallAviFile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2025-02-13 05:14:04

我遇到了相同的错误,但仅适用于文件末尾的MOOV atom元数据。
mov atom移动到文件的开头之后。
ffmpeg -i input.mp4 -movflags fastStart out.mp4
错误消失了。

I was getting the same error but only for files which had moov atom metadata at the end of a file.
After moving mov atom to the beginning of the file with:
ffmpeg -i input.mp4 -movflags faststart out.mp4
the error dissapeared.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文