snapshot: fix snapshots cropping
authorRomain Vimont <rom@rom1v.com>
Mon, 6 Nov 2017 10:06:20 +0000 (11:06 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 6 Nov 2017 15:30:55 +0000 (16:30 +0100)
The snapshot picture was created using picture_Copy(), which does not
handle offsets. As a consequence, snapshots of cropped videos were
broken.

Use picture_Clone() (shallow copy) instead, then copy the crop settings
from the format.

Fixes #18970

Signed-off-by: Romain Vimont <rom@rom1v.com>
Acked-by: Thomas Guillem <thomas@gllm.fr>
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
src/misc/image.c
src/video_output/snapshot.c
src/video_output/snapshot.h

index aa5dd43..7c3ad99 100644 (file)
@@ -778,6 +778,11 @@ static filter_t *CreateFilter( vlc_object_t *p_this, const es_format_t *p_fmt_in
     es_format_Copy( &p_filter->fmt_in, p_fmt_in );
     es_format_Copy( &p_filter->fmt_out, p_fmt_in );
     video_format_Copy( &p_filter->fmt_out.video, p_fmt_out );
+
+    /* whatever the input offset, write at offset 0 in the target image */
+    p_filter->fmt_out.video.i_x_offset = 0;
+    p_filter->fmt_out.video.i_y_offset = 0;
+
     p_filter->fmt_out.i_codec = p_fmt_out->i_chroma;
     p_filter->p_module = module_need( p_filter, "video converter", NULL, false );
 
index ceade00..f9bc106 100644 (file)
@@ -112,18 +112,18 @@ bool vout_snapshot_IsRequested(vout_snapshot_t *snap)
 }
 void vout_snapshot_Set(vout_snapshot_t *snap,
                        const video_format_t *fmt,
-                       const picture_t *picture)
+                       picture_t *picture)
 {
     if (!fmt)
         fmt = &picture->format;
 
     vlc_mutex_lock(&snap->lock);
     while (snap->request_count > 0) {
-        picture_t *dup = picture_NewFromFormat(fmt);
+        picture_t *dup = picture_Clone(picture);
         if (!dup)
             break;
 
-        picture_Copy(dup, picture);
+        video_format_CopyCrop( &dup->format, fmt );
 
         dup->p_next = snap->picture;
         snap->picture = dup;
index b27a721..3085d50 100644 (file)
@@ -53,11 +53,11 @@ bool vout_snapshot_IsRequested(vout_snapshot_t *);
 /**
  * It set the picture used to create the snapshots.
  *
- * The given picture is only copied and not released.
+ * The given picture is cloned.
  * If p_fmt is non NULL it will override the format of the p_picture (mainly
  * used because of aspect/crop problems).
  */
-void vout_snapshot_Set(vout_snapshot_t *, const video_format_t *, const picture_t *);
+void vout_snapshot_Set(vout_snapshot_t *, const video_format_t *, picture_t *);
 
 /**
  * This function will return the directory used for snapshots