Пример декодирования аудио FFmpeg/Libav

Я пытаюсь получить тот же результат, что и ffmpeg/avconv, от преобразования файла MP2 в необработанный PCM с использованием кода. Я использовал функцию audio_decode_example из учебника, включенного в документацию FFmpeg/Libav. но выходы были разные.

Какие шаги выполняет команда ffmpeg/avconv, которые мне нужно добавить в мою программу, чтобы получить тот же результат?

Изменить: это вывод из avconv -v debug -i test.mp2 test.sw:

avconv version v10_beta1-302-g606cc8a, Copyright (c) 2000-2014 the Libav developers
built on Mar 20 2014 20:28:32 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu9)
configuration: 
libavutil     53.  6. 0 / 53.  6. 0
libavcodec    55. 34. 1 / 55. 34. 1
libavformat   55. 12. 0 / 55. 12. 0
libavdevice   54.  0. 0 / 54.  0. 0
libavfilter    4.  3. 0 /  4.  3. 0
libavresample  1.  2. 0 /  1.  2. 0
libswscale     2.  1. 2 /  2.  1. 2
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set libav* logging level) with argument 'debug'.
Reading option '-i' ... matched as input file with argument 'test.mp2'.
Reading option 'test1.sw' ... matched as output file.                                  
Finished splitting the commandline.                                       
Parsing a group of options: global .                
Applying option v (set libav* logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file test.mp2.
Successfully parsed a group of options.
Opening an input file: test.mp2.
[mp3 @ 0x27e5060] Probed with size=2048 and score=51
[mp3 @ 0x27e5060] Estimating duration from bitrate, this may be inaccurate
Guessed Channel Layout for  Input Stream #0.0 : stereo
Input #0, mp3, from 'test.mp2':
  Duration: 00:00:04.80, start: 0.000000, bitrate: 64 kb/s
    Stream #0.0, 200, 1/14112000: Audio: mp2, 48000 Hz, stereo, s16p, 64 kb/s
Successfully opened the file.
Parsing a group of options: output file test1.sw.
Successfully parsed a group of options.
Opening an output file: test1.sw.
Successfully opened the file.
Detected 2 logical cores.
[abuffer @ 0x27e5860] tb:1/48000 samplefmt:s16p samplerate: 48000 ch layout:0x3
[abuffersink @ 0x2807040] auto-inserting filter 'auto-inserted fifo 0' between the filter 'audio format for output stream 0:0' and the filter 'output stream 0:0'
[aformat @ 0x2806bc0] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed filter 0 anull' and the filter 'audio format for output stream 0:0'
[AVAudioResampleContext @ 0x28092a0] audio_convert: found function: s16p to s16  (C)
[AVAudioResampleContext @ 0x28092a0] audio_convert: found function: s16p to s16  (SSE2)
[resample @ 0x2808560] fmt:s16p srate:48000 cl:stereo -> fmt:s16 srate:48000 cl:stereo
Output #0, s16le, to 'test1.sw':
  Metadata:
    encoder         : Lavf55.12.0
    Stream #0.0, 0, 1/90000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
  Stream mapping:
    Stream #0:0 -> #0:0 (mp2 -> pcm_s16le)
Press ctrl-c to stop encoding
Input stream #0:0 frame changed from rate:48000 fmt:s16p ch:2 chl:stereo to rate:48000 fmt:s16 ch:2 chl:stereo
Detected 2 logical cores.
[abuffer @ 0x2806e40] tb:1/48000 samplefmt:s16 samplerate: 48000 ch layout:0x3
[abuffersink @ 0x2806fa0] auto-inserting filter 'auto-inserted fifo 0' between the filter 'audio format for output stream 0:0' and the filter 'output stream 0:0'
No more output streams to write to, finishing.
size=     900kB time=4.80 bitrate=1536.0kbits/s    
video:0kB audio:0kB global headers:0kB muxing overhead 0.000000%

person Walid Baccari    schedule 18.03.2014    source источник
comment
исходный вывод PCM отличается? это звучит так же? вы можете попробовать запустить ffmpeg с -loglevel verbose, возможно, чтобы получить больше информации   -  person rogerdpack    schedule 18.03.2014
comment
Выходной файл из программы имеет тот же размер, что и файл avconv, но звучит иначе (прерывистый и имеет больше шума)   -  person Walid Baccari    schedule 19.03.2014
comment
Вы используете двоичные файлы для ffmpeg и avconv? Если да, то полная командная строка и неразрезанный вывод консоли, пожалуйста   -  person rogerdpack    schedule 19.03.2014
comment
Хорошо, @rogerdpack, я сделал то, что ты просил. Я использую avconv, который я скомпилировал из исходников Libav на Github.   -  person Walid Baccari    schedule 26.03.2014
comment
автоматически вставляемый ресемплер 0 может быть подсказкой, но это все, что я знаю...   -  person rogerdpack    schedule 26.03.2014


Ответы (1)


У меня были те же проблемы. Кажется, декодирование libav mp2 по умолчанию выводит в формате S16P (планарный), который не так распространен в различных приложениях для редактирования аудио, которые поддерживают необработанный ввод (например, дерзость). Я решил свою проблему, указав request_sample_fmt в AVCodecContext как AV_SAMPLE_FMT_S16. Таким образом, нет необходимости в дополнительной программной передискретизации.

В функции audio_decode_example:

...
c = avcodec_alloc_context3(codec);
if (!c) {
    fprintf(stderr, "Could not allocate audio codec context\n");
    exit(1);
}
c->request_sample_fmt = AV_SAMPLE_FMT_S16;
...
person Ivo Andonov    schedule 19.05.2015