Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/d_main.c ./src/d_main.c
- 94a95,97
- > // NSM
- > #include "i_capture.h"
- >
- 471a475,480
- > // NSM
- > if (capturing_video && !doSkip)
- > {
- > I_CaptureFrame ();
- > }
- >
- 1655a1665,1673
- > // NSM
- > if ((p = M_CheckParm("-viddump")) && (p < myargc-1))
- > {
- > I_CapturePrep (myargv[p + 1]);
- > }
- >
- >
- >
- >
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/g_game.c ./src/g_game.c
- 87a88,89
- > #include "i_capture.h" // NSM
- >
- 3480a3483,3490
- > // NSM
- > if (capturing_video)
- > {
- > I_CaptureFinish ();
- > // supress I_Error since it needs to be clicked (in windows anyway),
- > // so causes problems with batch conversion
- > I_SafeExit (0);
- > }
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_capture.c ./src/i_capture.c
- 0a1,392
- > /* Emacs style mode select -*- C++ -*-
- > *-----------------------------------------------------------------------------
- > *
- > *
- > * PrBoom: a Doom port merged with LxDoom and LSDLDoom
- > * based on BOOM, a modified and improved DOOM engine
- > * Copyright (C) 1999 by
- > * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
- > * Copyright (C) 1999-2000 by
- > * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
- > * Copyright 2005, 2006 by
- > * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
- > * Copyright 2007 by
- > * Andrey Budko, Roman Marchenko
- > *
- > * This program is free software; you can redistribute it and/or
- > * modify it under the terms of the GNU General Public License
- > * as published by the Free Software Foundation; either version 2
- > * of the License, or (at your option) any later version.
- > *
- > * This program 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 General Public License for more details.
- > *
- > * You should have received a copy of the GNU General Public License
- > * along with this program; if not, write to the Free Software
- > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- > * 02111-1307, USA.
- > *
- > * DESCRIPTION:
- > *
- > *---------------------------------------------------------------------
- > */
- >
- > #include <stdio.h>
- > #include <stdlib.h>
- > #include "i_sound.h"
- > #include "i_video.h"
- > #include "lprintf.h"
- >
- >
- >
- >
- > static const char *vid_fname;
- >
- > static FILE *sndfile;
- > static void *sndfileinfo;
- > static FILE *vidfile;
- > static void *vidfileinfo;
- >
- > // %w video width (px)
- > // %h video height (px)
- > // %s sound rate (hz)
- > // %f filename passed to -viddump
- > // %% single percent sign
- >
- > const char *cap_soundcommand;
- > const char *cap_videocommand;
- > const char *cap_muxcommand;
- > const char *cap_tempfile1;
- > const char *cap_tempfile2;
- >
- > //static const char *sndcommandin = "ffmpeg -f s16le -ar %s -ac 2 -i pipe:0 -acodec libvorbis -f ogg output.ogg";
- > //static const char *sndcommandin = "ffmpeg -f s16le -ar %s -ac 2 -i pipe:0 -acodec pcm_s16le output.wav";
- > // todo: add aspect ratio information
- > //static const char *vidcommandin = "ffmpeg -f rawvideo -pix_fmt rgb24 -s %wx%h -r 35 -i pipe:0 -vcodec libx264 -f mp4 -fpre ./libx264-baseline.ffpreset -crf 22 output.mp4";
- > //static const char *vidcommandin = "ffmpeg -f rawvideo -pix_fmt rgb24 -s %wx%h -r 35 -i pipe:0 -f null fubar.out";
- > //static const char *fincommandin = "ffmpeg -i output.ogg -i output.mp4 -vcodec copy -acodec copy %f";
- > //static const char *fincommandin = "ffmpeg -formats";
- >
- >
- > // parsed versions
- > static char sndcommand[MAX_PATH];
- > static char vidcommand[MAX_PATH];
- > static char muxcommand[MAX_PATH];
- >
- > // parses a command with simple printf-style replacements.
- > static int parsecommand (char *out, const char *in, int len)
- > {
- > int i;
- >
- > char *buff = malloc (len);
- >
- > if (!buff)
- > return 0;
- >
- > while (*in && len > 1)
- > {
- > if (*in == '%')
- > {
- > switch (in[1])
- > {
- > case 'w':
- > i = snprintf (out, len, "%u", SCREENWIDTH);
- > break;
- > case 'h':
- > i = snprintf (out, len, "%u", SCREENHEIGHT);
- > break;
- > case 's':
- > i = snprintf (out, len, "%u", snd_samplerate);
- > break;
- > case 'f':
- > i = snprintf (out, len, "%s", vid_fname);
- > break;
- > case '%':
- > i = snprintf (out, len, "%%");
- > break;
- > default:
- > return 0;
- > }
- > out += i;
- > len -= i;
- > in += 2;
- > }
- > else
- > {
- > *out++ = *in++;
- > len--;
- > }
- > }
- > if (*in || len < 1)
- > { // out of space
- > return 0;
- > }
- > *out = 0;
- > return 1;
- > }
- >
- >
- > int capturing_video = 0;
- >
- >
- >
- >
- > // popen replacement for w32
- >
- > #ifdef _WIN32
- > #if 0
- > // this works, but it spawns unnessecary cmd.exe menus, and the winapi ref says it's depreciated
- > // and unsafe for non-console apps to call
- >
- > static FILE *my_popen (const char *cmd, void **finfo)
- > {
- > return _popen (cmd, "wb");
- > }
- > static void my_pclose (FILE *f, void *finfo)
- > {
- > _pclose (f);
- > }
- >
- > #else // #if 0
- > // direct winapi implementation
- >
- > #define WIN32_LEAN_AND_MEAN
- > #include <windows.h>
- > #include <io.h>
- >
- > typedef struct
- > {
- > HANDLE pipe[2];
- > HANDLE proc;
- > HANDLE thread;
- > } pinfo_t;
- >
- > // extra pointer is used to hold process id to wait on to close
- > static FILE *my_popen (const char *cmd, void **finfo)
- > {
- > FILE *f = NULL;
- > pinfo_t *pinfo;
- >
- >
- > PROCESS_INFORMATION piProcInfo;
- > STARTUPINFO siStartInfo;
- > SECURITY_ATTRIBUTES sa;
- >
- > pinfo = malloc (sizeof (pinfo_t));
- > if (!pinfo)
- > return NULL;
- >
- >
- > // make the pipe
- >
- > sa.nLength = sizeof (sa);
- > sa.bInheritHandle = 1;
- > sa.lpSecurityDescriptor = NULL;
- > if (!CreatePipe (pinfo->pipe, pinfo->pipe + 1, &sa, 1 << 22)) // suggest 4MB buffer
- > {
- > free (pinfo);
- > return NULL;
- > }
- >
- > // very important
- > if (!SetHandleInformation (pinfo->pipe[1], HANDLE_FLAG_INHERIT, 0))
- > {
- > CloseHandle (pinfo->pipe[0]);
- > CloseHandle (pinfo->pipe[1]);
- > free (pinfo);
- > return NULL;
- > }
- >
- >
- > // start the child process
- >
- > ZeroMemory (&siStartInfo, sizeof (STARTUPINFO));
- > siStartInfo.cb = sizeof (STARTUPINFO);
- > siStartInfo.hStdInput = pinfo->pipe[0];
- > siStartInfo.hStdOutput = 0; //GetStdHandle (STD_OUTPUT_HANDLE);
- > siStartInfo.hStdError = 0; //GetStdHandle (STD_ERROR_HANDLE);
- > siStartInfo.dwFlags = STARTF_USESTDHANDLES;
- >
- > if (!CreateProcess(NULL,// application name
- > (LPTSTR)cmd, // command line
- > NULL, // process security attributes
- > NULL, // primary thread security attributes
- > TRUE, // handles are inherited
- > DETACHED_PROCESS, // creation flags
- > NULL, // use parent's environment
- > NULL, // use parent's current directory
- > &siStartInfo, // STARTUPINFO pointer
- > &piProcInfo)) // receives PROCESS_INFORMATION
- > {
- > CloseHandle (pinfo->pipe[0]);
- > CloseHandle (pinfo->pipe[1]);
- > free (pinfo);
- > return NULL;
- > }
- >
- > CloseHandle (pinfo->pipe[0]);
- > pinfo->proc = piProcInfo.hProcess;
- > pinfo->thread = piProcInfo.hThread;
- >
- >
- > // what the hell is this cast for
- > f = _fdopen (_open_osfhandle ((int) pinfo->pipe[1], 0), "wb");
- >
- > if (!f)
- > {
- > CloseHandle (pinfo->pipe[0]);
- > CloseHandle (pinfo->pipe[1]);
- > CloseHandle (pinfo->proc);
- > CloseHandle (pinfo->thread);
- > free (pinfo);
- > return NULL;
- > }
- >
- > *finfo = pinfo;
- > return f;
- > }
- >
- > static void my_pclose (FILE *f, void *finfo)
- > {
- > pinfo_t *pinfo = (pinfo_t *) finfo;
- >
- > if (!f || !pinfo)
- > return;
- >
- > fclose (f);
- >
- > WaitForSingleObject (pinfo->proc, INFINITE);
- >
- > CloseHandle (pinfo->proc);
- > CloseHandle (pinfo->thread);
- > free (pinfo);
- > }
- >
- > #endif // #if 0
- > #else // _WIN32
- > // posix implementation
- >
- > static FILE *my_popen (const char *cmd, void **finfo)
- > {
- > return popen (cmd, "wb");
- > }
- > static void my_pclose (FILE *f, void *finfo)
- > {
- > pclose (f);
- > }
- > #endif // _WIN32
- >
- >
- >
- > // init and open sound, video pipes
- > // fn is filename passed from command line, typically final output file
- > void I_CapturePrep (const char *fn)
- > {
- > vid_fname = fn;
- >
- > if (!parsecommand (sndcommand, cap_soundcommand, MAX_PATH))
- > {
- > lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_soundcommand);
- > capturing_video = 0;
- > return;
- > }
- > if (!parsecommand (vidcommand, cap_videocommand, MAX_PATH))
- > {
- > lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_videocommand);
- > capturing_video = 0;
- > return;
- > }
- > if (!parsecommand (muxcommand, cap_muxcommand, MAX_PATH))
- > {
- > lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_muxcommand);
- > capturing_video = 0;
- > return;
- > }
- >
- > lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", sndcommand);
- > sndfile = my_popen (sndcommand, &sndfileinfo);
- > if (!sndfile)
- > {
- > lprintf (LO_ERROR, "I_CapturePrep: sound pipe failed\n");
- > capturing_video = 0;
- > return;
- > }
- > lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", vidcommand);
- > vidfile = my_popen (vidcommand, &vidfileinfo);
- > if (!vidfile)
- > {
- > lprintf (LO_ERROR, "I_CapturePrep: video pipe failed\n");
- > my_pclose (sndfile, sndfileinfo);
- > capturing_video = 0;
- > return;
- > }
- > I_SetSoundCap ();
- > lprintf (LO_INFO, "I_CapturePrep: video capture started\n");
- > capturing_video = 1;
- > }
- >
- >
- >
- > // capture a single frame of video (and corresponding audio length)
- > // and send it to pipes
- > void I_CaptureFrame (void)
- > {
- > char *snd;
- > char *vid;
- >
- > if (!capturing_video)
- > return;
- >
- > // NB: sync errors will occur if samplerate % 35 != 0
- > snd = I_GrabSound (snd_samplerate / 35);
- > if (snd)
- > {
- > fwrite (snd, 4, snd_samplerate / 35, sndfile);
- > free (snd);
- > }
- > vid = I_GrabScreen ();
- > if (vid)
- > {
- > fwrite (vid, 1, SCREENWIDTH * SCREENHEIGHT * 3, vidfile);
- > free (vid);
- > }
- >
- > }
- >
- >
- > // close pipes, call muxcommand, finalize
- > void I_CaptureFinish (void)
- > {
- > FILE *f;
- > void *finfo;
- >
- > const char **s;
- >
- > if (!capturing_video)
- > return;
- > capturing_video = 0;
- >
- > my_pclose (sndfile, sndfileinfo);
- > sndfile = NULL;
- > my_pclose (vidfile, vidfileinfo);
- > vidfile = NULL;
- >
- > // muxing and temp file cleanup
- >
- > f = my_popen (muxcommand, &finfo);
- >
- > lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", muxcommand);
- > if (!f)
- > {
- > lprintf (LO_ERROR, "I_CaptureFinish: finalize pipe failed\n");
- > return;
- > }
- >
- > my_pclose (f, finfo);
- >
- > // unlink any files user wants gone
- > remove (cap_tempfile1);
- > remove (cap_tempfile2);
- > }
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_capture.h ./src/i_capture.h
- 0a1,64
- > /* Emacs style mode select -*- C++ -*-
- > *-----------------------------------------------------------------------------
- > *
- > *
- > * PrBoom: a Doom port merged with LxDoom and LSDLDoom
- > * based on BOOM, a modified and improved DOOM engine
- > * Copyright (C) 1999 by
- > * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
- > * Copyright (C) 1999-2000 by
- > * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
- > * Copyright 2005, 2006 by
- > * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
- > * Copyright 2007 by
- > * Andrey Budko, Roman Marchenko
- > *
- > * This program is free software; you can redistribute it and/or
- > * modify it under the terms of the GNU General Public License
- > * as published by the Free Software Foundation; either version 2
- > * of the License, or (at your option) any later version.
- > *
- > * This program 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 General Public License for more details.
- > *
- > * You should have received a copy of the GNU General Public License
- > * along with this program; if not, write to the Free Software
- > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- > * 02111-1307, USA.
- > *
- > * DESCRIPTION:
- > *
- > *---------------------------------------------------------------------
- > */
- >
- > #ifndef __I_CAPTURE__
- > #define __I_CAPTURE__
- >
- > // commandlines passed to popen()
- > // this one recieves raw PCM sound on stdin
- > extern const char *cap_soundcommand;
- > // this one recieves raw RGB video on stdin
- > extern const char *cap_videocommand;
- > // this one recieves nothing on stdin and is called after the other two finish
- > extern const char *cap_muxcommand;
- > // names of two files to remove after muxcommand finishes
- > extern const char *cap_tempfile1;
- > extern const char *cap_tempfile2;
- >
- > // true if we're capturing video
- > extern int capturing_video;
- >
- > // init and open sound, video pipes
- > // fn is filename passed from command line, typically final output file
- > void I_CapturePrep (const char *fn);
- >
- > // capture a single frame of video (and corresponding audio length)
- > // and send it to pipes
- > void I_CaptureFrame (void);
- >
- > // close pipes, call muxcommand, finalize
- > void I_CaptureFinish (void);
- >
- > #endif
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_sound.h ./src/i_sound.h
- 82a83,89
- > // NSM sound capture routines
- > // silences sound output, and instead allows sound capture to work
- > // call this before sound startup
- > void I_SetSoundCap (void);
- > // grabs len samples of audio (16 bit interleaved)
- > char *I_GrabSound (int len);
- >
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_video.h ./src/i_video.h
- 64a65,66
- > // NSM expose lower level screen data grab for vidcap
- > unsigned char *I_GrabScreen (void);
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/m_misc.c ./src/m_misc.c
- 85a86,88
- > // NSM
- > #include "i_capture.h"
- >
- 893a897,904
- > // NSM
- > {"Video capture encoding settings",{NULL},{0},UL,UL,def_none,ss_none},
- > {"cap_soundcommand",{NULL, &cap_soundcommand},{0,"ffmpeg -f s16le -ar %s -ac 2 -i pipe:0 -acodec libvorbis -f ogg -aq 5 output.ogg"},UL,UL,def_str,ss_none},
- > {"cap_videocommand",{NULL, &cap_videocommand},{0,"ffmpeg -f rawvideo -pix_fmt rgb24 -s %wx%h -r 35 -i pipe:0 -vcodec libx264 -f mp4 -fpre ./libx264-baseline.ffpreset -crf 22 output.mp4"},UL,UL,def_str,ss_none},
- > {"cap_muxcommand",{NULL, &cap_muxcommand},{0,"ffmpeg -i output.ogg -i output.mp4 -vcodec copy -acodec copy %f"},UL,UL,def_str,ss_none},
- > {"cap_tempfile1",{NULL, &cap_tempfile1},{0,"output.ogg"},UL,UL,def_str,ss_none},
- > {"cap_tempfile2",{NULL, &cap_tempfile2},{0,"output.mp4"},UL,UL,def_str,ss_none},
- >
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/Makefile.am ./src/Makefile.am
- 61c61
- < s_advsound.c s_advsound.h \
- ---
- > s_advsound.c s_advsound.h i_capture.c i_capture.h \
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/SDL/i_sound.c ./src/SDL/i_sound.c
- 132a133,135
- > // NSM
- > static int dumping_sound = 0;
- >
- 434a438,444
- > // NSM: when dumping sound, ignore the callback calls and only
- > // service dumping calls
- > if (dumping_sound && unused != (void *) 0xdeadbeef)
- > return;
- >
- >
- >
- 618a629,652
- > // NSM sound capture routines
- >
- > // silences sound output, and instead allows sound capture to work
- > // call this before sound startup
- > void I_SetSoundCap (void)
- > {
- > dumping_sound = 1;
- > }
- >
- > // grabs len samples of audio (16 bit interleaved)
- > char *I_GrabSound (int len)
- > {
- > char *buff;
- > if (!dumping_sound)
- > return NULL;
- >
- > buff = malloc (len * 4);
- > if (buff)
- > {
- > memset (buff, 0, len * 4);
- > I_UpdateSound ((void *) 0xdeadbeef, buff, len * 4);
- > }
- > return buff;
- > }
- diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/SDL/i_sshot.c ./src/SDL/i_sshot.c
- 331a332,395
- >
- > // NSM
- > // returns current screern contents as RGB24 (raw)
- > // returned pointer should be freed when done
- >
- > unsigned char *I_GrabScreen (void)
- > {
- > unsigned char *pixel_data;
- >
- > #ifdef GL_DOOM
- > if (V_GetMode() == VID_MODEGL)
- > {
- > pixel_data = gld_ReadScreen();
- > return pixel_data;
- > }
- > #endif
- >
- > pixel_data = malloc(SCREENWIDTH * SCREENHEIGHT * 3);
- >
- > if (pixel_data)
- > {
- > SDL_Surface *scr = SDL_GetVideoSurface();
- > SDL_PixelFormat *fmt = scr->format;
- > SDL_Palette *pal = fmt->palette;
- > unsigned char *pixel_src = (unsigned char *) scr->pixels;
- >
- > int lock_needed = SDL_MUSTLOCK(scr);
- > int lock_was_successful = 0;
- >
- > if (!lock_needed || SDL_LockSurface(scr) >= 0)
- > {
- > // While the screen is locked write it into a buffer
- > unsigned char *s = pixel_data;
- > int i;
- >
- > if (pal) // 8bpp
- > {
- > for (i = 0; i < SCREENWIDTH * SCREENHEIGHT; i++)
- > {
- > *s++ = pal->colors[pixel_src[i]].r;
- > *s++ = pal->colors[pixel_src[i]].g;
- > *s++ = pal->colors[pixel_src[i]].b;
- > }
- > }
- > else // high/truecolor
- > {
- > for (i = 0; i < SCREENWIDTH * SCREENHEIGHT; i++)
- > {
- > Uint32 p = *(Uint32 *) (pixel_src + i * fmt->BytesPerPixel);
- > *s++ = (((p & fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss);
- > *s++ = (((p & fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss);
- > *s++ = (((p & fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss);
- > }
- > }
- >
- > if (lock_needed)
- > SDL_UnlockSurface(scr);
- > }
- > }
- > return pixel_data;
- > }
- >
- >
- >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement