Friday, 14 April 2017

FFMPEG - issue with raw audio

FFMPEG - issue with raw audio

I am writting a free and open source software for video and audio editing. I decided to use FFMPEG as video converter because it is free and open source too. My goal is to convert video and audio formats to raw data using FFMPEG, then edit raw data with my application and then convert back to readable/playable format using FFMPEG.

For video, it is simple. The following command:

ffmpeg -i 1.mp4 -y -f rawvideo -pix_fmt rgb24 1.hex

allows me to do exactly that. After processing 1.hex I convert it back using

ffmpeg -f rawvideo -pix_fmt rgb24 -i 1.mp4 -y -pix_fmt yuv420p 1.mp4
del 1.hex

It works properly.

The problem is when 1.mp4 contains audio. I know I must separately process audio and video (I have to create two raw files and the join them together after processing). I used the following command for audio:

ffmpeg -i 1.mp3 -y -f s16le 1.hex

But, without even touching 1.hex, I immediatelly converted again to mp3, but the output is 2 times slower (speed is decreased x2):

ffmpeg -f s16le -ar 48000 -i 1.hex -y 1.mp3

Obviously, I am missing something. After a lot of search on the internet, I didn't find anything useful. Then I decided to use ffprobe to analyze input and output file. This is the result

Before:

Input #0, mp3, from '1.mp3':
  Metadata:
    encoder         : Lavf57.57.100
  Duration: 00:00:03.02, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc57.66

After:

Input #0, mp3, from '1.mp3':
  Metadata:
    encoder         : Lavf57.57.100
  Duration: 00:00:06.56, start: 0.025057, bitrate: 64 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s

So, I noticed two things which are different: bitrate and frequency. So, I changed my parameters to the following:

ffmpeg -f s16le -ar 48000 -i 1.hex -y -b:a 128k 1.mp3

Now, it fixed frequency and bitrate:

Input #0, mp3, from '3.mp3':
  Metadata:
    encoder         : Lavf57.57.100
  Duration: 00:00:06.02, start: 0.023021, bitrate: 128 kb/s
    Stream #0:0: Audio: mp3, 48000 Hz, mono, s16p, 128 kb/s

but audio is still x2 times slower (notice that duration is still 6 seconds instead of 3 seconds).

What am I missing?



via grxsxehlresxhuv

No comments:

Post a Comment