summaryrefslogtreecommitdiff
path: root/fftools/ffprobe.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-03-09 16:59:12 +0100
committerAnton Khirnov <anton@khirnov.net>2023-03-20 10:42:09 +0100
commite6126abc6997058ca49ee596b70611bbe367163e (patch)
treed291ee8ee6fd8e657264c6c6fdba6c29e73033ff /fftools/ffprobe.c
parent0ad64cdd92a132b57748bd8b84db955e1369f74e (diff)
fftools/ffprobe: stop using AVFrame.pkt_{pos,size}
These fields are ad-hoc and will be deprecated. Use the recently-added AV_CODEC_FLAG_COPY_OPAQUE to pass arbitrary user data from packets to frames. Changes the result of the flcl1905 test, which uses ffprobe to decode wmav2 with multiple frames per packet. Such packets are handled internally by calling the decoder's decode callback multiple times, offsetting the internal packet's data pointer and decreasing its size after each call. The output pkt_size value before this commit is then the remaining internal packet size at the time of each internal decode call. After this commit, output pkt_size is simply the size of the full packet submitted by the caller to the decoder. This is more correct, since internal packets are never seen by the caller and should have no observable outside effects.
Diffstat (limited to 'fftools/ffprobe.c')
-rw-r--r--fftools/ffprobe.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 969fa1b9f8..95dda97edc 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -79,6 +79,12 @@
# define pthread_mutex_unlock(a) do{}while(0)
#endif
+// attached as opaque_ref to packets/frames
+typedef struct FrameData {
+ int64_t pkt_pos;
+ int pkt_size;
+} FrameData;
+
typedef struct InputStream {
AVStream *st;
@@ -2571,6 +2577,7 @@ static void show_subtitle(WriterContext *w, AVSubtitle *sub, AVStream *stream,
static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
AVFormatContext *fmt_ctx)
{
+ FrameData *fd = frame->opaque_ref ? (FrameData*)frame->opaque_ref->data : NULL;
AVBPrint pbuf;
char val_str[128];
const char *s;
@@ -2599,10 +2606,10 @@ static void show_frame(WriterContext *w, AVFrame *frame, AVStream *stream,
#endif
print_duration_ts ("duration", frame->duration);
print_duration_time("duration_time", frame->duration, &stream->time_base);
- if (frame->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, frame->pkt_pos);
- else print_str_opt("pkt_pos", "N/A");
- if (frame->pkt_size != -1) print_val ("pkt_size", frame->pkt_size, unit_byte_str);
- else print_str_opt("pkt_size", "N/A");
+ if (fd && fd->pkt_pos != -1) print_fmt ("pkt_pos", "%"PRId64, fd->pkt_pos);
+ else print_str_opt("pkt_pos", "N/A");
+ if (fd && fd->pkt_size != -1) print_val ("pkt_size", fd->pkt_size, unit_byte_str);
+ else print_str_opt("pkt_size", "N/A");
switch (stream->codecpar->codec_type) {
AVRational sar;
@@ -2911,6 +2918,15 @@ static int read_interval_packets(WriterContext *w, InputFile *ifile,
}
if (do_read_frames) {
int packet_new = 1;
+ FrameData *fd;
+
+ pkt->opaque_ref = av_buffer_allocz(sizeof(*fd));
+ if (!pkt->opaque_ref)
+ return AVERROR(ENOMEM);
+ fd = (FrameData*)pkt->opaque_ref->data;
+ fd->pkt_pos = pkt->pos;
+ fd->pkt_size = pkt->size;
+
while (process_frame(w, ifile, frame, pkt, &packet_new) > 0);
}
}
@@ -3405,6 +3421,8 @@ static int open_input_file(InputFile *ifile, const char *filename,
av_dict_set(&codec_opts, "threads", "1", 0);
}
+ av_dict_set(&opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
+
ist->dec_ctx->pkt_timebase = stream->time_base;
if (avcodec_open2(ist->dec_ctx, codec, &opts) < 0) {