From: Shuang He Date: Wed, 24 Apr 2013 02:01:15 +0000 (+0800) Subject: Add option '--snapshot-format=' to allow write raw RGB directly to stdout X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=90808c138de511a81b6b85d22a9400007d91336b;p=apitrace Add option '--snapshot-format=' to allow write raw RGB directly to stdout 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 v3: Use enum for snapshotFormat and add example in README.markdown --- diff --git a/README.markdown b/README.markdown index 7545982..03f9e88 100644 --- a/README.markdown +++ b/README.markdown @@ -277,6 +277,14 @@ You can make a video of the output by doing apitrace dump-images -o - application.trace \ | ffmpeg -r 30 -f image2pipe -vcodec ppm -i pipe: -vcodec mpeg4 -y output.mp4 +Recording a video with gstreamer +-------------------------------------- + +You can make a video of the output with gstreamer by doing + + 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 Trimming a trace ---------------- 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 + * 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 +#include +#include +#include + +#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..492deca 100644 --- a/retrace/retrace_main.cpp +++ b/retrace/retrace_main.cpp @@ -46,6 +46,11 @@ static bool loopOnFinish = false; static const char *comparePrefix = NULL; static const char *snapshotPrefix = NULL; +static enum { + PNM_FMT, + RAW_RGB +} snapshotFormat = PNM_FMT; + static trace::CallSet snapshotFrequency; static trace::CallSet compareFrequency; static trace::ParseBookmark lastFrameStart; @@ -128,7 +133,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 == RAW_RGB) + src->writeRAW(std::cout); + else + src->writePNM(std::cout, comment); } else { os::String filename = os::String::format("%s%010u.png", snapshotPrefix, @@ -567,6 +575,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 +594,7 @@ enum { PPD_OPT, PMEM_OPT, SB_OPT, + SNAPSHOT_FORMAT_OPT, LOOP_OPT, SINGLETHREAD_OPT }; @@ -609,6 +619,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 +710,12 @@ int main(int argc, char **argv) retrace::verbosity = -2; } break; + case SNAPSHOT_FORMAT_OPT: + if (strcmp(optarg, "RGB") == 0) + snapshotFormat = RAW_RGB; + else + snapshotFormat = PNM_FMT; + break; case 'S': snapshotFrequency = trace::CallSet(optarg); if (snapshotPrefix == NULL) {