From patchwork Wed Aug 21 11:34:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 14639 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DBF2E447D83 for ; Wed, 21 Aug 2019 14:34:49 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B7A6568A55A; Wed, 21 Aug 2019 14:34:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpproxy19.qq.com (smtpproxy19.qq.com [184.105.206.84]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1244568A101 for ; Wed, 21 Aug 2019 14:34:42 +0300 (EEST) X-QQ-mid: bizesmtp17t1566387273tzs8nb20 Received: from localhost (unknown [43.247.177.226]) by esmtp6.qq.com (ESMTP) with id ; Wed, 21 Aug 2019 19:34:32 +0800 (CST) X-QQ-SSF: 01100000002000K0ZQF1000A0000000 X-QQ-FEAT: 9MsTBLS6yXHF+jDjYaT1stRBD6AGi5tshsdTghtynbUWWyLlo+R7xRpzN1tuo 0PWi1w7omEDV6z0zcG6f8l/PIoXvoT+my4GPrLlqKEz79Z6eqXQp1Jv6tIIB0bLIGPFJqA3 sEe0rsgD0gtpX6Qd0fMtcqAqjB2O3T9tu4ZsZ/DxWxB3y2dXCSmni/XPkWwtlIdiK4exLu6 ChlLp0BJLbBuBHNqNY3mS0TOOduAEzrtI542V+h/8N6OMfvTukhfBhZnRo0Kc8J2jbONNh6 UJ9tTI1zU6fmRaX5EVCgdnnmf0YA4ZLkWxkR6cE1+YY/tB5SXGLq315Y40ZjADvvc3unJWH SQofkCg X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Aug 2019 19:34:28 +0800 Message-Id: <20190821113428.33142-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.17.2 (Apple Git-113) X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign4 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH 1/2] doc/examples/decode_audio: print message about how to play the output file X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Steven Liu --- doc/examples/decode_audio.c | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/doc/examples/decode_audio.c b/doc/examples/decode_audio.c index 19dcafd2c8..23d0c9bf50 100644 --- a/doc/examples/decode_audio.c +++ b/doc/examples/decode_audio.c @@ -39,6 +39,35 @@ #define AUDIO_INBUF_SIZE 20480 #define AUDIO_REFILL_THRESH 4096 +static int get_format_from_sample_fmt(const char **fmt, + enum AVSampleFormat sample_fmt) +{ + int i; + struct sample_fmt_entry { + enum AVSampleFormat sample_fmt; const char *fmt_be, *fmt_le; + } sample_fmt_entries[] = { + { AV_SAMPLE_FMT_U8, "u8", "u8" }, + { AV_SAMPLE_FMT_S16, "s16be", "s16le" }, + { AV_SAMPLE_FMT_S32, "s32be", "s32le" }, + { AV_SAMPLE_FMT_FLT, "f32be", "f32le" }, + { AV_SAMPLE_FMT_DBL, "f64be", "f64le" }, + }; + *fmt = NULL; + + for (i = 0; i < FF_ARRAY_ELEMS(sample_fmt_entries); i++) { + struct sample_fmt_entry *entry = &sample_fmt_entries[i]; + if (sample_fmt == entry->sample_fmt) { + *fmt = AV_NE(entry->fmt_be, entry->fmt_le); + return 0; + } + } + + fprintf(stderr, + "sample format %s is not supported as output format\n", + av_get_sample_fmt_name(sample_fmt)); + return -1; +} + static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile) { @@ -172,6 +201,28 @@ int main(int argc, char **argv) pkt->size = 0; decode(c, pkt, decoded_frame, outfile); + /* print output pcm infomations, because there have no metadata of pcm */ + enum AVSampleFormat sfmt = c->sample_fmt; + int n_channels = c->channels; + const char *fmt; + + if (av_sample_fmt_is_planar(sfmt)) { + const char *packed = av_get_sample_fmt_name(sfmt); + printf("Warning: the sample format the decoder produced is planar " + "(%s). This example will output the first channel only.\n", + packed ? packed : "?"); + sfmt = av_get_packed_sample_fmt(sfmt); + } + + n_channels = c->channels; + if ((ret = get_format_from_sample_fmt(&fmt, sfmt)) < 0) + goto end; + + printf("Play the output audio file with the command:\n" + "ffplay -f %s -ac %d -ar %d %s\n", + fmt, n_channels, c->sample_rate, + outfilename); +end: fclose(outfile); fclose(f);