Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
On Sat, Apr 4, 2015 at 3:38 PM, Michael Niedermayer michae...@gmx.at wrote: On Mon, Mar 30, 2015 at 02:46:10PM -0700, Vignesh Venkatasubramanian wrote: This patch adds support for WebM Live Muxing by adding a new WebM Chunk muxer. It writes out live WebM Chunks which can be used for playback using Live DASH Clients. Please see muxers.texi for sample usage. [...] diff --git a/libavformat/version.h b/libavformat/version.h index a183d7f..ff85227 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include libavutil/version.h #define LIBAVFORMAT_VERSION_MAJOR 56 -#define LIBAVFORMAT_VERSION_MINOR 26 +#define LIBAVFORMAT_VERSION_MINOR 27 #define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c new file mode 100644 index 000..48ea6f0 --- /dev/null +++ b/libavformat/webm_chunk.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2015, Vignesh Venkatasubramanian + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file WebM Chunk Muxer + * The chunk muxer enables writing WebM Live chunks where there is a header + * chunk, followed by data chunks where each Cluster is written out as a Chunk. + */ + +#include float.h +#include time.h + +#include avformat.h +#include avio.h +#include internal.h + +#include libavutil/avassert.h +#include libavutil/log.h +#include libavutil/opt.h +#include libavutil/avstring.h +#include libavutil/parseutils.h +#include libavutil/mathematics.h +#include libavutil/time.h +#include libavutil/time_internal.h +#include libavutil/timestamp.h + +typedef struct WebMChunkContext { +const AVClass *class; +int chunk_start_index; +char *header_filename; +int chunk_duration; +int chunk_count; +int chunk_index; +uint64_t duration_written; +int prev_pts; +AVOutputFormat *oformat; +AVFormatContext *avf; +} WebMChunkContext; + +static int chunk_mux_init(AVFormatContext *s) +{ +WebMChunkContext *wc = s-priv_data; +AVFormatContext *oc; +int ret; + +ret = avformat_alloc_output_context2(wc-avf, wc-oformat, NULL, NULL); +if (ret 0) +return ret; +oc = wc-avf; + +oc-interrupt_callback = s-interrupt_callback; +oc-max_delay = s-max_delay; +av_dict_copy(oc-metadata, s-metadata, 0); + +oc-priv_data = av_mallocz(oc-oformat-priv_data_size); +if (!oc-priv_data) { +avio_close(oc-pb); +return AVERROR(ENOMEM); +} +*(const AVClass**)oc-priv_data = oc-oformat-priv_class; +av_opt_set_defaults(oc-priv_data); +av_opt_set_int(oc-priv_data, dash, 1, 0); +av_opt_set_int(oc-priv_data, cluster_time_limit, wc-chunk_duration, 0); +av_opt_set_int(oc-priv_data, live, 1, 0); + +oc-streams = s-streams; +oc-nb_streams = s-nb_streams; why doesnt the code use avformat_new_stream() and avcodec_copy_context() see hlsenc/segment muxers for examples or is there a reason why this would not work or be hard ? it seems unnecessary to make a copy of the stream and codec context when it can be used safely within this file without duplication. is there something wrong with that line of thought? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel -- Vignesh ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
On Mon, Apr 06, 2015 at 11:19:36AM -0700, Vignesh Venkatasubramanian wrote: On Sat, Apr 4, 2015 at 3:38 PM, Michael Niedermayer michae...@gmx.at wrote: On Mon, Mar 30, 2015 at 02:46:10PM -0700, Vignesh Venkatasubramanian wrote: This patch adds support for WebM Live Muxing by adding a new WebM Chunk muxer. It writes out live WebM Chunks which can be used for playback using Live DASH Clients. Please see muxers.texi for sample usage. [...] diff --git a/libavformat/version.h b/libavformat/version.h index a183d7f..ff85227 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include libavutil/version.h #define LIBAVFORMAT_VERSION_MAJOR 56 -#define LIBAVFORMAT_VERSION_MINOR 26 +#define LIBAVFORMAT_VERSION_MINOR 27 #define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c new file mode 100644 index 000..48ea6f0 --- /dev/null +++ b/libavformat/webm_chunk.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2015, Vignesh Venkatasubramanian + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file WebM Chunk Muxer + * The chunk muxer enables writing WebM Live chunks where there is a header + * chunk, followed by data chunks where each Cluster is written out as a Chunk. + */ + +#include float.h +#include time.h + +#include avformat.h +#include avio.h +#include internal.h + +#include libavutil/avassert.h +#include libavutil/log.h +#include libavutil/opt.h +#include libavutil/avstring.h +#include libavutil/parseutils.h +#include libavutil/mathematics.h +#include libavutil/time.h +#include libavutil/time_internal.h +#include libavutil/timestamp.h + +typedef struct WebMChunkContext { +const AVClass *class; +int chunk_start_index; +char *header_filename; +int chunk_duration; +int chunk_count; +int chunk_index; +uint64_t duration_written; +int prev_pts; +AVOutputFormat *oformat; +AVFormatContext *avf; +} WebMChunkContext; + +static int chunk_mux_init(AVFormatContext *s) +{ +WebMChunkContext *wc = s-priv_data; +AVFormatContext *oc; +int ret; + +ret = avformat_alloc_output_context2(wc-avf, wc-oformat, NULL, NULL); +if (ret 0) +return ret; +oc = wc-avf; + +oc-interrupt_callback = s-interrupt_callback; +oc-max_delay = s-max_delay; +av_dict_copy(oc-metadata, s-metadata, 0); + +oc-priv_data = av_mallocz(oc-oformat-priv_data_size); +if (!oc-priv_data) { +avio_close(oc-pb); +return AVERROR(ENOMEM); +} +*(const AVClass**)oc-priv_data = oc-oformat-priv_class; +av_opt_set_defaults(oc-priv_data); +av_opt_set_int(oc-priv_data, dash, 1, 0); +av_opt_set_int(oc-priv_data, cluster_time_limit, wc-chunk_duration, 0); +av_opt_set_int(oc-priv_data, live, 1, 0); + +oc-streams = s-streams; +oc-nb_streams = s-nb_streams; why doesnt the code use avformat_new_stream() and avcodec_copy_context() see hlsenc/segment muxers for examples or is there a reason why this would not work or be hard ? it seems unnecessary to make a copy of the stream and codec context when it can be used safely within this file without duplication. is there something wrong with that line of thought? well, it feels a bit odd but if you prefer it? ill push it that way Thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The misfortune of the wise is better than the prosperity of the fool. -- Epicurus signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
On Mon, Mar 30, 2015 at 02:46:10PM -0700, Vignesh Venkatasubramanian wrote: This patch adds support for WebM Live Muxing by adding a new WebM Chunk muxer. It writes out live WebM Chunks which can be used for playback using Live DASH Clients. Please see muxers.texi for sample usage. [...] diff --git a/libavformat/version.h b/libavformat/version.h index a183d7f..ff85227 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include libavutil/version.h #define LIBAVFORMAT_VERSION_MAJOR 56 -#define LIBAVFORMAT_VERSION_MINOR 26 +#define LIBAVFORMAT_VERSION_MINOR 27 #define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c new file mode 100644 index 000..48ea6f0 --- /dev/null +++ b/libavformat/webm_chunk.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2015, Vignesh Venkatasubramanian + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file WebM Chunk Muxer + * The chunk muxer enables writing WebM Live chunks where there is a header + * chunk, followed by data chunks where each Cluster is written out as a Chunk. + */ + +#include float.h +#include time.h + +#include avformat.h +#include avio.h +#include internal.h + +#include libavutil/avassert.h +#include libavutil/log.h +#include libavutil/opt.h +#include libavutil/avstring.h +#include libavutil/parseutils.h +#include libavutil/mathematics.h +#include libavutil/time.h +#include libavutil/time_internal.h +#include libavutil/timestamp.h + +typedef struct WebMChunkContext { +const AVClass *class; +int chunk_start_index; +char *header_filename; +int chunk_duration; +int chunk_count; +int chunk_index; +uint64_t duration_written; +int prev_pts; +AVOutputFormat *oformat; +AVFormatContext *avf; +} WebMChunkContext; + +static int chunk_mux_init(AVFormatContext *s) +{ +WebMChunkContext *wc = s-priv_data; +AVFormatContext *oc; +int ret; + +ret = avformat_alloc_output_context2(wc-avf, wc-oformat, NULL, NULL); +if (ret 0) +return ret; +oc = wc-avf; + +oc-interrupt_callback = s-interrupt_callback; +oc-max_delay = s-max_delay; +av_dict_copy(oc-metadata, s-metadata, 0); + +oc-priv_data = av_mallocz(oc-oformat-priv_data_size); +if (!oc-priv_data) { +avio_close(oc-pb); +return AVERROR(ENOMEM); +} +*(const AVClass**)oc-priv_data = oc-oformat-priv_class; +av_opt_set_defaults(oc-priv_data); +av_opt_set_int(oc-priv_data, dash, 1, 0); +av_opt_set_int(oc-priv_data, cluster_time_limit, wc-chunk_duration, 0); +av_opt_set_int(oc-priv_data, live, 1, 0); + +oc-streams = s-streams; +oc-nb_streams = s-nb_streams; why doesnt the code use avformat_new_stream() and avcodec_copy_context() see hlsenc/segment muxers for examples or is there a reason why this would not work or be hard ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
Vignesh Venkatasubramanian vigneshv at google.com writes: +if (!wc-oformat) { return AVERROR_MUXER_NOT_FOUND; } It is your file but most people here seem to agree that the following is more (and not less) readable: if (!wc-oformat) return AVERROR_MUXER_NOT_FOUND; +if ((ret = chunk_mux_init(s)) 0) { return ret; } It is your decision but not merging assignment and comparison is common practice here: I suspect both for readability and because it saves a lot of time debugging... +oc-streams = NULL; +oc-nb_streams = 0; +avformat_free_context(oc); +oc-streams = NULL; +oc-nb_streams = 0; +avformat_free_context(oc); The first two seem unnecessary if you call avformat_free_context(). Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
Vignesh Venkatasubramanian vigneshv at google.com writes: +oc-streams = NULL; +oc-nb_streams = 0; +avformat_free_context(oc); The first two seem unnecessary if you call avformat_free_context(). The first two lines are intentional. Sorry about the comment;-) Carl Eugen ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
On Mon, 30 Mar 2015 12:49:45 -0700 Vignesh Venkatasubramanian vigne...@google.com wrote: This patch adds support for WebM Live Muxing by adding a new WebM Chunk muxer. It writes out live WebM Chunks which can be used for playback using Live DASH Clients. Please see muxers.texi for sample usage. Signed-off-by: Vignesh Venkatasubramanian vigne...@google.com --- Changelog | 1 + doc/muxers.texi | 43 libavformat/Makefile | 5 +- libavformat/allformats.c | 1 + libavformat/matroskaenc.c | 12 ++- libavformat/version.h | 2 +- libavformat/webm_chunk.c | 251 ++ 7 files changed, 309 insertions(+), 6 deletions(-) create mode 100644 libavformat/webm_chunk.c diff --git a/Changelog b/Changelog index 75da156..2c7f283 100644 --- a/Changelog +++ b/Changelog @@ -12,6 +12,7 @@ version next: - Detelecine filter - Intel QSV-accelerated H.264 encoding - MMAL-accelerated H.264 decoding +- WebM Live Chunk Muxer version 2.6: diff --git a/doc/muxers.texi b/doc/muxers.texi index a8225fc..d9d900b 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -1236,4 +1236,47 @@ ffmpeg -f webm_dash_manifest -i video1.webm \ manifest.xml @end example +@section webm_chunk + +WebM Live Chunk Muxer. + +This muxer writes out WebM headers and chunks as separate files which can be +consumed by clients that support WebM Live streams via DASH. + +@subsection Options + +This muxer supports the following options: + +@table @option +@item chunk_start_index +Index of the first chunk (defaults to 0). + +@item header +Filename of the header where the initialization data will be written. + +@item audio_chunk_duration +Duration of each audio chunk in milliseconds (defaults to 5000). +@end table + +@subsection Example +@example +ffmpeg -f v4l2 -i /dev/video0 \ + -f alsa -i hw:0 \ + -map 0:0 \ + -c:v libvpx-vp9 \ + -s 640x360 -keyint_min 30 -g 30 \ + -f webm_chunk \ + -header webm_live_video_360.hdr \ + -chunk_start_index 1 \ + webm_live_video_360_%d.chk \ + -map 1:0 \ + -c:a libvorbis \ + -b:a 128k \ + -f webm_chunk \ + -header webm_live_audio_128.hdr \ + -chunk_start_index 1 \ + -audio_chunk_duration 1000 \ + webm_live_audio_128_%d.chk +@end example + @c man end MUXERS diff --git a/libavformat/Makefile b/libavformat/Makefile index 2118ff2..e40ed4d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -237,7 +237,7 @@ OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \ OBJS-$(CONFIG_MATROSKA_MUXER)+= matroskaenc.o matroska.o \ isom.o avc.o hevc.o \ flacenc_header.o avlanguage.o vorbiscomment.o wv.o \ -webmdashenc.o +webmdashenc.o webm_chunk.o OBJS-$(CONFIG_MD5_MUXER) += md5enc.o OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o OBJS-$(CONFIG_MICRODVD_DEMUXER) += microdvddec.o subtitles.o @@ -451,12 +451,13 @@ OBJS-$(CONFIG_WEBM_MUXER)+= matroskaenc.o matroska.o \ isom.o avc.o hevc.o \ flacenc_header.o avlanguage.o \ wv.o vorbiscomment.o \ -webmdashenc.o +webmdashenc.o webm_chunk.o OBJS-$(CONFIG_WEBM_DASH_MANIFEST_DEMUXER)+= matroskadec.o matroska.o \ isom.o rmsipr.o flac_picture.o \ oggparsevorbis.o vorbiscomment.o \ flac_picture.o replaygain.o OBJS-$(CONFIG_WEBM_DASH_MANIFEST_MUXER) += webmdashenc.o matroska.o +OBJS-$(CONFIG_WEBM_CHUNK_MUXER) += webm_chunk.o matroska.o OBJS-$(CONFIG_WEBP_MUXER)+= webpenc.o OBJS-$(CONFIG_WEBVTT_DEMUXER)+= webvttdec.o subtitles.o OBJS-$(CONFIG_WEBVTT_MUXER) += webvttenc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 26ccc27..f56493c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -316,6 +316,7 @@ void av_register_all(void) REGISTER_DEMUXER (WC3, wc3); REGISTER_MUXER (WEBM, webm); REGISTER_MUXDEMUX(WEBM_DASH_MANIFEST, webm_dash_manifest); +REGISTER_MUXER (WEBM_CHUNK, webm_chunk); REGISTER_MUXER (WEBP, webp); REGISTER_MUXDEMUX(WEBVTT, webvtt); REGISTER_DEMUXER (WSAUD,wsaud); diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index
Re: [FFmpeg-devel] [PATCH] lavf: Add support for WebM Live Muxing
When are we going to get a DASH demuxer? Why don't you implement it? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel