converting of wma to mp3 through ffmpeg is not working - audio

I want to convert my wma file to mp3 by ffmpeg .
why this error is coming what should i do ? i installed libmp3lame already .
when i am trying to convert by following command gives error :
/var/www/yapi$ sudo /usr/local/bin/ffmpeg -i uploads/4e02dc4f197c1.wma uploads/4e02dc4f1b212.mp3
ffmpeg version N-30971-g4b87a08, Copyright (c) 2000-2011 the FFmpeg developers
built on Jun 23 2011 10:08:49 with gcc 4.4.5
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-x11grab
libavutil 51. 9. 1 / 51. 9. 1
libavcodec 53. 7. 0 / 53. 7. 0
libavformat 53. 4. 0 / 53. 4. 0
libavdevice 53. 1. 1 / 53. 1. 1
libavfilter 2. 23. 0 / 2. 23. 0
libswscale 2. 0. 0 / 2. 0. 0
libpostproc 51. 2. 0 / 51. 2. 0
Input #0, asf, from 'uploads/4e02dc4f197c1.wma':
Metadata:
title : "Highway Blues"
artist : Marc Seales, composer. New Stories. Ernie Watts, saxophone.
genre : Jazz
album : Speakin' Out
track : 1
WM/Year : 1999
WMFSDKVersion : 8.00.00.4389
WMFSDKNeeded : 0.0.0.0000
Duration: 00:01:33.71, start: 0.000000, bitrate: 64 kb/s
Stream #0.0: Audio: wmav2, 44100 Hz, 2 channels, s16, 64 kb/s
File 'uploads/4e02dc4f1b212.mp3' already exists. Overwrite ? [y/N] y
Output #0, mp3, to 'uploads/4e02dc4f1b212.mp3':
Stream #0.0: Audio: [0][0][0][0] / 0x0000, 44100 Hz, 2 channels, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Encoder (codec id 86017) not found for output stream #0.0
why it is not working ?

You may have installed libmp3lame, but according to
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-x11grab
ffmpeg wasn't built against it. Re-configure and -build ffmpeg, making sure that it knows where to find libmp3lame.

Related

Concatenate audio with image and video using ffmpeg

I have 1 image, 1 audio file and 1 video. I would like to merge all of them to make a video which will
show the image and play audio file for the first 10s
play the video file
here is what I was trying to do so far.
ffmpeg \
-loop 1 -framerate 24 -t 10 -i item1.jpg \
-i "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/Music/66/58/f7/mzi.eoocfriy.aac.p.m4a" \
-i item4.mp4 \
-filter_complex \
"[0]scale=432:432,setdar=1[img1]; \
[1]volume=1[aud1]; \
[2]scale=432:432,setdar=1[vid1]; \
[img1][aud1][vid1] concat=n=3:v=1:a=1" \
outputfile.mp4
I got the error:
[Parsed_setdar_4 # 0x3063780] Media type mismatch between the
'Parsed_setdar_4' filter output pad 0 (video) and the
'Parsed_concat_6' filter input pad 1 (audio) [AVFilterGraph #
0x30479a0] Cannot create the link setdar:0 -> concat:1 Error
initializing complex filters. Invalid argument
I tried to googled but still cannot figure out what I am doing wrong?
Updated:
I ran the following command:
ffmpeg \
-loop 1 -framerate 24 -t 10 -i item1.jpg \
-t 10 -i "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/Music/66/58/f7/mzi.eoocfriy.aac.p.m4a" \
-i item4.mp4 \
-f lavfi -t 1 -i anullsrc \
-filter_complex \
"[0]scale=432:432,setsar=1[img1]; \
[2]scale=432:432,setsar=1[vid1]; \
[img1][1][vid1][3] concat=n=2:v=1:a=1" \
outputfile.mp4
and got the following error:
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libavresample 3. 5. 0 / 3. 5. 0
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, image2, from 'item1.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 8365 kb/s
Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 432x432 [SAR 1:1 DAR 1:1], 24 fps, 24 tbr, 24 tbn, 24 tbc
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/Music/66/58/f7/mzi.eoocfriy.aac.p.m4a':
Metadata:
major_brand : M4A
minor_version : 0
compatible_brands: M4A mp42isom
creation_time : 1983-06-16T23:20:44.000000Z
iTunSMPB : 00000000 00000840 00000000 00000000001423C0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Duration: 00:00:29.98, start: 0.047891, bitrate: 285 kb/s
Stream #1:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 271 kb/s (default)
Metadata:
creation_time : 1983-06-16T23:20:44.000000Z
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'item4.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 1970-01-01T00:00:00.000000Z
encoder : Lavf53.24.2
Duration: 00:00:13.70, start: 0.000000, bitrate: 615 kb/s
Stream #2:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 229 kb/s, 15 fps, 15 tbr, 15360 tbn, 30 tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:00.000000Z
handler_name : VideoHandler
Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 382 kb/s (default)
Metadata:
creation_time : 1970-01-01T00:00:00.000000Z
handler_name : SoundHandler
Input #3, lavfi, from 'anullsrc':
Duration: N/A, start: 0.000000, bitrate: 705 kb/s
Stream #3:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
[AVFilterGraph # 0x3955e20] No such filter: ' '
Error initializing complex filters.
Invalid argument
When concatting paired streams, for each segment, the concat filter expects a corresponding pair of inputs. So, if you are concatting 1 video and 2 audio streams, each segment input should be [v][a][a].
So, in this case, a dummy audio is required to pair with the 2nd video.
ffmpeg \
-loop 1 -framerate 24 -t 10 -i item1.jpg \
-t 10 -i "https://audio-ssl.itunes.apple.com/apple-assets-us-std-000001/Music/66/58/f7/mzi.eoocfriy.aac.p.m4a" \
-i item4.mp4 \
-f lavfi -t 1 -i anullsrc \
-filter_complex \
"[0]scale=432:432,setsar=1[img1]; \
[2]scale=432:432,setsar=1[vid1]; \
[img1][1][vid1][3] concat=n=2:v=1:a=1" \
outputfile.mp4
The anullsrc provides the dummy audio.
The intro audio has to be limited to the image duration, since the concat filter uses the duration of the longer stream in each segment.
Use setsar not setdar since SAR is the actual parameter that is changed and it's possible that after reduction to a rational number, the SARs may not match.
n in concat should be 2 since it specifies the number of paired segments, not total number of inputs.

ffmpeg : Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

I'm experiencing troubles running ffmpeg on my synology. I'm trying to convert .avi video to mp4.
Here is the command :
ffmpeg -i vid20160623.avi -acodec libfaac -b:a 128k -vcodec mpeg4 -b:v 1200k -flags +aic+mv4 -f mp4 vid20160623.mp4
And the logs :
ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.3 (crosstool-NG 1.20.0) 20150311 (prerelease)
configuration: --prefix=/usr --incdir='${prefix}/include/ffmpeg' --arch=arm --target-os=linux --cross-prefix=/usr/local/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi- --enable-cross-compile --enable-optimizations --enable-pic --enable-gpl --enable-shared --disable-static --enable-version3 --enable-nonfree --enable-libfaac --enable-encoders --enable-pthreads --disable-bzlib --disable-protocol=rtp --disable-muxer=image2 --disable-muxer=image2pipe --disable-swscale-alpha --disable-ffserver --disable-ffplay --disable-devices --disable-bzlib --disable-altivec --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --disable-vaapi --disable-decoder=amrnb --disable-encoder=zmbv --disable-encoder=dca --disable-encoder=ac3 --disable-encoder=ac3_fixed --disable-encoder=eac3 --disable-decoder=dca --disable-decoder=eac3 --disable-decoder=truehd --cc=/usr/local/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-ccache-gcc
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, avi, from 'vid20160623.avi':
Metadata:
encoder : MEncoder git-ab94fc6-4.4.3
Duration: 00:20:18.07, start: 0.000000, bitrate: 1197 kb/s
Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 624x352 [SAR 1:1 DAR 39:22], 1056 kb/s, 25 fps, 23.98 tbr, 25 tbn, 23.98 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 128 kb/s
Output #0, mp4, to vid20160623.mp4':
Metadata:
encoder : MEncoder git-ab94fc6-4.4.3
Stream #0:0: Video: mpeg4, none, q=2-31, 128 kb/s, SAR 351:352 DAR 0:0, 23.98 fps
Metadata:
encoder : Lavc56.41.100 mpeg4
Stream #0:1: Audio: aac, 0 channels, 128 kb/s
Metadata:
encoder : Lavc56.41.100 libfaac
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
Stream #0:1 -> #0:1 (mp3 (native) -> aac (libfaac))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
I tried to reduce b:a and b:v but it did not work.
Any help will be welcome.
Looks like the encoder is not recognizing the resolution of the output stream. Also, the codec frame rate is different than the actual frame rate. Try,
ffmpeg -i vid20160623.avi -acodec libfaac -b:a 128k -vf "scale=624:352,setsar=1" -vcodec mpeg4 -r 25 -b:v 1200k -flags +aic+mv4 -f mp4 vid20160623.mp4
Maybe a late answer but as I looked for a while for the same reason...
The issue is not in your command line but in FFmpeg version itself!
You asked for 1200k bit rate but we can see in output->Stream 0:0, it would try 128kb/s!
I have just used same command line with FFMpeg 2.8.11 and it works like a charm!

"Amix" and "adelay" combined leads to "Error while filtering: Cannot allocate memory"

I was trying to add to audio clips together (using amix) while delaying one of them (with adelay). I used the following command
ffmpeg -i org/onclassical_demo_luisi_chopin_scherzo_2_31_small-version_ii-ending.wav \
-i org/all_u_had_2_say.wav -filter_complex \
"[1]adelay=1000[del1];[0][del1]amix" out.wav
and get the following output
ffmpeg version N-77387-g9d38f06 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --enable-libmp3lame --enable-gpl --enable-libx264 --enable-libx265
libavutil 55. 11.100 / 55. 11.100
libavcodec 57. 18.100 / 57. 18.100
libavformat 57. 20.100 / 57. 20.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 21.100 / 6. 21.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from 'org/onclassical_demo_luisi_chopin_scherzo_2_31_small-version_ii-ending.wav':
Duration: 00:02:18.26, bitrate: 1411 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
Guessed Channel Layout for Input Stream #1.0 : mono
Input #1, wav, from 'org/all_u_had_2_say.wav':
Duration: 00:00:03.85, bitrate: 88 kb/s
Stream #1:0: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 11025 Hz, 1 channels, u8, 88 kb/s
Output #0, wav, to 'out.wav':
Metadata:
ISFT : Lavf57.20.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 11025 Hz, mono, s16, 176 kb/s (default)
Metadata:
encoder : Lavc57.18.100 pcm_s16le
Stream mapping:
Stream #0:0 (pcm_s16le) -> amix:input0
Stream #1:0 (pcm_u8) -> adelay
amix -> Stream #0:0 (pcm_s16le)
Press [q] to stop, [?] for help
Error while filtering: Cannot allocate memory
size= 83kB time=00:00:03.85 bitrate= 176.6kbits/s speed= 213x
video:0kB audio:83kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.091808%
Maybe there is some incompatibility between the streams (pcm_s16le, 44100 Hz, 2 channels vs. pcm_u8, 11025 Hz, 1 channel) that need to be handled first, but running only amix works so that doesn't actually seem to be the case.
Try new build. Or the command below with the current one:
ffmpeg -i org/onclassical_demo_luisi_chopin_scherzo_2_31_small-version_ii-ending.wav \
-i org/all_u_had_2_say.wav -filter_complex \
"[0]aresample=48000,aformat=fltp[a];
[1]aresample=48000,aformat=fltp,asetpts=PTS+(1.000/TB)[del1]; \
[a][del1]amix" out.wav

FFMPEG - Get the exact calculated audio filesize after encode

Im trying to guess an audio (mp3) filesize before encode with ffmpeg, afterward, need to have the exact calculated filesize.
Here is the formula im using to predict and calculate the filesize (hope im not wrong) :
( Bitrates x Duration ) / 8) x 1000 = Filesize in Bytes.
Im going to give a real example so that everyone can understand the use case.
Example :
Having an m4a file with the following data :
Name : Assuming xxx.m4a
Filesize : 8 304 014 bytes (8,3 Mo)
Bitrates : 256k
Duration : 260 seconds
Expected filesize : ( (256 x 260) / 8 ) x 1000 = 8 320 000 bytes
Then im running the following ffmpeg command :
ffmpeg -i xxx.m4a -f mp3 -y -minrate 256k -maxrate 256k -bufsize 256k -b:a 256k -fs 8320000 output.mp3
Console output :
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'xxx.m4a':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf56.36.100
Duration: 00:04:20.53, start: 0.000000, bitrate: 254 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 253 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, mp3, to 'output.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
TSSE : Lavf56.36.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 256 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc56.41.100 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
size= 8127kB time=00:04:20.02 bitrate= 256.1kbits/s
video:0kB audio:8127kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.011765%
Problem and Questions :
Can you tell me why im I getting an output with 8 322 546 bytes and
not 8 320 000 as expected ?
Is there something wrong in my formula or the ffmpeg command ?
What solution can you suggest to get the exact predicted filesize ?
Thank you in advance.
Besides the muxing overhead inherent in the container, MP3 audio is stored in frames. And each frame has fixed number of 1152 samples. The encoder will output full frames so for an output sampling rate of 44100, the closest to 260 seconds is
ceiling of (260 x 44100/1152) = 9954 frames = ~260.02285 seconds.
This throws your calculation, by itself, off balance, even if the encoding assumptions were right.
Even then, the bit reservoir may come into play.
Edit:
You can drop the bitrate and add silent padding, but this too isn't precise as muxing overhead comes into play
ffmpeg -i xxx.m4a -f lavfi -t 5 -i anullsrc -lavfi "[0:a][1:a]concat=n=2:v=0:a=1" -f mp3 -y -minrate 224k -maxrate 224k -bufsize 224k -b:a 224k -fs N output.mp3
Here, the fs should be calculated as per MP3 + 5 seconds duration.

ffmpeg - when merging an image and audio, audio gets shortened

I am trying to merge a png image with 11 seconds of audio and create an mp4 file. When I execute ffmpeg I end up with a total duration of 10 seconds for the mp4 file. The command I'm using is...
ffmpeg -r 6 -loop 1 -i "image1.png" -i "audio1.wav" out.mp4
UPDATE: Here is the log that is produced...
FFmpeg version SVN-r15986, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --extra-cflags=-fno-common --enable-memalign-hack --enable-pthr
eads --enable-libmp3lame --enable-libxvid --enable-libvorbis --enable-libtheora
--enable-libspeex --enable-libfaac --enable-libgsm --enable-libx264 --enable-lib
schroedinger --enable-avisynth --enable-swscale --enable-gpl
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 6. 0 / 52. 6. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
libswscale 0. 6. 1 / 0. 6. 1
built on Dec 3 2008 01:59:37, gcc: 4.2.4
Input #0, image2, from 'image1.png':
Duration: 00:00:00.16, start: 0.000000, bitrate: N/A
Stream #0.0: Video: png, rgb32, 400x300, 6.00 tb(r)
Input #1, wav, from 'audio1.wav':
Duration: 00:00:11.07, bitrate: 88 kb/s
Stream #1.0: Audio: pcm_u8, 11025 Hz, mono, s16, 88 kb/s
File 'out.mp4' already exists. Overwrite ? [y/N] y
Output #0, mp4, to 'out.mp4':
Stream #0.0: Video: mpeg4, yuv420p, 400x300, q=2-31, 200 kb/s, 6.00 tb(c)
Stream #0.1: Audio: libfaac, 11025 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Press [q] to stop encoding
frame= 1 fps= 0 q=4.1 Lsize= 42kB time=0.17 bitrate=2063.7kbits/s
video:14kB audio:26kB global headers:0.kB muxing overhead 4.894235%
I have also tried using
ffmpeg -loop 1 -i "image1.png" -i "audio1.wav" -t 11 out.mp4
This command does create an mp4 of 11 seconds but the audio is still cut off at 10 seconds.
Why is the audio being cutoff at 10 seconds?
Thanks,
Gary
One possible thing is that your audio file is just 10 seconds long.
Are you sure you are losing a whole second of the audio? Maybe it is just a few miliseconds which could cause some rounding issues? You can check this by running
ffprobe "audio1.wav"
and then
ffprobe "out.mp4"
Adding some options of codec/bitrate (e.g. -c:a copy -b:a copy) might help

Resources