From patchwork Mon May 8 04:36:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 3609 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp684292vsd; Sun, 7 May 2017 21:43:04 -0700 (PDT) X-Received: by 10.223.142.213 with SMTP id q79mr36565141wrb.25.1494218584122; Sun, 07 May 2017 21:43:04 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w2si14424289wrb.205.2017.05.07.21.43.03; Sun, 07 May 2017 21:43:04 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF7F06882CA; Mon, 8 May 2017 07:42:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6447C6882AF for ; Mon, 8 May 2017 07:42:48 +0300 (EEST) Received: by mail-qt0-f195.google.com with SMTP id a46so8219553qte.0 for ; Sun, 07 May 2017 21:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=v6V8L/x/oEMW52XHSV/eei43jKqpuY/BIOyLeGD60qM=; b=nYNKUPxPa0lI9RyubqhMxAud9pBGzrMAzObAUO2gLLYstKVEo/7O02FnVVSzRjB78c roFc3b0p4qeGSR0x77t9JCaI20flzbh6JiB/qdQbrx2Nn8tfzqvrGGtn6dN8htEQ+bZP /yEQY9tU3/DPhnWMj68wwTuAENeqOdHqKTNIjS2lk00HOdDdgUfROVgVVS335WzMLQ7V JQjQskpmKe9BrS5vC59VLUa6tJxmTKL9LKPf0wCJGfrKB8DLe0hjA9TOKYgT/wQdwTmb qy4KHhrZdllghYWCQhiPUCh/i0BKHC7tFESpt9Ojox5Wc4/fVVVNrWwijTDh9qr7mxyn BtvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=v6V8L/x/oEMW52XHSV/eei43jKqpuY/BIOyLeGD60qM=; b=CKp14FUrXkwYJJY4vEmpqnmxPQ+1y0+cYoovY2qv/fyu7+jFqS4+Qok+pUFJ2DOy2U 73D5/Bsl6EXgmcqJf8bXr+lLOxG4YKl4lz4bT54qd9qQL0ZBaIcb1WtUgiX8AiwmfkA7 Qx7hEaa/TZYwxuZ3V8artt411zFIBzjRQM4qyLm/sjfz43n99RHqEoE439Q5MXk5a1fM bHQ82I+G5MC7txX0Ck7vvyneU0RskDPUdYU2zL8549yC5n4XAiQb3VJCBVxK81QrXCPu CWTvhhdsniMT+rr16GsCG57JydjwZao4r0Q8S9Ni6d+wP4cZQ4MWC7HxDsDhviSEEqte u6IA== X-Gm-Message-State: AODbwcDkzqQCCyKIr0OyXIOc7yZUtPVseP0OmIbNaoMjsS0ts9X4nSlz F//lM/TyRfT+gwTeGQM= X-Received: by 10.200.55.193 with SMTP id e1mr4489220qtc.198.1494218187602; Sun, 07 May 2017 21:36:27 -0700 (PDT) Received: from rcombs-NAS.hsd1.il.comcast.net. (c-73-110-121-59.hsd1.il.comcast.net. [73.110.121.59]) by smtp.gmail.com with ESMTPSA id 88sm10056162qkx.68.2017.05.07.21.36.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 May 2017 21:36:26 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2017 23:36:18 -0500 Message-Id: <1494218184-17850-1-git-send-email-rodger.combs@gmail.com> X-Mailer: git-send-email 2.6.4 Subject: [FFmpeg-devel] [PATCH 1/7] lavf: add cue sheet demuxer 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- Changelog | 2 + doc/demuxers.texi | 8 ++ libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/cuedec.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 4 +- 6 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 libavformat/cuedec.c diff --git a/Changelog b/Changelog index 0787bea..3e2776d 100644 --- a/Changelog +++ b/Changelog @@ -8,6 +8,8 @@ version : - pixscope video filter - oscilloscope video filter - config.log and other configuration files moved into ffbuild/ directory +- Cue sheet demuxer + version 3.3: - CrystalHD decoder moved to new decode API diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 29a23d4..7ea4f27 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -244,6 +244,14 @@ file subdir/file-2.wav @end example @end itemize +@section cue + +Cue sheet demuxer. + +This demuxer reads a cue sheet (text file) and exports its track listing in +the form of AVChapters. Packet data is read from the file listed in the sheet. +To override the path the packet data is read from, use the @code{url} option. + @section flv, live_flv Adobe Flash Video Format demuxer. diff --git a/libavformat/Makefile b/libavformat/Makefile index 4e169fd..d4c8b3b 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -130,6 +130,7 @@ OBJS-$(CONFIG_CDXL_DEMUXER) += cdxl.o OBJS-$(CONFIG_CINE_DEMUXER) += cinedec.o OBJS-$(CONFIG_CONCAT_DEMUXER) += concatdec.o OBJS-$(CONFIG_CRC_MUXER) += crcenc.o +OBJS-$(CONFIG_CUE_DEMUXER) += cuedec.o OBJS-$(CONFIG_DATA_DEMUXER) += rawdec.o OBJS-$(CONFIG_DATA_MUXER) += rawenc.o OBJS-$(CONFIG_DASH_MUXER) += dashenc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 09e62c3..ad29a8c 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -96,6 +96,7 @@ static void register_all(void) REGISTER_DEMUXER (CINE, cine); REGISTER_DEMUXER (CONCAT, concat); REGISTER_MUXER (CRC, crc); + REGISTER_DEMUXER (CUE, cue); REGISTER_MUXER (DASH, dash); REGISTER_MUXDEMUX(DATA, data); REGISTER_MUXDEMUX(DAUD, daud); diff --git a/libavformat/cuedec.c b/libavformat/cuedec.c new file mode 100644 index 0000000..b177a26 --- /dev/null +++ b/libavformat/cuedec.c @@ -0,0 +1,207 @@ +/* + * Cue sheet demuxer + * Copyright (c) 2016 The FFmpeg Project + * + * 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 + * Cue sheet demuxer + * @author Rodger Combs + */ + +#include "avformat.h" +#include "internal.h" +#include "subtitles.h" +#include "url.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/avstring.h" +#include "libavutil/opt.h" + +typedef struct CueDemuxContext { + AVClass *class; + char *url; + AVFormatContext *avf; +} CueDemuxContext; + +static int cue_probe(AVProbeData *p) +{ + const unsigned char *ptr = p->buf; + + if (AV_RB24(ptr) == 0xEFBBBF) + ptr += 3; /* skip UTF-8 BOM */ + while (*ptr && strncmp(ptr, "FILE ", 5)) + ptr += ff_subtitles_next_line(ptr); + if (!strncmp(ptr, "FILE ", 5)) + return AVPROBE_SCORE_MAX - 5; + return 0; +} + +static char *get_token(char *in) +{ + char *end; + while (av_isspace(*in)) + in++; + if (*in == '"') { + in++; + end = in + strcspn(in, "\"\n\t\r"); + } else { + end = in + strcspn(in, " \n\t\r"); + } + *end = '\0'; + return in; +} + +static int cue_read_header(AVFormatContext *s) +{ + int ret, i; + CueDemuxContext *cue = s->priv_data; + char line[4096], *ptr; + AVDictionary **meta = &s->metadata; + AVChapter *chap = NULL; + while (ff_get_line(s->pb, line, sizeof(line))) { + ptr = line; + if (AV_RB24(ptr) == 0xEFBBBF) + ptr += 3; /* skip UTF-8 BOM */ + while (*ptr == ' ' || *ptr == '\t') + ptr++; + if (!strncmp(ptr, "REM ", 4)) { + char *end = ptr + strcspn(ptr, "\r\n"); + *end = '\0'; + av_log(s, AV_LOG_INFO, "Comment: \"%s\"\n", ptr + 4); + } else if (!strncmp(ptr, "TITLE ", 6)) { + ptr = get_token(ptr + 6); + av_dict_set(meta, chap ? "title" : "album", ptr, 0); + } else if (!strncmp(ptr, "PERFORMER ", 10)) { + ptr = get_token(ptr + 10); + av_dict_set(meta, chap ? "artist" : "album_artist", ptr, 0); + } else if (!strncmp(ptr, "FILE ", 5)) { + if (!cue->url || !*cue->url) { + char url[4096] = {0}; + av_freep(&cue->url); + ff_make_absolute_url(url, sizeof(url), s->filename, get_token(ptr + 5)); + if (!(cue->url = av_strdup(url))) + return AVERROR(ENOMEM); + } + } else if (!strncmp(ptr, "TRACK ", 6)) { + int index = strtol(ptr + 6, &ptr, 10); + chap = avpriv_new_chapter(s, index, (AVRational){1, 75}, AV_NOPTS_VALUE, AV_NOPTS_VALUE, NULL); + if (!chap) + return AVERROR(ENOMEM); + meta = &chap->metadata; + if ((ret = av_dict_copy(meta, s->metadata, 0)) < 0) + return ret; + av_dict_set_int(meta, "track", index, 0); + } else if (!strncmp(ptr, "INDEX ", 6)) { + int min, sec, frame; + int index = strtol(ptr + 6, &ptr, 10); + if (!chap) + return AVERROR_INVALIDDATA; + if (sscanf(ptr, "%u:%u:%u", &min, &sec, &frame) != 3) + return AVERROR_INVALIDDATA; + if (index == 1 || chap->start == 0) + chap->start = min * 75 * 60 + sec * 75 + frame; + } else { + av_log(s, AV_LOG_WARNING, "Unknown command: \"%s\"\n", ptr); + } + } + + if (!cue->url || !*cue->url) + return AVERROR_INVALIDDATA; + + if (!(cue->avf = avformat_alloc_context())) + return AVERROR(ENOMEM); + + cue->avf->interrupt_callback = s->interrupt_callback; + if ((ret = ff_copy_whiteblacklists(cue->avf, s)) < 0) + return ret; + + if ((ret = avformat_open_input(&cue->avf, cue->url, NULL, NULL)) < 0 || + (ret = avformat_find_stream_info(cue->avf, NULL)) < 0) { + av_log(s, AV_LOG_ERROR, "Failed to open '%s'\n", cue->url); + avformat_close_input(&cue->avf); + return ret; + } + + ff_read_frame_flush(cue->avf); + + for (i = 0; i < cue->avf->nb_streams; i++) { + AVStream *st = avformat_new_stream(s, NULL); + AVStream *ist = cue->avf->streams[i]; + if (!st) + return AVERROR(ENOMEM); + st->id = i; + + avcodec_parameters_copy(st->codecpar, ist->codecpar); + + st->disposition = ist->disposition; + avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den); + av_copy_packet(&st->attached_pic, &ist->attached_pic); + } + + s->duration = cue->avf->duration; + + return 0; +} + +static int cue_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + CueDemuxContext *cue = s->priv_data; + return av_read_frame(cue->avf, pkt); +} + +static int cue_read_seek(AVFormatContext *s, int stream_index, + int64_t min_ts, int64_t ts, int64_t max_ts, int flags) +{ + CueDemuxContext *cue = s->priv_data; + return avformat_seek_file(cue->avf, stream_index, min_ts, ts, max_ts, flags); +} + +static int cue_read_close(AVFormatContext *s) +{ + CueDemuxContext *cue = s->priv_data; + avformat_close_input(&cue->avf); + return 0; +} + +#define OFFSET(x) offsetof(CueDemuxContext, x) +#define E AV_OPT_FLAG_DECODING_PARAM +static const AVOption options[] = { + { "url", "override underlying audio location", OFFSET(url), AV_OPT_TYPE_STRING, {.str = ""}, CHAR_MIN, CHAR_MAX, E }, + { NULL } +}; + +static const AVClass cue_class = { + .class_name = "Cue sheet demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_cue_demuxer = { + .name = "cue", + .long_name = NULL_IF_CONFIG_SMALL("Cue sheet"), + .extensions = "cue", + .priv_data_size = sizeof(CueDemuxContext), + .read_probe = cue_probe, + .read_header = cue_read_header, + .read_packet = cue_read_packet, + .read_seek2 = cue_read_seek, + .read_close = cue_read_close, + .priv_class = &cue_class, +}; diff --git a/libavformat/version.h b/libavformat/version.h index 411fd66..b00a8b0 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,8 +32,8 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 57 -#define LIBAVFORMAT_VERSION_MINOR 72 -#define LIBAVFORMAT_VERSION_MICRO 101 +#define LIBAVFORMAT_VERSION_MINOR 73 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \