From patchwork Sat Jan 21 17:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_Gro=C3=9Fe?= X-Patchwork-Id: 2277 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp569345vsb; Sat, 21 Jan 2017 09:00:35 -0800 (PST) X-Received: by 10.223.177.134 with SMTP id q6mr16440249wra.83.1485018035012; Sat, 21 Jan 2017 09:00:35 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o184si7681149wma.89.2017.01.21.09.00.34; Sat, 21 Jan 2017 09:00:34 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 364AC68A620; Sat, 21 Jan 2017 19:00:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from james.theweblords.de (james.theweblords.de [217.11.55.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B4BB668A117 for ; Sat, 21 Jan 2017 19:00:11 +0200 (EET) Received: (qmail 3677 invoked by uid 210); 21 Jan 2017 17:00:23 -0000 X-Qmail-Scanner-Diagnostics: from x5d808bdc.dyn.telefonica.de (petronios@theweblords.de@x5d808bdc.dyn.telefonica.de) by james (envelope-from , uid 201) with qmail-scanner-2.10st (mhr: 1.0. spamassassin: 3.4.1. perlscan: 2.10st. Clear:RC:1(93.128.139.220):. Processed in 0.04482 secs); 21 Jan 2017 17:00:23 -0000 Received: from x5d808bdc.dyn.telefonica.de (HELO montepegro.fem.tu-ilmenau.de) (petronios@theweblords.de@93.128.139.220) by james.theweblords.de with ESMTPA; 21 Jan 2017 17:00:22 -0000 From: =?UTF-8?q?Peter=20Gro=C3=9Fe?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 Jan 2017 18:00:13 +0100 Message-Id: <20170121170013.2300-1-pegro@friiks.de> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] libavformat/dashenc: add webm support 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: ischluff@mailbox.org, pegro@friiks.de Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Use webm muxer for VP8, VP9 and Opus codec, mp4 muxer otherwise. Signed-off-by: Peter Große --- libavformat/dashenc.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index bd6bb88..29920fa 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -114,6 +114,23 @@ static void set_codec_str(AVFormatContext *s, AVCodecParameters *par, { const AVCodecTag *tags[2] = { NULL, NULL }; uint32_t tag; + + // common Webm codecs are not part of RFC 6381 + switch (par->codec_id) { + case AV_CODEC_ID_VP8: + snprintf(str, size, "vp8"); + return; + case AV_CODEC_ID_VP9: + snprintf(str, size, "vp9"); + return; + case AV_CODEC_ID_VORBIS: + snprintf(str, size, "vorbis"); + return; + case AV_CODEC_ID_OPUS: + snprintf(str, size, "opus"); + return; + } + if (par->codec_type == AVMEDIA_TYPE_VIDEO) tags[0] = ff_codec_movvideo_tags; else if (par->codec_type == AVMEDIA_TYPE_AUDIO) @@ -500,14 +517,14 @@ static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind continue; if (as->media_type == AVMEDIA_TYPE_VIDEO) { - avio_printf(out, "\t\t\tcodec_str, os->bit_rate, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height); + avio_printf(out, "\t\t\tctx->oformat->name, os->codec_str, os->bit_rate, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height); if (s->streams[i]->avg_frame_rate.num) avio_printf(out, " frameRate=\"%d/%d\"", s->streams[i]->avg_frame_rate.num, s->streams[i]->avg_frame_rate.den); avio_printf(out, ">\n"); } else { - avio_printf(out, "\t\t\t\n", - i, os->codec_str, os->bit_rate, s->streams[i]->codecpar->sample_rate); + avio_printf(out, "\t\t\t\n", + i, os->ctx->oformat->name, os->codec_str, os->bit_rate, s->streams[i]->codecpar->sample_rate); avio_printf(out, "\t\t\t\t\n", s->streams[i]->codecpar->channels); } @@ -790,7 +807,14 @@ static int dash_init(AVFormatContext *s) dict_copy_entry(&as->metadata, s->streams[i]->metadata, "language"); dict_copy_entry(&as->metadata, s->streams[i]->metadata, "role"); - ret = avformat_alloc_output_context2(&ctx, NULL, "mp4", NULL); + // choose muxer based on codec: webm for VP8/9 and opus, mp4 otherwise + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VP8 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VP9 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS) { + ret = avformat_alloc_output_context2(&ctx, NULL, "webm", NULL); + } else { + ret = avformat_alloc_output_context2(&ctx, NULL, "mp4", NULL); + } if (ret < 0) return AVERROR(ENOMEM); os->ctx = ctx; @@ -829,7 +853,14 @@ static int dash_init(AVFormatContext *s) return ret; os->init_start_pos = 0; - av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0); + if (!strcmp(ctx->oformat->name, "mp4")) { + av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0); + } else { + av_dict_set_int(&opts, "dash", 1, 0); + av_dict_set_int(&opts, "cluster_time_limit", c->min_seg_duration / 1000 + 100 , 0); + av_dict_set_int(&opts, "live", 1, 0); + av_dict_set_int(&opts, "dash_track_number", i + 1, 0); + } if ((ret = avformat_init_output(ctx, &opts)) < 0) return ret; os->ctx_inited = 1; @@ -1047,7 +1078,8 @@ static int dash_flush(AVFormatContext *s, int final, int stream) os->pos += range_length; // write chunk header - write_styp(os->ctx->pb); + if (!strcmp(os->ctx->oformat->name, "mp4")) + write_styp(os->ctx->pb); } if (c->window_size || (final && c->remove_at_exit)) {