[FFmpeg-devel] [PATCH 6/7] tools/uncoded_frame: use AV_BUFFERSINK_FLAG_PARAMS
Anton Khirnov
anton at khirnov.net
Mon Sep 23 18:01:44 EEST 2024
---
tools/uncoded_frame.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/tools/uncoded_frame.c b/tools/uncoded_frame.c
index a17d406417..39818963d0 100644
--- a/tools/uncoded_frame.c
+++ b/tools/uncoded_frame.c
@@ -153,6 +153,13 @@ int main(int argc, char **argv)
for (; i < nb_streams; i++)
streams[i].mux = streams[0].mux;
+ frame = av_frame_alloc();
+ if (!frame) {
+ ret = AVERROR(ENOMEM);
+ av_log(NULL, AV_LOG_ERROR, "Could not allocate frame\n");
+ goto fail;
+ }
+
/* Create output device streams */
for (i = 0; i < nb_streams; i++) {
st = &streams[i];
@@ -161,29 +168,34 @@ int main(int argc, char **argv)
av_log(NULL, AV_LOG_ERROR, "Failed to create output stream\n");
goto fail;
}
+
+ ret = av_buffersink_get_frame_flags(st->sink, frame, AV_BUFFERSINK_FLAG_PARAMS);
+ if (ret < 0)
+ goto fail;
+
st->stream->codecpar->codec_type = av_buffersink_get_type(st->sink);
- st->stream->time_base = av_buffersink_get_time_base(st->sink);
+ st->stream->time_base = frame->time_base;
switch (av_buffersink_get_type(st->sink)) {
case AVMEDIA_TYPE_VIDEO:
st->stream->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
st->stream->avg_frame_rate =
st->stream-> r_frame_rate = av_buffersink_get_frame_rate(st->sink);
- st->stream->codecpar->width = av_buffersink_get_w(st->sink);
- st->stream->codecpar->height = av_buffersink_get_h(st->sink);
- st->stream->codecpar->sample_aspect_ratio = av_buffersink_get_sample_aspect_ratio(st->sink);
- st->stream->codecpar->format = av_buffersink_get_format(st->sink);
+ st->stream->codecpar->width = frame->width;
+ st->stream->codecpar->height = frame->height;
+ st->stream->codecpar->sample_aspect_ratio = frame->sample_aspect_ratio;
+ st->stream->codecpar->format = frame->format;
break;
case AVMEDIA_TYPE_AUDIO:
- ret = av_buffersink_get_ch_layout(st->sink, &st->stream->codecpar->ch_layout);
- if (ret < 0)
- goto fail;
- st->stream->codecpar->sample_rate = av_buffersink_get_sample_rate(st->sink);
- st->stream->codecpar->format = av_buffersink_get_format(st->sink);
+ FFSWAP(AVChannelLayout, st->stream->codecpar->ch_layout, frame->ch_layout);
+ st->stream->codecpar->sample_rate = frame->sample_rate;
+ st->stream->codecpar->format = frame->format;
st->stream->codecpar->codec_id = av_get_pcm_codec(st->stream->codecpar->format, -1);
break;
default:
av_assert0(!"reached");
}
+
+ av_frame_unref(frame);
}
/* Init output devices */
@@ -222,11 +234,6 @@ int main(int argc, char **argv)
for (i = 0; i < nb_streams; i++) {
st = &streams[i];
while (1) {
- if (!frame && !(frame = av_frame_alloc())) {
- ret = AVERROR(ENOMEM);
- av_log(NULL, AV_LOG_ERROR, "Could not allocate frame\n");
- goto fail;
- }
ret = av_buffersink_get_frame_flags(st->sink, frame,
AV_BUFFERSINK_FLAG_NO_REQUEST);
if (ret < 0) {
--
2.43.0
More information about the ffmpeg-devel
mailing list