mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
1ef13dda12
Previously, we would create a new GstMemory per write operation and then append them to the GstBuffer. This would cause a reallocation every 16 Memories which is an issue since the png encoder will usually do write in a pattern of 4, 8 and 8k bytes repeating until the frame is done. Instead allocate a single GstMemory and keep writting it into it with a manual index. Much like the jpegenc does. Doing some basic testing With a testsrc snow pattern at 4k and 8k the same pipeline would take ~3.30s to encode a 4k frame and ~23s for an 8k. At 4k 0.70s/33% is taken by memory allocations, while at 8k its ~10.5s/45%. With this patch, at 4k the pipeline takes ~2.40s and at 8k only 9.60s making this 28% and 58% faster accordingly on my laptop, and allocation runtime is dropped to subsecond times. Here's the test pipeline used, increase num-buffers in image freeze to gather more samples. ``` gst-launch-1.0 videotestsrc num-buffers=1 pattern=snow ! imagefreeze num-buffers=1 ! \ video/x-raw,width=7680,height=4320 ! pngenc ! fakesink ``` Close #2717 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4944>
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
/* GStreamer
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
* Copyright (C) 2012 Collabora Ltd.
|
|
* Author : Edward Hervey <edward@collabora.com>
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
* Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
|
|
#ifndef __GST_PNGENC_H__
|
|
#define __GST_PNGENC_H__
|
|
|
|
#include <gst/gst.h>
|
|
#include <gst/video/gstvideoencoder.h>
|
|
#include <png.h>
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GST_TYPE_PNGENC (gst_pngenc_get_type())
|
|
G_DECLARE_FINAL_TYPE (GstPngEnc, gst_pngenc, GST, PNGENC, GstVideoEncoder)
|
|
|
|
struct _GstPngEnc
|
|
{
|
|
GstVideoEncoder parent;
|
|
|
|
GstVideoCodecState *input_state;
|
|
|
|
GstMemory *output_mem;
|
|
GstMapInfo output_map;
|
|
gsize output_mem_pos;
|
|
|
|
png_structp png_struct_ptr;
|
|
png_infop png_info_ptr;
|
|
|
|
gint png_color_type;
|
|
gint depth;
|
|
guint compression_level;
|
|
|
|
gboolean snapshot;
|
|
gboolean newmedia;
|
|
};
|
|
|
|
GST_ELEMENT_REGISTER_DECLARE (pngenc);
|
|
|
|
G_END_DECLS
|
|
|
|
#endif /* __GST_PNGENC_H__ */
|