0

I have a video file and its properties are as the following when I check via the ffprobe command; My purpose is to take the audio file only and its size should not be >100mb. Is there any proper way of doing it in an NPM project?

ffprobe 2.webm
ffprobe version N-86175-g64ea4d1 Copyright (c) 2007-2017 the FFmpeg 
developers built with gcc 6.3.0 (GCC)   configuration: --enable-gpl -- 
nable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 
--
nable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable- 
ontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --
 nable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype -- 
nable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-
ibmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-
ibopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-
ibsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-
ibtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --
nable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
ibx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --
nable-zlib   libavutil      55. 63.100 / 55. 63.100   libavcodec     57. 
96.101   
7. 96.101
libavformat    57. 72.101 / 57. 72.101
libavdevice    57.  7.100 / 57.  7.100
libavfilter     6. 90.100 /  6. 90.100
libswscale      4.  7.101 /  4.  7.101
libswresample   2.  8.100 /  2.  8.100
libpostproc    54.  6.100 / 54.  6.100
Input #0, matroska,webm, from '2.webm':
 Metadata:
  encoder         : libwebm-0.2.1.0
  creation_time   : 2017-05-04T14:59:01.639000Z
 Duration: 00:02:35.16, start: 0.000000, bitrate: 32 kb/s
Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
Stream #0:1(eng): Video: vp8, yuv420p(progressive), 640x480, SAR 1:1 DAR 
4:3, 14.99 tbr, 1k tbn, 1k tbc (default)
shamaleyte
  • 1,882
  • 3
  • 21
  • 38

1 Answers1

2

Using fluent-ffmpeg's API

You could use the noVideo() method which tells ffmpeg to produce output with "no video".

ffmpeg('/path/to/file.avi').noVideo();

Using ffmpeg's CLI API

I'm not sure of fluent-ffmpeg, but using ffmpeg, you would use the -map option to dictate what streams you want from you inputs in your output. So for your example, the command to get an MP3 file that contains only the first audio stream from your input would be:

ffmpeg -i 2.webm -map 0:a:0 out.mp3

Alternatively, you could tell ffmpeg to not include video streams using the -vn option; but I like to be explicit. Your command would then be:

ffmpeg -i 2.webm -vn out.mp3

You can also use the -acodec option to dictate what encoder you want to use such as AAC or whatever. ffmpeg will use the best guess by looking at the extension you gave your output if you don't give it enough options.

As to limiting filesize, I'm not sure of a clean way to do that, but this question on the Video Production StackExchange may help: How to limit file size with ffmpeg?. It suggests playing with your bitrate until you get the size you want. I would assume you could calculate correct bitrate ahead of time.

zero298
  • 25,467
  • 10
  • 75
  • 100
  • I do get the following error; how do you think I can overcome it? (My ffmpeg lib. is updated); [opus @ 00000000006a59c0] LBRR frames is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented. [opus @ 00000000006a59c0] Error decoding a SILK frame. [opus @ 00000000006a59c0] Error decoding an Opus frame. – shamaleyte Jul 03 '17 at 17:02
  • 1
    @shamaleyte Try forcing **de**coding using libopus: `ffmpeg -acodec libopus -i input.webm -vn -acodec mp3 output.mp3`. See this issue on ffmpeg's GitHub: [Support for ffmpeg/avconv input parameters](ffmpeg -acodec libopus -i input.webm -vn -acodec mp3 output.mp3). – zero298 Jul 03 '17 at 17:06
  • it works but from the command line using ffmpeg just like your command. But is there any way of running that inside an NPM project? Pretty important to me. I checked the Github issue as well, but not sure how to adjust that "AudioSegment.from_file" part in Node project. I will accept this answer of yours but I really appreciate your further help! Thanks in advance. Please check this ticket as well : https://stackoverflow.com/questions/44723558/how-to-use-codec-type-properly-in-npm – shamaleyte Jul 03 '17 at 17:24
  • @shamaleyte Not sure if checking the audio size is really an issue, since at 32 kBit/s, you can fit seven hours worth of audio into 100 MB. (That is, if you really meant MB and not MBit.) – slhck Jul 03 '17 at 17:26
  • @slhck , the produced video is an output of Webrtc platform. I need to make sure that the result is well produced (without any missing frame) and smaller than 100 MB (not MBit) . Thanks for your further help! can you also take a look at it? https://stackoverflow.com/questions/44723558/how-to-use-codec-type-properly-in-npm – shamaleyte Jul 03 '17 at 17:29
  • 1
    @shamaleyte Take a look at my edit, there is a way to tell fluent to not include video through its own API. – zero298 Jul 03 '17 at 17:56