Wrong Bitrate after ffmpeg WAV to MP3 Conversion - audio

I converted a WAV file to MP3. ffmpeg's output states that it's being converted into 128k bitrate, but it ends up with only 32k bitrate.
# ffmpeg -i 3.28.09.WAV -acodec libmp3lame -ab 128k 3.28.09.mp3
ffmpeg version 0.8.6-6:0.8.6-1, Copyright (c) 2000-2013 the Libav developers
built on Mar 24 2013 07:20:17 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[wav # 0x954f800] max_analyze_duration reached
Input #0, wav, from '3.28.09.WAV':
Duration: 00:27:07.47, bitrate: 2304 kb/s
Stream #0.0: Audio: pcm_s24le, 48000 Hz, 2 channels, s32, 2304 kb/s
Incompatible sample format 's32' for codec 'libmp3lame', auto-selecting format 's16'
Output #0, mp3, to '3.28.09.mp3':
Metadata:
TSSE : Lavf53.21.1
Stream #0.0: Audio: libmp3lame, 48000 Hz, 2 channels, s16, 128 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
size= 25430kB time=1627.51 bitrate= 128.0kbits/s
video:0kB audio:25430kB global headers:0kB muxing overhead 0.000495%
The original WAV file is RIFF (little-endian) data, WAVE audio, Microsoft PCM, 24 bit, stereo 48000 Hz.
The output MP3 file is an audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 32 kbps, 48 kHz, Stereo when inspected with the file utility. My PHP library getID3 also state.
# ffmpeg -i 3.28.09.mp3
ffmpeg version 0.8.6-6:0.8.6-1, Copyright (c) 2000-2013 the Libav developers
built on Mar 24 2013 07:20:17 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[mp3 # 0x8f56800] max_analyze_duration reached
Input #0, mp3, from '3.28.09.mp3':
Metadata:
encoder : Lavf53.21.1
Duration: 00:27:07.51, start: 0.000000, bitrate: 128 kb/s
Stream #0.0: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s
At least one output file must be specified
Any ideas what I might be missing here?

It turned out that the ffmpeg version I was using, installed via Debian packet manager:
version 0.8.6-6:0.8.6-1
Copyright (c) 2000-2013 the Libav developers
built on Mar 24 2013 07:20:17 with gcc 4.7.2
Locally I just upgraded to the latest version via Homebrew:
version 2.5.4
Copyright (c) 2000-2015 the FFmpeg developers
built on Feb 15 2015 20:17:10 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)

Related

Multichannel AAC mp4 encoding using libav (avconv) or ffmpeg

I am trying to create a four-channel mp4 file with AAC encoding for ambisonics use. I am trying to encode a 4-channel first-order ambisonic wav file into AAC like so:
avconv -i four_channel_input.wav -c:a libfaac -ac 4 four_channel_output.mp4
This gives me the error
[libfaac # 0x7f938885a000] Specified channel_layout is not supported
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Removing the -ac 4 option gives me a 5 channel file
Duration: 00:01:21.09, start: 0.021333, bitrate: 218 kb/s
Stream #0:0(und): Audio: aac (LC) [mp4a / 0x6134706D]
48000 Hz, 5.0, fltp, 215 kb/s (default)
with a blank first channel, which is obviously suboptimal. In order to create compressed ambisonics files, should I be using a separate format like AmbiX (even though I believe this is uncompressed)?
With ffmpeg, you can run
ffmpeg -i input.wav -c:a aac -ac 4 -channel_layout 4.0 four_channel_output.mp4

Fluent-ffmpeg "not a suitable output format"

I'm using the fluent-ffmpeg module for Node.js to convert audio files. I have a .mp3 file that I'd like to convert to .wma
Here's what that looks like:
var proc = new ffmpeg({
source: 'file.mp3',
nolog: false
}).toFormat('wma')
.saveToFile('file.wma', function(stdout, stderr)
{
console.log(stderr);
});
Unfortunately, I get the error:
Requested output format 'wma' is not a suitable output format
This is the entire error log:
ffmpeg version 0.8.9-4:0.8.9-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
built on Nov 9 2013 19:25:10 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
Input #0, mp3, from 'song_downloads/You Suffer.mp3':
Metadata:
title : You Suffer
artist : Napalm Death
album : Scum
genre : Death Metal
track : 12
date : 1987
Duration: 00:00:04.98, start: 0.000000, bitrate: 381 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 193 kb/s
Requested output format 'wma' is not a suitable output format
I know this isn't an ffmpeg issue because
ffmpeg -i file.mp3 file.wma
Works fine. Any ideas?
I think, wma is not a container format. It is an audio codec. WMA file is most commonly contained in ASF (Advanced Systems Format) format. So choose the correct options as given in the fluent-ffmpeg API to set codec and the format. You can run these commands:
ffmpeg -formats to see all formats and
ffmpeg -codecs to see all supported codecs
this worked for me fine
fluent_ffmpeg('input.mp3').audioCodec("aac").save('output.aac')
when formats was:
D aac raw ADTS AAC (Advanced Audio Coding)
not E = Muxing supported

FFmpeg inaccurate outputs [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
ffmpeg: videos before and after conversion aren't the same length
Recently, I've been trying to use FFmpeg for an application which requires a VERY accurate manipulation when it comes to the time parameter (milliseconds resolution). Unfortunately, I was surprised to find out that FFmpeg's manipulation functionalities return some inaccurate results.
Here is the output of 'ffmpeg':
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
built on Jul 25 2012 19:55:05 with gcc 4.2.1 (Apple Inc. build 5664)
configuration: --enable-gpl --enable-shared --enable-pthreads --enable-libx264 --enable-libmp3lame
libavutil 51. 54.100 / 51. 54.100
libavcodec 54. 23.100 / 54. 23.100
libavformat 54. 6.100 / 54. 6.100
libavdevice 54. 0.100 / 54. 0.100
libavfilter 2. 77.100 / 2. 77.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
Now, let's assume I want to rip the audio track of 'foo.mov'. Here is the relevant output of 'ffmpeg -i foo.mov':
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'foo.mov':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2012-07-24 23:16:08
Duration: 00:00:40.38, start: 0.000000, bitrate: 805 kb/s
Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x360, 733 kb/s, 24.46 fps, 29.97 tbr, 600 tbn, 1200 tbc
Metadata:
rotate : 90
creation_time : 2012-07-24 23:16:08
handler_name : Core Media Data Handler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, s16, 63 kb/s
Metadata:
creation_time : 2012-07-24 23:16:08
handler_name : Core Media Data Handler
As you probably noticed, the video file duration is 00:00:40.38. Using the following command, I ripped it's audio track:
'ffmpeg -i foo.mov foo.wav'
Output:
Output #0, wav, to 'foo.wav':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2012-07-24 23:16:08
encoder : Lavf54.6.100
Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Metadata:
creation_time : 2012-07-24 23:16:08
handler_name : Core Media Data Handler
Stream mapping:
Stream #0:1 -> #0:0 (aac -> pcm_s16le)
Press [q] to stop, [?] for help
size=3482kB time=00:00:40.42 bitrate= 705.6kbits/s
video:0kB audio:3482kB global headers:0kB muxing overhead 0.001290%
As you can see, the output file is longer than the file in the input.
Another example is audio (and video) file trimming:
Let's assume I would like to use ffmpeg for audio file trimming. I used the next command:
'ffmpeg -t 00:00:10.000 -i foo.wav trimmed_foo.wav -ss 00:00:25.000'
Output:
[wav # 0x10180e800] max_analyze_duration 5000000 reached at 5015510
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, wav, from 'foo.wav':
Duration: 00:00:40.42, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Output #0, wav, to 'trimmed_foo.wav':
Metadata:
encoder : Lavf54.6.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le -> pcm_s16le)
Press [q] to stop, [?] for help
size=864kB time=00:00:10.03 bitrate= 705.6kbits/s
video:0kB audio:864kB global headers:0kB muxing overhead 0.005199%
Again, the output file is 30 milliseconds longer than I expected.
I tried, for a long time, to research the issue without any success. When I use audacity for the same functionality, it does it very accurately!
Does anyone have any idea how to solve this problem?
TL; DR: FFmpeg and your iOS device are the wrong tools for your needs.
There are a host of problems to cover, so in no particular order:
Neither FFmpeg or the underlying codecs that you're working with are designed for the sort of time resolution you want. 40ms is 1 frame at 25fps, which just isn't much in the context of most video and audio files. Hyperaccurate timing isn't a design feature of common audio codecs, like your source AAC data, and FFmpeg follows suit.
Don't do any transcoding! If you want to change the data as little as possible... don't change it. You can use ffmpeg -i in.mov -c:a copy out.m4a to extract the audio stream exactly instead of transcoding it to wav format.
Use FFprobe instead of FFmpeg to get file information. FFmpeg just gives some cursory information about input and output files because its default logging is overly verbose. FFprobe is usually bundled with FFmpeg and is specifically designed to extract information in a convenient form. Use ffprobe -show_streams -show_format in.mov to get information.
Increase your -analyzeduration! You might've noticed the note about max_analyze_duration reached in your output. From the docs that's how many microseconds are going to actually be read of the file before FFmpeg estimates the total length. Again, for most purposes knowing the length of the file to microsecond accuracy isn't feasible or desirable and it is expensive. If you want hyperaccuracy, make sure that that parameter is set much higher, probably longer than your actual input.
Be a bit more careful with your option placement. This is fairly minor, but I thought that I should bring it up in case you're unaware. Many of FFmpeg's options behave differently depending on the order they're given with respect to input and output. Notably -ss that you're using. You have it after the input, which is where you want it, but you also have the output-only option -t at the beginning which is... weird. The more natural way to order that command would be:
ffmpeg -i foo.wav -ss 00:00:25.000 -t 00:00:10.000 trimmed_foo.wav
All the timing commands accept input in seconds (including fractional seconds), so you don't have to prepend everything with 00:00:.
Distinguish container length and actual stream length. I don't use Audacity, but I wouldn't be surprised if it showed extreme accuracy because it was lying to you about what it was doing. Actually trimming audio or video data with millisecond accuracy would require not merely choosing which frames from the input are included in the output (which is accurate to 40ms at 25fps!) but changing frame data to insert silence at the end. Far easier would be to just trim based on frame inclusion, then put the hyper-accurate length in the container file metadata. Some playback software might actually cut off based on that number, but again, most AV software just isn't designed for that level of accuracy. I would be curious to see what FFmpeg shows as the length of a file trimmed by Audacity.
That's all that springs to mind now, but I'm happy to give more feedback once you've had a chance to incorporate some of the above. My guess would be that this sort of accuracy is required for research pruposes, in which case, happy researching!

Convert a video to MP4 (H.264/AAC) with ffmpeg

If I don't make a mistake, Safari currently need MP4 (H.264/AAC) video encoded for the HTML5 <video> element.
So I tried to convert a video to this format with ffmpeg. However when I enter the shell command ffmpeg -i video.flv video.mp4, the returned error is :
Seems stream 0 codec frame rate
differs from container frame rate:
2000.00 (2000/1) -> 29.92 (359/12) Input #0, flv, from 'video.flv':
Duration: 00:05:01.20, start:
0.000000, bitrate: 66 kb/s
Stream #0.0: Video: h264, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 66 kb/s,
29.92 tbr, 1k tbn, 2k tbc
Stream #0.1: Audio: aac, 22050 Hz, stereo, s16 Output #0, mp4, to
'video.mp4':
Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3],
q=2-31, 200 kb/s, 90k tbn, 29.92 tbc
Stream #0.1: Audio: 0x0000, 22050 Hz, stereo, s16, 64 kb/s Stream
mapping: Stream #0.0 -> #0.0
Stream #0.1 -> #0.1 Unsupported codec
for output stream #0.1
An AAC codec is required but I'm quite newbie with ubuntu and I dont really now how to fix this problem. I'm using Ubuntu 9.10 Karmik Koala (for amd64).
Thank you very much. :)
http://handbrake.fr is a nice high level tool with a lot of useful presets for mp4 for iPod, PS3, ... with both GUI and CLI interfaces for Linux, Windows and Mac OS X.
It comes with its own dependencies as a single statically linked fat binary so you have all the x264 / aac codecs included.
$ HandBrakeCLI -Z Universal -i myinputfile.mov -o myoutputfile.mp4
To list all the available presets:
$ HandBrakeCLI -z
Software patents led Debian/Ubuntu to disable the H.264 and AAC encoders in ffmpeg. See /usr/share/doc/ffmpeg/README.Debian.gz.
So go install x264, mplayer/mencoder, and Nero's AAC encoder. (Or, if you want to use all Free software, and don't care so much about audio quality, then sudo aptitude install faac.)
I don't remember if the medibuntu package of mencoder includes x264 vid encoding, since I build my own from git x264 and svn mplayer sources. (x264 is very actively developed, with significant quality and speed improvements frequently added.)
http://git.videolan.org/?p=x264.git;a=summary
x264 is also packaged, but you should check that it's up to date enough to include weightp with recent bugfixes, and even more recent speed improvements...
Or if you're already willing to convert from .flv, instead of going from the high-quality source the flv was made from, then probably whatever recent version of x264 you can find will be fine.
You're trying to convert a (rather rare) .flv file that (already) contains H.264 video and AAC audio.
Formatting your console's output as FFmpeg brings out these details.
Input #0, flv, from 'video.flv':
Duration: 00:05:01.20, start: 0.000000, bitrate: 66 kb/s
Stream #0.0: Video: h264, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 66 kb/s, 29.92 tbr, 1k tbn, 2k tbc
Stream #0.1: Audio: aac, 22050 Hz, stereo, s16
The original flv is converted to an .mp4 file with H.264 video and AAC audio (just like the original .flv):
Output #0, mp4, to 'video.mp4':
Stream #0.0: Video: mpeg4, yuv420p, 320x240 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 29.92 tbc
Stream #0.1: Audio: 0x0000, 22050 Hz, stereo, s16, 64 kb/s
Because the audio and video data in the .flv are already in the format/codecs you need for the .mp4, you can just copy everything to the new .mp4 container. This process will be massively faster than decoding and reencoding everything:
ffmpeg -i video.flv -vcodec copy -acodec copy video.mp4
or more simply:
ffmpeg -i video.flv -codec copy video.mp4
##The real error you're getting is:##
Unsupported codec for output stream #0.1
Which means FFmpeg can't convert audio (stream #0.1) to AAC.
You can skip the error by:
copying the audio data since it's already AAC encoded (use the copy command above)
or you can solve the error by:
using a FFmpeg build with AAC decode/encode support. FFmpeg currently supports 4 AAC libraries (see FFmpeg and AAC Encoding Guide).
For more details you should also read Converting FLV to MP4 With FFmpeg The Ultimate Guide
You need to recompile ffmpeg (from source) so that it supports x264. If you follow the instructions in this page, then you will be able to peform any kind of conversion you want.
You can also try adding the Motumedia PPA to your apt sources and update your ffmpeg packages.
Had this problem recently with converting nasty WMV into Final Cut Pro X for editing. Flow player can do it but it leaves a water mark, so I fiddled a bit with ffmpeg till I got something going.
First install ffmpeg - I used
brew install ffmpeg
Obviously you need brew installed first, google that bit.
Next I wrote a simple command line script with the following content - you can substitute the $1 for an input / output file or just create a shell script file...
vi convert.sh
Paste.
echo "Pass one"
ffmpeg -y -i "$1" -c:v libx264 -preset medium -b:v 1555k -pass 1 -c:a libfaac -b:a 256k -f mp4 /dev/null &&
echo "Pass two"
ffmpeg -i "$1" -c:v libx264 -preset medium -b:v 1555k -pass 2 -c:a libfaac -b:a 256k "$1.mp4"
Then to convert your video...
sh convert.sh myvideofile.wmv
If all went well you should see a new file called myvideofile.wmv.mp4.
Hope that works for you.
You need to compile ffmpeg with an AAC encoder. You can find one at AudioCoding.
Try This one:: Libav in Linux
Installation: run command
sudo apt-get install libav-tools
Video conversion command::Go to folder contains the video and run in terminal
avconv -i oldvideo.flv -ar 22050 convertedvideo.mp4

RTMP: Is there such a linux command line tool?

I have looked everywhere to find a linux utility that will allow me to download rtmp streams. Not flv video but MP3 streams. The location of the streams I want to download are in this format.
rtmp://live.site.com/loc/45/std_fc74a6b7f79c70a5f60.mp3
Anyone know of such a command line tool? Or even anything close to what I am asking for?
I do not want full software applications and it would be great if it worked on Linux via Shell or something.
Thanks all
One of the following should do, if you have mplayer or vlc compiled with RTMP access.
mplayer -dumpstream rtmp://live.site.com/loc/45/std_fc74a6b7f79c70a5f60.mp3
This will generate a ./stream.dump.
vlc -I dummy rtmp://live.site.com/loc/45/std_fc74a6b7f79c70a5f60.mp3 \
--sout file/ts:output.mpg vlc://quit
This will generate a ./output.mpg. You'll have to demux it to extract just the audio stream out.
This question is old but this can help to another users with this doubt.
To download directly, without any conversion, there is two options (the author of both programs is the same and the behavior is the same):
RTMPDump. Example: rtmpdump -r "rtmp://host.com/dir/file.flv" -o filename.flv
flvstreamer. Example: flvstreamer -r "rtmp://od.flash.plus.es/ondemand/14314/plus/plustv/PO770632.flv" -o salida.flv
And if you want download and convert the video at same time, the best way is use ffmpeg:
ffmpeg -i rtmp://server/live/streamName -acodec copy -vcodec copy dump.mp4
I think the landscape has changed a bit since the time of some of the previous answers. At least according to the rtmp wikipedia page. It would appear that the rtmp protocol specification is open for public use. To that end you can use 2 tools to accomplish what the original poster was asking, rtmpdump and ffmpeg. Here's what I did to download a rtmp stream that was sending an audio podcast.
step #1 - download the stream
I used the tool rtmpdump to accomplish this. Like so:
% rtmpdump -r rtmp://url/to/some/file.mp3 -o /path/to/file.flv
RTMPDump v2.3
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
Connecting ...
INFO: Connected...
Starting download at: 0.000 kB
28358.553 kB / 3561.61 sec
Download complete
step #2 - convert the flv file to mp3
OK, so now you've got a local copy of the stream, file.flv. You can use ffmpeg to interrogate the file further and also to extract just the audio portion.
% ffmpeg -i file.flv
....
[flv # 0x25f6670]max_analyze_duration reached
[flv # 0x25f6670]Estimating duration from bitrate, this may be inaccurate
Input #0, flv, from 'file.flv':
Duration: 00:59:21.61, start: 0.000000, bitrate: 64 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, 1 channels, s16, 64 kb/s
From the above output we can see that the file.flv contains a single stream, just audio, and it's in mp3 format, and it's a single channel. To extract it to a proper mp3 file you can use ffmpeg again:
% ffmpeg -i file.flv -vn -acodec copy file.mp3
....
[flv # 0x22a6670]max_analyze_duration reached
[flv # 0x22a6670]Estimating duration from bitrate, this may be inaccurate
Input #0, flv, from 'file.flv':
Duration: 00:59:21.61, start: 0.000000, bitrate: 64 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, 1 channels, s16, 64 kb/s
Output #0, mp3, to 'file.mp3':
Metadata:
TSSE : Lavf52.64.2
Stream #0.0: Audio: libmp3lame, 44100 Hz, 1 channels, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
size= 27826kB time=3561.66 bitrate= 64.0kbits/s
video:0kB audio:27826kB global headers:0kB muxing overhead 0.000116%
The above command will copy the audio stream into a file, file.mp3. You could also have extracted it to a wav file like so:
ffmpeg -i file.flv -vn -acodec pcm_s16le -ar 44100 -ac 2 file.wav
This page was useful in determining how to convert the flv file to other formats.

Resources