From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id A8A574E474 for ; Tue, 11 Mar 2025 16:55:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 71B1868E1BC; Tue, 11 Mar 2025 18:55:50 +0200 (EET) Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1767868E165 for ; Tue, 11 Mar 2025 18:55:26 +0200 (EET) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6fda22908d9so43054797b3.1 for ; Tue, 11 Mar 2025 09:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741712124; x=1742316924; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=De89RIP9ytJD1t1Lmqf27ugfHw8OP3v+K3r82KPq+14=; b=hYyNKM9nO6WFX0ObGLLUZsEiMEtTov4l2rUpi1SGxwK37MD3xGaiB/pfMiGS6CZPeh a+VFRvbHEpv5KuQcPk7zlSpMyOwHmWG7mSAwpVHWUV8iKlOmmmq/a1aj2gRXlztYHxxT 54Jhk1/cTdeefwfYHyoQMRFVUAFHriO8sm9Lx13SUtwDC4SCjQ2Jq7sjrMYeBo89TBhO lrIN1t0OdZ5aAa8ok1Dp8h5Ec29h+9Uwqpaag4Ead0rC4pbO6vn63z9nFPh83Q5ki2Jr 5QKMEgst3TANjIKVfUWIUYKvPL1VU5ttrZ/HKMd3u2oJ47a9bpO+Qt+SM7s7VyFAmpFq 0PTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741712124; x=1742316924; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=De89RIP9ytJD1t1Lmqf27ugfHw8OP3v+K3r82KPq+14=; b=TGcY2j/dqWuA/Gw6oH0vCGZhDA91mNcmQPJASefB7+CkNY47MnfX9f4hrEzzlwP99z t6oeupfI8RECrmko0tc7YK4cHVXQUsokpPp0P9MfLF24fU9y11ZLbzud9yTX+8ec8ScB LEeR4XLF3yt5Wt7GyZIXdoewq1kFi/NVwm3PUplSLGuAwVLb+qxrXnpM9eT80hdvMvsc yW/h9xZG+rHd4++HLo+17uFt3f8IL3Jb1shyaQ0b7tjgqlAWiSGt/EzUSGhAdZEQnUjM nN5EgJQU3kL6qczaFhRmIZkWlAx9jTSLVFJBnl7AbDx/ob8g3veliIXqeOE90FLPnFOu R9BA== X-Gm-Message-State: AOJu0Yx9NsGwe2QnG2pXClkltu+AiPZiGPwvL/P7AX49aKhu0hEmljSB Lill5/ro5uapX+Q4QuI40HHalMEmY3k0XFZfYgn+R6Z6m19Kui4f0EN1CtGp X-Gm-Gg: ASbGncukjjaGFl18RGcb1glqHNX0jk7Xpfy7WK04T6UwMqa3DPoNUhJaBFHPJ9hbxel /pvKmFkxi73DPybfJEWDb7cVT4vHKAVzNBmqx6n62AtWjF1/enETe0XBvkq1dXT1hbzoUl8UTXB YtTCArXgi7wamMZPlo+VAtcLfds0pRyd9EOY0AvxqEcdqixJ8xwXWM6ThyyO5aHI05+p5hZTnN1 P3jofJegFI7CD1/orF6M9Ua9RBHfQnAhVqRsr78mOq4vHmQ9OLoVnuTe8lSXihqePSHsfcScao6 aIeeyas76mbko0yqW3yZJ2/sPssB63KVQa0h3p7dOUJc11beq+etyK93ijhJW2uopJ/kGvG8A1x LF+o/zRIHoo/RJF3Uhsk= X-Google-Smtp-Source: AGHT+IGAfNllc6G9C/a80DC0ogwi2XaplmpRiI7FZ9cgv0mg+zvbPEIy2N5+ErlB322gsiUdB4zuyA== X-Received: by 2002:a05:690c:3612:b0:6fd:2192:cf3c with SMTP id 00721157ae682-6febf3b7663mr257341047b3.34.1741712124006; Tue, 11 Mar 2025 09:55:24 -0700 (PDT) Received: from localhost.localdomain ([2607:fb90:ee62:1559:4ce8:9cd:68c0:bf98]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6feb2c64b57sm27544217b3.119.2025.03.11.09.55.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Mar 2025 09:55:23 -0700 (PDT) From: Romain Beauxis To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Mar 2025 11:55:07 -0500 Message-Id: <20250311165513.17834-3-romain.beauxis@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250311165513.17834-1-romain.beauxis@gmail.com> References: <20250311165513.17834-1-romain.beauxis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v8 2/8] tests: Add stream dump test API util. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Romain Beauxis Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- tests/Makefile | 1 + tests/api/Makefile | 2 +- tests/api/api-dump-stream-meta-test.c | 179 ++++++++++++++++++++++++++ 3 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 tests/api/api-dump-stream-meta-test.c diff --git a/tests/Makefile b/tests/Makefile index f9f5fc07f3..1f7e5003c2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -277,6 +277,7 @@ $(FATE_FFPROBE) $(FATE_FFMPEG_FFPROBE) $(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FF $(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(EXESUF) $(FATE_SAMPLES_DUMP_DATA) $(FATE_SAMPLES_DUMP_DATA-yes): tools/venc_data_dump$(EXESUF) $(FATE_SAMPLES_SCALE_SLICE): tools/scale_slice_test$(EXESUF) +$(FATE_SAMPLES_DUMP_STREAM_META): tests/api/api-dump-stream-meta-test$(EXESUF) ifdef SAMPLES FATE += $(FATE_EXTERN) diff --git a/tests/api/Makefile b/tests/api/Makefile index c96e636756..a2cb06a729 100644 --- a/tests/api/Makefile +++ b/tests/api/Makefile @@ -1,7 +1,7 @@ APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264-slice -APITESTPROGS-yes += api-seek +APITESTPROGS-yes += api-seek api-dump-stream-meta APITESTPROGS-$(call DEMDEC, H263, H263) += api-band APITESTPROGS-$(HAVE_THREADS) += api-threadmessage APITESTPROGS += $(APITESTPROGS-yes) diff --git a/tests/api/api-dump-stream-meta-test.c b/tests/api/api-dump-stream-meta-test.c new file mode 100644 index 0000000000..f44ad476e6 --- /dev/null +++ b/tests/api/api-dump-stream-meta-test.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2025 Romain Beauxis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * Dump stream metadata + */ + +#include "libavcodec/avcodec.h" +#include "libavformat/avformat.h" +#include "libavutil/timestamp.h" + +static int dump_stream_meta(const char *input_filename) { + const AVCodec *codec = NULL; + AVPacket *pkt = NULL; + AVFrame *fr = NULL; + AVFormatContext *fmt_ctx = NULL; + AVCodecContext *ctx = NULL; + AVCodecParameters *origin_par = NULL; + AVStream *st; + int audio_stream; + int result; + char *metadata; + + result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL); + if (result < 0) { + av_log(NULL, AV_LOG_ERROR, "Can't open file\n"); + return result; + } + + result = avformat_find_stream_info(fmt_ctx, NULL); + if (result < 0) { + av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n"); + goto end; + } + + // TODO: add ability to work with video format + audio_stream = + av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0); + if (audio_stream < 0) { + av_log(NULL, AV_LOG_ERROR, "Can't find audio stream in input file\n"); + result = audio_stream; + goto end; + } + + origin_par = fmt_ctx->streams[audio_stream]->codecpar; + st = fmt_ctx->streams[audio_stream]; + + result = av_dict_get_string(st->metadata, &metadata, '=', ':'); + if (result < 0) + goto end; + + printf("Stream ID: %d, codec name: %s, metadata: %s\n", audio_stream, + avcodec_get_name(origin_par->codec_id), metadata); + + codec = avcodec_find_decoder(origin_par->codec_id); + if (!codec) { + av_log(NULL, AV_LOG_ERROR, "Can't find decoder\n"); + result = AVERROR_DECODER_NOT_FOUND; + goto end; + } + + ctx = avcodec_alloc_context3(codec); + if (!ctx) { + av_log(NULL, AV_LOG_ERROR, "Can't allocate decoder context\n"); + result = AVERROR(ENOMEM); + goto end; + } + + result = avcodec_parameters_to_context(ctx, origin_par); + if (result) { + av_log(NULL, AV_LOG_ERROR, "Can't copy decoder context\n"); + goto end; + } + + result = avcodec_open2(ctx, codec, NULL); + if (result < 0) { + av_log(ctx, AV_LOG_ERROR, "Can't open decoder\n"); + goto end; + } + + pkt = av_packet_alloc(); + if (!pkt) { + av_log(NULL, AV_LOG_ERROR, "Cannot allocate packet\n"); + result = AVERROR(ENOMEM); + goto end; + } + + fr = av_frame_alloc(); + if (!fr) { + av_log(NULL, AV_LOG_ERROR, "Can't allocate frame\n"); + result = AVERROR(ENOMEM); + goto end; + } + + for (;;) { + result = av_read_frame(fmt_ctx, pkt); + if (result) + goto end; + + if (pkt->stream_index != audio_stream) { + av_packet_unref(pkt); + continue; + } + + printf("Stream ID: %d, packet PTS: %s, packet DTS: %s\n", + pkt->stream_index, av_ts2str(pkt->pts), av_ts2str(pkt->dts)); + + if (st->event_flags & AVSTREAM_EVENT_FLAG_METADATA_UPDATED) { + result = av_dict_get_string(st->metadata, &metadata, '=', ':'); + if (result < 0) + goto end; + + printf("Stream ID: %d, new metadata: %s\n", pkt->stream_index, + metadata); + + st->event_flags &= ~AVSTREAM_EVENT_FLAG_METADATA_UPDATED; + } + + result = avcodec_send_packet(ctx, pkt); + av_packet_unref(pkt); + + if (result < 0) + goto end; + + result = avcodec_receive_frame(ctx, fr); + if (result == AVERROR_EOF) { + result = 0; + goto end; + } + + if (result == AVERROR(EAGAIN)) + continue; + + result = av_dict_get_string(fr->metadata, &metadata, '=', ':'); + if (result < 0) + goto end; + + printf("Stream ID: %d, frame PTS: %s, metadata: %s\n", + pkt->stream_index, av_ts2str(fr->pts), metadata); + } + +end: + av_packet_free(&pkt); + av_frame_free(&fr); + avformat_close_input(&fmt_ctx); + avcodec_free_context(&ctx); + return result; +} + +int main(int argc, char **argv) { + if (argc < 2) { + av_log(NULL, AV_LOG_ERROR, "Incorrect input\n"); + return 1; + } + + if (dump_stream_meta(argv[1]) != AVERROR_EOF) + return 1; + + return 0; +} -- 2.39.5 (Apple Git-154) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".