[PATCH v2] Add option '--snapshot-format=' to allow write raw RGB directly to stdout

José Fonseca jose.r.fonseca at gmail.com
Tue Apr 23 00:47:15 PDT 2013


Just a few requests:
- Please make snapshotFormat global an enum, and do the string compare when
parsing the options.
- Please add an example to the README.markdown, just after "Recording a
video with FFmpeg" section.

Otherwise looks greast.

Given that raw does not encode the frame buffer size, and framebuffer sizes
are variable/fickle, I think a nice future improvement would be to allow
forcing the size on command line, to prevent video to go bust. For example:

  glretrace --snapshot-format=RGB:1920x1080 ...

Jose


On Fri, Apr 19, 2013 at 3:23 AM, Shuang He <shuang.he at intel.com> wrote:

> This allows to create h264 video with gstreamer-vaapi very fast, and save
> much more disk space.
> Using PNM format couldn't reach same performance, since PNM decoding seems
> inefficient in gstreamer.
> Following are some experiment data with smokinguns demo 1920x1080
> resolution on Ivybridge:
> 1. With png saving, it runs at around 4.5 FPS, which has compression rate
> 5.15x against raw RGB data
>    Reference command:
>         glretrace -s snapshot/ smokinguns.trace
>
> 2. Using PNM with gstreamer-vaapi, which could run at around 9 FPS, which
> has compression rate
>    485x (QP dependent) against raw RGB data.
>    Reference command:
>         glretrace -s - smokinguns.trace | gst-launch-0.10 fdsrc
> blocksize=409600 ! queue \
>         ! pnmdec ! videoparse format=rgb width=1920 height=1080 !
> ffmpegcolorspace ! queue \
>         ! vaapiupload direct-rendering=0 ! queue ! vaapiencodeh264 !
> filesink location=xxx.264
>
> 3. With following command that directly write raw RGB stream and encoded
> into H264 video, it
>    runs at around 18.5 FPS, which has compression rate 485x (QP dependent)
> against raw RGB data,
>    Reference command:
>         glretrace --snapshot-format=RGB -s - smokinguns.trace |
> gst-launch-0.10 fdsrc blocksize=409600 ! queue \
>         ! videoparse format=rgb width=1920 height=1080 ! queue !
> ffmpegcolorspace ! queue \
>         ! vaapiupload direct-rendering=0 ! queue ! vaapiencodeh264 !
> filesink location=xxx.264
>
> v2: Use --snapshot-format= option to specify which format is used to write
> to stdout output
> ---
>  image/CMakeLists.txt     |    1 +
>  image/image.hpp          |   13 +++++++++++++
>  image/image_raw.cpp      |   47
> ++++++++++++++++++++++++++++++++++++++++++++++
>  retrace/retrace_main.cpp |   12 +++++++++++-
>  4 files changed, 72 insertions(+), 1 deletion(-)
>  create mode 100644 image/image_raw.cpp
>
> diff --git a/image/CMakeLists.txt b/image/CMakeLists.txt
> index ee4d98f..37203f8 100644
> --- a/image/CMakeLists.txt
> +++ b/image/CMakeLists.txt
> @@ -7,6 +7,7 @@ add_library (image STATIC
>      image_bmp.cpp
>      image_png.cpp
>      image_pnm.cpp
> +    image_raw.cpp
>  )
>
>  target_link_libraries (image
> diff --git a/image/image.hpp b/image/image.hpp
> index 7dd18c1..11bfc63 100644
> --- a/image/image.hpp
> +++ b/image/image.hpp
> @@ -106,6 +106,19 @@ public:
>          return writePNG(os);
>      }
>
> +    void
> +    writeRAW(std::ostream &os) const;
> +
> +    inline bool
> +    writeRAW(const char *filename) const {
> +       std::ofstream os(filename, std::ofstream::binary);
> +       if (!os) {
> +           return false;
> +       }
> +       writeRAW(os);
> +       return true;
> +    }
> +
>      double compare(Image &ref);
>  };
>
> diff --git a/image/image_raw.cpp b/image/image_raw.cpp
> new file mode 100644
> index 0000000..dd45d10
> --- /dev/null
> +++ b/image/image_raw.cpp
> @@ -0,0 +1,47 @@
>
> +/**************************************************************************
> + *
> + * Copyright (C) 2013 Intel Corporation. All rights reversed.
> + * Author: Shuang He <shuang.he at intel.com>
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining
> a copy
> + * of this software and associated documentation files (the "Software"),
> to deal
> + * in the Software without restriction, including without limitation the
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or
> sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
> SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> IN
> + * THE SOFTWARE.
> + *
> +
> **************************************************************************/
> +
> +
> +#include <assert.h>
> +#include <string.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +
> +#include "image.hpp"
> +
> +
> +namespace image {
> +
> +void
> +Image::writeRAW(std::ostream &os) const {
> +    const unsigned char *row;
> +
> +    for (row = start(); row != end(); row += stride()) {
> +        os.write((const char *)row, width*channels);
> +    }
> +}
> +
> +} /* namespace image */
> diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp
> index 2d3311f..dbe34f8 100644
> --- a/retrace/retrace_main.cpp
> +++ b/retrace/retrace_main.cpp
> @@ -46,6 +46,7 @@ static bool loopOnFinish = false;
>
>  static const char *comparePrefix = NULL;
>  static const char *snapshotPrefix = NULL;
> +static const char *snapshotFormat = NULL;
>  static trace::CallSet snapshotFrequency;
>  static trace::CallSet compareFrequency;
>  static trace::ParseBookmark lastFrameStart;
> @@ -128,7 +129,10 @@ takeSnapshot(unsigned call_no) {
>              char comment[21];
>              snprintf(comment, sizeof comment, "%u",
>                       useCallNos ? call_no : snapshot_no);
> -            src->writePNM(std::cout, comment);
> +            if (snapshotFormat != NULL && strcmp(snapshotFormat, "RGB")
> == 0)
> +                src->writeRAW(std::cout);
> +            else
> +                src->writePNM(std::cout, comment);
>          } else {
>              os::String filename = os::String::format("%s%010u.png",
>                                                       snapshotPrefix,
> @@ -567,6 +571,7 @@ usage(const char *argv0) {
>          "      --driver=DRIVER     force driver type (`hw`, `sw`, `ref`,
> `null`, or driver module name)\n"
>          "      --sb                use a single buffer visual\n"
>          "  -s, --snapshot-prefix=PREFIX    take snapshots; `-` for PNM
> stdout output\n"
> +        "      --snapshot-format=FMT       use (PNM or RGB; default is
> PNM) when writing to stdout output\n"
>          "  -S, --snapshot=CALLSET  calls to snapshot (default is every
> frame)\n"
>          "  -v, --verbose           increase output verbosity\n"
>          "  -D, --dump-state=CALL   dump state at specific call no\n"
> @@ -585,6 +590,7 @@ enum {
>      PPD_OPT,
>      PMEM_OPT,
>      SB_OPT,
> +    SNAPSHOT_FORMAT_OPT,
>      LOOP_OPT,
>      SINGLETHREAD_OPT
>  };
> @@ -609,6 +615,7 @@ longOptions[] = {
>      {"pmem", no_argument, 0, PMEM_OPT},
>      {"sb", no_argument, 0, SB_OPT},
>      {"snapshot-prefix", required_argument, 0, 's'},
> +    {"snapshot-format", required_argument, 0, SNAPSHOT_FORMAT_OPT},
>      {"snapshot", required_argument, 0, 'S'},
>      {"verbose", no_argument, 0, 'v'},
>      {"wait", no_argument, 0, 'w'},
> @@ -699,6 +706,9 @@ int main(int argc, char **argv)
>                  retrace::verbosity = -2;
>              }
>              break;
> +       case SNAPSHOT_FORMAT_OPT:
> +           snapshotFormat = optarg;
> +           break;
>          case 'S':
>              snapshotFrequency = trace::CallSet(optarg);
>              if (snapshotPrefix == NULL) {
> --
> 1.7.10.1
>
> _______________________________________________
> apitrace mailing list
> apitrace at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/apitrace
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/apitrace/attachments/20130423/b336e8fa/attachment.html>


More information about the apitrace mailing list