Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream input doesn't work with .ogg audio file #1309

Open
3 tasks done
biigpongsatorn opened this issue Nov 26, 2024 · 2 comments
Open
3 tasks done

Stream input doesn't work with .ogg audio file #1309

biigpongsatorn opened this issue Nov 26, 2024 · 2 comments

Comments

@biigpongsatorn
Copy link

biigpongsatorn commented Nov 26, 2024

Version information

  • fluent-ffmpeg version: 2.1.3
  • ffmpeg version: 7.1
  • OS: Mac OS

Code to reproduce

// This doesn't work
const inputReadStream = fs.createReadStream(`input.ogg`);
const outputWriteStream = fs.createWriteStream(`output.ogg`);

ffmpeg(inputReadStream)
   .inputFormat("ogg")
   .setStartTime(400)
   .outputFormat("ogg")
   .on("start", () => {
      console.log("Processing....");
   })
   .on("error", (err: any) => {
      console.error("An error occurred: " + err.message);
   })
   .on("end", () => {
      console.log("Processing finished !");
   })
   .pipe(outputWriteStream, { end: false });

// This works!
const outputWriteStream = fs.createWriteStream(`output.ogg`);

ffmpeg("input.ogg")
   .inputFormat("ogg")
   .setStartTime(400)
   .outputFormat("ogg")
   .on("start", () => {
      console.log("Processing....");
   })
   .on("error", (err: any) => {
      console.error("An error occurred: " + err.message);
   })
   .on("end", () => {
      console.log("Processing finished !");
   })
   .pipe(outputWriteStream, { end: false });

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results & Observed results

I want to trim the audio starting from 400 seconds to the end. It seems that FFmpeg does not work when using an input stream, but it functions properly with an input file path. It's strange that it can cut the audio by a few seconds (like 3-4 seconds) but not by 400 seconds and no errors appear.

Here's the result
With stream:
input.ogg
image

output.ogg (4 seconds was cut)
image

Without stream:
input.ogg
image

output.ogg (Cut correctly)
image

PS.

This is an example code to reproduce the bug. In my use case, I need to read the input file from AWS S3, then pass it to FFMPEG to cut the audio before uploading it again.

So, It's important to give an input as a stream input to FFMPEG.

Checklist

  • I have read the FAQ
  • I tried the same with command line ffmpeg and it works correctly (hint: if the problem also happens this way, this is an ffmpeg problem and you're not reporting it to the right place)
  • I have included full stderr/stdout output from ffmpeg
@biigpongsatorn
Copy link
Author

biigpongsatorn commented Nov 26, 2024

I've tried with .wav file and It works! I think it just happen with .ogg

    const inputReadStream = fs.createReadStream(`input.wav`);
    const outputWriteStream = fs.createWriteStream(`output.wav`);

    ffmpeg(inputReadStream)
      .inputFormat("wav")
      .setStartTime(400)
      .outputFormat("wav")
      .on("start", () => {
        console.log("Processing....");
      })
      .on("error", (err: any) => {
        console.error("An error occurred: " + err.message);
      })
      .on("end", () => {
        console.log("Processing finished !");
      })
      .pipe(outputWriteStream, { end: false });

Results

Input:
image

Output:
image

Btw, my audio is 2 channels.

@biigpongsatorn
Copy link
Author

biigpongsatorn commented Nov 26, 2024

The log from using this ffmpeg command

 ffmpeg -ss 400 -i ./input.ogg ./output.ogg

Log

ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers
  built with Apple clang version 16.0.0 (clang-1600.0.26.4)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.1_3 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
  libavutil      59. 39.100 / 59. 39.100
  libavcodec     61. 19.100 / 61. 19.100
  libavformat    61.  7.100 / 61.  7.100
  libavdevice    61.  3.100 / 61.  3.100
  libavfilter    10.  4.100 / 10.  4.100
  libswscale      8.  3.100 /  8.  3.100
  libswresample   5.  3.100 /  5.  3.100
  libpostproc    58.  3.100 / 58.  3.100
Input #0, ogg, from './input.ogg':
  Duration: 00:08:43.72, start: 0.000000, bitrate: 20 kb/s
  Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
Stream mapping:
  Stream #0:0 -> #0:0 (opus (native) -> vorbis (libvorbis))
Press [q] to stop, [?] for help
Output #0, ogg, to './output.ogg':
  Metadata:
    encoder         : Lavf61.7.100
  Stream #0:0: Audio: vorbis, 48000 Hz, stereo, fltp
      Metadata:
        encoder         : Lavc61.19.100 libvorbis
[opus @ 0x153e08100] Error parsing the packet header./s speed= 111x
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Invalid data found when processing input
[opus @ 0x153e08100] Error parsing the packet header.
[opus @ 0x153e08100] Too many errors when draining, this is a bug. Stop draining and force EOF.
[aist#0:0/opus @ 0x153e05de0] [dec:opus @ 0x153e07b20] Decoding error: Internal bug, should not have happened
[out#0/ogg @ 0x60000374c3c0] video:0KiB audio:1057KiB subtitle:0KiB other streams:0KiB global headers:4KiB muxing overhead: 1.233056%
size=    1070KiB time=00:02:03.71 bitrate=  70.8kbits/s speed= 111x

Seems like it has errors but the audio was trimmed correctly.
input:
image

output:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant