History

avformat/mov: parse clap boxes that reference heif items

James Almer committed 2 years ago

Commit f225e6f1 parent ba6eeb21 file · +22 −10Browse files

Unified · Split

libavformat/mov.c+22−10
@@ -1234,14 +1234,26 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1233 unmodified lines
12341234 static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
12351235 {
12361236 AVStream *st;
1237+ HEIFItem *item;
12371238 AVPacketSideData *sd;
1239+ int width, height;
12381240 AVRational aperture_width, aperture_height, horiz_off, vert_off;
12391241 AVRational pc_x, pc_y;
12401242 uint64_t top, bottom, left, right;
12411243
1242− if (c->fc->nb_streams < 1)
1244+ item = heif_cur_item(c);
1245+ st = get_curr_st(c);
1246+ if (!st)
12431247 return 0;
1244− st = c->fc->streams[c->fc->nb_streams-1];
1248+
1249+ width = st->codecpar->width;
1250+ height = st->codecpar->height;
1251+ if ((!width || !height) && item) {
1252+ width = item->width;
1253+ height = item->height;
1254+ }
1255+ if (!width || !height)
1256+ return AVERROR_INVALIDDATA;
12451257
12461258 aperture_width.num = avio_rb32(pb);
12471259 aperture_width.den = avio_rb32(pb);
@@ -1263,9 +1275,9 @@ static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 15 unmodified lines
12631275 aperture_width.num, aperture_width.den, aperture_height.num, aperture_height.den,
12641276 horiz_off.num, horiz_off.den, vert_off.num, vert_off.den);
12651277
1266− pc_x = av_mul_q((AVRational) { st->codecpar->width - 1, 1 }, (AVRational) { 1, 2 });
1278+ pc_x = av_mul_q((AVRational) { width - 1, 1 }, (AVRational) { 1, 2 });
12671279 pc_x = av_add_q(pc_x, horiz_off);
1268− pc_y = av_mul_q((AVRational) { st->codecpar->height - 1, 1 }, (AVRational) { 1, 2 });
1280+ pc_y = av_mul_q((AVRational) { height - 1, 1 }, (AVRational) { 1, 2 });
12691281 pc_y = av_add_q(pc_y, vert_off);
12701282
12711283 aperture_width = av_sub_q(aperture_width, (AVRational) { 1, 1 });
@@ -1278,18 +1290,18 @@ static int mov_read_clap(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 6 unmodified lines
12781290 top = av_q2d(av_sub_q(pc_y, aperture_height));
12791291 bottom = av_q2d(av_add_q(pc_y, aperture_height));
12801292
1281− if (bottom > (st->codecpar->height - 1) ||
1282− right > (st->codecpar->width - 1))
1293+ if (bottom > (height - 1) ||
1294+ right > (width - 1))
12831295 return AVERROR_INVALIDDATA;
12841296
1285− bottom = st->codecpar->height - 1 - bottom;
1286− right = st->codecpar->width - 1 - right;
1297+ bottom = height - 1 - bottom;
1298+ right = width - 1 - right;
12871299
12881300 if (!(left | right | top | bottom))
12891301 return 0;
12901302
1291− if ((left + right) >= st->codecpar->width ||
1292− (top + bottom) >= st->codecpar->height)
1303+ if ((left + right) >= width ||
1304+ (top + bottom) >= height)
12931305 return AVERROR_INVALIDDATA;
12941306
12951307 sd = av_packet_side_data_new(&st->codecpar->coded_side_data,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t