Skip to content

Commit

Permalink
added thumbnail generator filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Mar 29, 2022
1 parent f7baad5 commit b8959e1
Show file tree
Hide file tree
Showing 11 changed files with 1,068 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/xcode/gpac.xcodeproj/project.pbxproj
Expand Up @@ -2022,7 +2022,6 @@
92F8D47E1F71643600616F7C /* filters */ = {
isa = PBXGroup;
children = (
9272B50327E34CDF00D9D304 /* mux_ogg.c */,
925E564B2798B87300BBD530 /* bs_agg.c */,
926D48FC27957D8400E3C68C /* bs_split.c */,
9274295724647AB8009ADD8D /* bsrw.c */,
Expand Down Expand Up @@ -2081,6 +2080,7 @@
922E29812051940C00C8DCBB /* mux_avi.c */,
9206823320EA96AA0041169F /* mux_gsf.c */,
9290F5101FAB4C2C0038C30D /* mux_isom.c */,
9272B50327E34CDF00D9D304 /* mux_ogg.c */,
9256B38A208662FB00088537 /* mux_ts.c */,
92E164AE20F8EBB60024A9CA /* nvdec */,
922E29822051940C00C8DCBB /* out_audio.c */,
Expand Down
10 changes: 10 additions & 0 deletions share/doc/idl/evg.idl
Expand Up @@ -1117,6 +1117,16 @@ interface Texture {
\return the converted value
*/
Object get_pixel(unsigned long x, unsigned long y, optional bool as_array=false);

/*! gets MAE (Mean Absolute Error) and/or MSE (Mean Square Error) metric of texture compared with another texture. Both textures shall have the same size and pixel format.
\param diff_with texture to compute difference with
\param mode string indicating metric(s) to compute as a comma-separated list. Currently only 'mae' and 'mse' are supported.
\param split_planes if true, metrics are computed per plane, otherwise averaged on all planes. For YUV textures, if this is not set, metric is only computed on luma plane and alpha plane if present.
\return an array of object, each containing 'mae' and 'mse' properties. Values are numbers between 0 (all identical) and 100 (all pixels have full intensity difference).

If split_planes is false, the array contains a single object. Otherwise, it contains 4 objects if alpha plane or 3 otherwise, in {R,G,B,A} or {Y,U,V,A} order.
*/
Array diff_score(Texture diff_with, optional DOMString mode="mae", optional boolean split_planes=false);
};

/*! convolution kernel interface*/
Expand Down
199 changes: 198 additions & 1 deletion share/doc/man/gpac-filters.1
Expand Up @@ -8179,6 +8179,201 @@ force_stereo (bool, default: true): use stereo output for multiview (top-bottom
reset_switch (bool, default: false): reset decoder at config change
.br

.br
.SH thumbs
.LP
.br
Description: Thumbnail collection generator
.br
Version: 1.0
.br
Author: GPAC team
.br

.br
This filter generates screenshots from a video stream.
.br

.br
The input video is downsampled by the .I scale factor. The output size is configured based on the number of images per line and per column in the .I grid.
.br
Once configured, the output size is no longer modified.
.br

.br
The .I snap option indicates to use one video frame every given seconds. If value is 0, all input frames are used.
.br

.br
If the number of rows is 0, it will be computed based on the source duration and desired .I snap time, and will default to 10 if it cannot be resolved.
.br

.br
To output one image per input frame, use :grid=1x1.
.br

.br
If a single image per output frame is used, the default value for .I snap is 0 and for .I scale is 1.
.br
Otherwise, the default value for .I snap is 1 second and for .I scale is 10.
.br

.br
A single line of text can be inserted over each frame. Predefined keywords can be used in input text, identified as $KEYWORD$:
.br
* ts: replaced by packet timestamp
.br
* timescale: replaced by PID timescale
.br
* time: replaced by packet time as HH:MM:SS.ms
.br
* cpu: replaced by current CPU usage of process
.br
* mem: replaced by current memory usage of process
.br
* version: replaced by GPAC version
.br
* fversion: replaced by GPAC full version
.br
* mae: replaced by Mean Absolute Error with previous frame
.br
* mse: replaced by Mean Square Error with previous frame
.br
* P4CC, PropName: replaced by corresponding PID property
.br

.br
Example
.br
gpac -i src reframer:saps=1 thumbs:snap=30:grid=6x30 -o dump/$num$.png
.br

.br
This will generate images from key-frames only, inserting one image every 30 seconds. Using key-frame filtering is much faster but may give unexpected results if there are not enough key-frames in the source.
.br

.br
Example
.br
gpac -i src thumbs:snap=0:grid=5x5 -o dump/$num$.png
.br

.br
This will generate one image containing 25 frames every second at 25 fps.
.br

.br
If a single image per output frame is used and the scaling factor is 1, the input packet is reused as input with text and graphics overlaid.
.br

.br
Example
.br
gpac -i src thumbs:grid=1x1:txt='Frame $time$' -o dump/$num$.png
.br

.br
This will inject text over each frame and keep timing and other packet properties.
.br

.br
A json output can be specified in input .I list to let applications retrieve frame position in output image from its timing.
.br

.br
.SH Scene change detection
.LP
.br

.br
The filter can compute the absolute and/or square error metrics between consecutive images and drop image if the computed metric is less than the given threshold.
.br
If both .I mae and .I mse thresholds are 0, scene detection is not performed (default).
.br
If both .I mae and .I mse thresholds are not 0, the frame is added if it passes both thresholds.
.br

.br
For both metrics, a value of 0 means all pixels are the same, a value of 100 means all pixels have 100% intensity difference (e.g. black versus white).
.br

.br
The scene detection is performed after the .I snap filtering and uses:
.br
- the previous frame in the stream, whether it was added or not, if .I scref is not set,
.br
- the last added frame otherwise.
.br

.br
Typical thresholds for scene cut detection are 14 to 20 for .I mae and 5 to 7 for .I mse.
.br

.br
Since this is a costly process, it is recommended to use it combined with key-frames selection:
.br

.br
Example
.br
gpac -i src reframer:saps=1 thumbs:mae=15 -o dump/$num$.png
.br

.br

.br
The .I maxsnap option can be used to force insertion after the given time if no scene cut is found.
.br

.br
.SH Options (expert):
.LP
.br
grid (v2di, default: 6x0): number of images per lines and columns
.br
scale (dbl, default: -1): scale factor for input size
.br
mae (uint, default: 0, minmax: 0,100): scene diff threshold using Mean Absolute Error
.br
mse (uint, default: 0, minmax: 0,100): scene diff threshold using Mean Square Error
.br
lw (dbl, default: 0.0): line width between images in pixels
.br
lc (str, default: white): line color
.br
clear (str, default: white): clear color
.br
snap (dbl, default: -1): duration between images, 0 for all images
.br
maxsnap (dbl, default: -1): maximum duration between two thumbnails when scene change detection is enabled
.br
pfmt (pfmt, default: rgb): output pixel format
.br
txt (str, default: ): text to insert per thumbnail
.br
tc (str, default: white): text color
.br
tb (str, default: black): text shadow
.br
font (str, default: SANS): font to use
.br
fs (dbl, default: 10): font size to use in percent of scaled height
.br
tv (dbl, default: 0): text vertical position in percent of scaled height
.br
thread (sint, default: -1): number of threads for software rasterizer, -1 for all available cores
.br
blt (bool, default: true): use blit instead of software rasterizer
.br
scref (bool, default: false): use last inserted image as reference for scene change detection
.br
dropfirst (bool, default: false): drop first image
.br
list (str, default: null): export json list of frame times and positions to given file
.br
lxy (bool, default: false): add explict x and y in json export
.br

.br
.SH avmix
.LP
Expand Down Expand Up @@ -9581,6 +9776,8 @@ Predefined keywords can be used in input text, identified as $KEYWORD$. The foll
.br
* fversion: replaced by GPAC full version
.br
* P4CC, PropName: replaced by corresponding PID property
.br

.br
.SS Custom paths
Expand Down Expand Up @@ -10123,7 +10320,7 @@ Authors: GPAC developers, see git repo history (-log)
.br
For bug reports, feature requests, more information and source code, visit https://github.com/gpac/gpac
.br
build: 2.1-DEV-rev77-gf671116f3-master
build: 2.1-DEV-rev80-gf7baad5d7-master
.br
Copyright: (c) 2000-2022 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
.br
Expand Down
2 changes: 1 addition & 1 deletion share/doc/man/gpac.1
Expand Up @@ -4603,7 +4603,7 @@ Authors: GPAC developers, see git repo history (-log)
.br
For bug reports, feature requests, more information and source code, visit https://github.com/gpac/gpac
.br
build: 2.1-DEV-rev77-gf671116f3-master
build: 2.1-DEV-rev80-gf7baad5d7-master
.br
Copyright: (c) 2000-2022 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
.br
Expand Down
2 changes: 1 addition & 1 deletion share/doc/man/mp4box.1
Expand Up @@ -2837,7 +2837,7 @@ Authors: GPAC developers, see git repo history (-log)
.br
For bug reports, feature requests, more information and source code, visit https://github.com/gpac/gpac
.br
build: 2.1-DEV-rev77-gf671116f3-master
build: 2.1-DEV-rev80-gf7baad5d7-master
.br
Copyright: (c) 2000-2022 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
.br
Expand Down
2 changes: 1 addition & 1 deletion share/doc/man/mp4client.1
Expand Up @@ -257,7 +257,7 @@ Authors: GPAC developers, see git repo history (-log)
.br
For bug reports, feature requests, more information and source code, visit https://github.com/gpac/gpac
.br
build: 2.1-DEV-rev77-gf671116f3-master
build: 2.1-DEV-rev80-gf7baad5d7-master
.br
Copyright: (c) 2000-2022 Telecom Paris distributed under LGPL v2.1+ - http://gpac.io
.br
Expand Down
11 changes: 11 additions & 0 deletions share/scripts/jsf/avmix/scenes/shape.js
Expand Up @@ -47,6 +47,7 @@ Predefined keywords can be used in input text, identified as \`$KEYWORD$\`. The
- mem: replaced by current memory usage of process
- version: replaced by GPAC version
- fversion: replaced by GPAC full version
- P4CC, PropName: replaced by corresponding PID property
## Custom paths
Expand Down Expand Up @@ -578,7 +579,17 @@ function set_text(txt)
}
else if (kword=='fversion') {
item = sys.version_full;
} else {
try {
let p = ipid.get_prop(item);
if (!p) p = ipid.get_info(item);
if (typeof p != 'undefined') {
if (p==null) item = 'n/a';
else item = '' + p;
}
} catch (e) {}
}

new_line += item;

if (timeout) {
Expand Down

0 comments on commit b8959e1

Please sign in to comment.