0

Use Case

When a user records an audio file and uploads to firebase storage, run a trigger that crops a clip of that file and saves it to a "preview" directory.

Problem

When the file arrives on the server, it is just dead air before the start time (10 seconds) and then doesn't stop after the duration of 10 seconds is exceeded. Whatever I put in the "-t" and "-ss" arguments seems to have no impact on the output file - not cropping correctly.

Environment

  • mac client / firebase storage
  • node v8.1.0
  • ffmpeg v3.2.2
  • fluent-ffmpeg v2.1.2

Node Code

  var command = new ffmpeg({ source: tempFilePath, timeout: 0 })
      .setFfmpegPath(ffmpegPath)
      .setFfprobePath(ffprobePath)
      .inputOption('-t', '10')
      .inputOption('-ss', '10')
      .outputOption('-acodec', 'copy')
      .on('start', function(commandLine) {
            console.log('Spawned Ffmpeg with command: ', commandLine);
       })
      .on('end', function() {
          console.log('Preview file cropping done successfully');
       })
      .on('error', function(err, stdout, stderr) {
          var build = err;
          if (!stdout === '') { build = build + '\n' + stdout; }
          build = build + '\n' + stderr;

          console.log(build);
       }).save(tempFilePath);

Ffmpeg Command

Spawned Ffmpeg with command: ffmpeg -t 10 -i /tmp/2EB100B0-6C1E-4D51-9087-764CA653AFC720170711232034.aac -y -acodec aac /tmp/2EB100B0-6C1E-4D51-9087-764CA653AFC720170711232034.aac

Console Output

 $ ffmpeg -t 10 -i E506FE2E-DC81-4DD8-B751-211F7FD9A25820170816160502.aac -y -acodec aac output.aac -loglevel debug
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Volumes/Ramdisk/sw --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --enable-libgsm --enable-libvidstab --enable-libx265 --disable-doc --arch=x86_64 --enable-runtime-cpudetect
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Splitting the commandline.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '10'.
Reading option '-i' ... matched as input url with argument 'E506FE2E-DC81-4DD8-B751-211F7FD9A25820170816160502.aac'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'aac'.
Reading option 'output.aac' ... matched as output url.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url E506FE2E-DC81-4DD8-B751-211F7FD9A25820170816160502.aac.
Applying option t (record or transcode "duration" seconds of audio/video) with argument 10.
Successfully parsed a group of options.
Opening an input file: E506FE2E-DC81-4DD8-B751-211F7FD9A25820170816160502.aac.
[file @ 0x7fe42f700420] Setting default whitelist 'file,crypto'
[aac @ 0x7fe431000000] Format aac probed with size=2048 and score=51
[aac @ 0x7fe431000000] Before avformat_find_stream_info() pos: 0 bytes read:32928 seeks:4 nb_streams:1
[aac @ 0x7fe431000000] All info found
[aac @ 0x7fe431000000] Estimating duration from bitrate, this may be inaccurate
[aac @ 0x7fe431000000] After avformat_find_stream_info() pos: 37888 bytes read:98464 seeks:4 frames:50
Input #0, aac, from 'E506FE2E-DC81-4DD8-B751-211F7FD9A25820170816160502.aac':
  Duration: 00:01:24.28, bitrate: 335 kb/s
    Stream #0:0, 50, 1/28224000: Audio: aac (LC), 44100 Hz, stereo, fltp, 335 kb/s
Successfully opened the file.
Parsing a group of options: output url output.aac.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument aac.
Successfully parsed a group of options.
Opening an output file: output.aac.
[file @ 0x7fe42f7016e0] Setting default whitelist 'file,crypto'
Successfully opened the file.
detected 4 logical cores
[graph 0 input from stream 0:0 @ 0x7fe42f701880] Setting 'time_base' to value '1/44100'
[graph 0 input from stream 0:0 @ 0x7fe42f701880] Setting 'sample_rate' to value '44100'
[graph 0 input from stream 0:0 @ 0x7fe42f701880] Setting 'sample_fmt' to value 'fltp'
[graph 0 input from stream 0:0 @ 0x7fe42f701880] Setting 'channel_layout' to value '0x3'
[graph 0 input from stream 0:0 @ 0x7fe42f701880] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3
[audio format for output stream 0:0 @ 0x7fe42f702060] Setting 'sample_fmts' to value 'fltp'
[audio format for output stream 0:0 @ 0x7fe42f702060] Setting 'sample_rates' to value '96000|88200|64000|48000|44100|32000|24000|22050|16000|12000|11025|8000|7350'
[AVFilterGraph @ 0x7fe42f6101a0] query_formats: 5 queried, 12 merged, 0 already done, 0 delayed
Output #0, adts, to 'output.aac':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0, 0, 1/44100: Audio: aac (LC), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
    Metadata:
      encoder         : Lavc57.64.101 aac
Stream mapping:
  Stream #0:0 -> #0:0 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
    Last message repeated 1 times
[output stream 0:0 @ 0x7fe42f701ee0] EOF on sink link output stream 0:0:default.
No more output streams to write to, finishing.
[aac @ 0x7fe431001200] Trying to remove 344 more samples than there are in the queue
size=     160kB time=00:00:10.00 bitrate= 130.9kbits/s speed=20.2x    
video:0kB audio:157kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.881580%
Input file #0 (E506FE2E-DC81-4DD8-B751-211F7FD9A25820170816160502.aac):
  Input stream #0:0 (audio): 432 packets read (398208 bytes); 432 frames decoded (442368 samples); 
  Total: 432 packets (398208 bytes) demuxed
Output file #0 (output.aac):
  Output stream #0:0 (audio): 431 frames encoded (441000 samples); 432 packets muxed (160716 bytes); 
  Total: 432 packets (160716 bytes) muxed
432 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x7fe42f611040] Statistics: 0 seeks, 432 writeouts
[aac @ 0x7fe431001200] Qavg: 4508.253
[AVIOContext @ 0x7fe42f7004c0] Statistics: 458912 bytes read, 4 seeks
Peter
  • 5,251
  • 16
  • 63
  • 98
  • Show the new ffmpeg console output/log so we can see what you mean by it not cropping correctly. – llogan Aug 16 '17 at 16:47
  • Hi. Thanks for taking a look. Some more detail on what I mean by "not cropping correctly" can be seen here: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/issues/744 . Posted my local console output of the command run on firebase. Thanks again. – Peter Aug 16 '17 at 17:19
  • Have I provided enough information @LordNeckbeard? Any ideas where I might be going wrong? – Peter Aug 16 '17 at 20:15
  • Don't use the same file as input **and** output. – llogan Aug 17 '17 at 21:07

0 Answers0