| dem2vid bash script | |
|
|
Author | Message |
---|
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: dem2vid bash script Tue Dec 02, 2008 7:53 am | |
| Simple script to encode a .dem to an aac/avc video.See post #7 for faster encoding. Put this script anywhere & make executable. To produce a high quality mp4 within your working directory simply specify the demo to encode in addition to your desired width & file size. The demo file must be within your ~/.nexuiz/data/demos/ directory, I recommend renaming it to something simple beforehand. Please have a quick look through it before use, it works here but you may need extra dependencies or have different preferences. - Code:
-
#!/bin/bash
#Script to capture demo, calculate bitrate, scale & encode to aac/avc #uses ffmpeg presets within ~/.ffmpeg (-vpre fast/-vpre vhq) #examples: http://svn.mplayerhq.hu/ffmpeg/trunk/ffpresets #depends: mplayer, faac, ffmpeg & x264 (>20081002 recommended) #use: ./dem2vid yourDemo.dem requiredWidth requiredSizeInMB
DEM="$1" WID="$2" MB="$3"
dumpDemo() { LOC=`locate nexuiz-linux-glx.sh` ${LOC} -demo +cl_capturevideo 1 +playdemo demos/${DEM} VID=`find ~/.nexuiz/data/video/ -iname "dpvideo*.avi" -print | tail -1` echo ${LOC} ${VID} }
info() { mplayer -identify -frames 0 ${VID} 2>/dev/null > /tmp/$$ RESX=`grep ID_VIDEO_WIDTH /tmp/$$ | cut -d"=" -f2` RESY=`grep ID_VIDEO_HEIGHT /tmp/$$ | cut -d"=" -f2` LENGTH=`grep ID_LENGTH /tmp/$$ | cut -d"=" -f2` rm /tmp/$$ && echo ${RESX} ${RESY} ${LENGTH} }
height() { ASPECT=$(echo "scale=3; ${RESX} / ${RESY}" | bc) HEIGHT=$(echo "${WID} / ${ASPECT}" | bc) MOD16=$(( ${HEIGHT} / 16 * 16 )) echo ${MOD16} }
audioSize() { ffmpeg -i ${VID} -vn -acodec libfaac -ac 2 -aq 100 -async 2 aud.m4a STAT=$(stat aud.m4a | grep Size | awk '{print $2}') SIZE=$( echo "scale=6; ${STAT} / 1024" | bc) echo ${SIZE} }
bitrate() { RATE=$(echo "(( "$MB" * 1024 ) / ${LENGTH}) - ( ${SIZE} / ${LENGTH})" | bc) R8=$(echo "(( ${RATE} * 8 ) * 1.02)" | bc) KBPS=`echo "tmp=${R8}; tmp /= 1; tmp" | bc` echo ${KBPS} }
encode() { ffmpeg -i ${VID} -an -pass 1 -s ${WID}x${MOD16} -vcodec libx264 -vpre fast \ -b ${KBPS}k -threads 0 -rc_eq 'blurCplx^(1-qComp)' -level 41 "$DEM.mp4" ffmpeg -i ${VID} -acodec libfaac -ac 2 -aq 100 -async 2 -pass 2 \ -s ${WID}x${MOD16} -vcodec libx264 -vpre vhq -b ${KBPS}k -threads 0 \ -rc_eq 'blurCplx^(1-qComp)' -level 41 -psnr -y "$DEM.mp4" }
dumpDemo; info; height; audioSize; bitrate; encode; rm ${VID} aud.m4a *2pass*.log && echo Finished!
It didn't take too long to slap together. Feel free to add to it or recommend changes. It's not perfect, tho I hope it serves some purpose. Tony.
Last edited by lost on Tue May 26, 2009 10:56 am; edited 5 times in total (Reason for editing : This is old, try the newer one in post #7) | |
|
| |
Growl Side Admin
Posts : 980 Join date : 2008-07-20 Location : Germany
| Subject: Re: dem2vid bash script Wed Dec 03, 2008 1:45 am | |
| - Quote :
- Put this script anywhere & make executable.
How to make sth executable? I am a windows-user(noob, i know ), will it work for me too? And you mentioned a zoom-script some weeks ago. Would u mind to make it public? I would like to try it out | |
|
| |
Bommel
Posts : 258 Join date : 2008-11-14 Location : Auenland
| Subject: Re: dem2vid bash script Wed Dec 03, 2008 2:10 am | |
| first of all: thx to lost very useful thing! @ Growl: It probably dont work on windows (its a bash script), maybe with cygwin or something. | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Wed Dec 03, 2008 5:10 am | |
| I'd assume that it'd work on other UNIX like systems that have a BASH shell, unfortunately that's not Windows. I can't offer more than what Spohst has already suggested. Sorry Marc. PS. The zoom script I mentioned was kindly supplied by Kanonmat & can be found on his site: http://kanonmat.wikispaces.com/Scripts+and+configsI don't use it any more, I just have the following binds: - Code:
-
bind MWHEELUP "fov 25 ; sensitivity 8" bind MWHEELDOWN "fov 100 ; sensitivity 32" | |
|
| |
Growl Side Admin
Posts : 980 Join date : 2008-07-20 Location : Germany
| Subject: Re: dem2vid bash script Wed Dec 03, 2008 9:37 pm | |
| Just for your script (and because i was curious) i installed ubuntu linux yesterday So i can give it a try kanonmats site is very cool....nice stuff there, for me the colorchanging script for crosshairs is interesting, but i i have no idea how to put it in my config. I want my own crosshair wirh the same size and only a colorchange...can u translate it to me in the language of scripting noobs? | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Thu Dec 04, 2008 3:51 am | |
| That's progress Marc, you'll be using BSD next week. You may need to compile newer versions of ffmpeg & x264, tho you can get away with different presets: http://rob.opendot.cl/index.php/2008/10/06/changes-to-x264-and-ffpresets - It all depends what quality/compression you're after. I recommend that you don't use any Nexuiz packages that may be available, just download as usual & extract somewhere within your home directory. Anyhoo, the crosshair script... I'll have a look & get back to ya. So... His script provides full crosshair customisation in game. Keys 1-3 changing BRG, 4 changes opacity, 5 cycles through custom corsairs & 6 scales your selection. These binds become active whilst keeping mouse3 pressed. To use it, make a file within your 'data' dir called something like crosshair_script, copy & paste everything from the Crosshair section (removing the spaces within the comments). Then just issue 'exec crosshair_script' to activate it. Of course you could bind that or add it to your autoexec.cfg file. If you just want the ability to quickly change crosshair colour, try adding this to your cfg: - Code:
-
bind KP_END "toggle crosshair_color_red 0 0.14 0.29 0.43 0.57 0.71 0.86 1; echo RGB $crosshair_color_red $crosshair_color_green $crosshair_color_blue" bind KP_DOWNARROW "toggle crosshair_color_green 0 0.14 0.29 0.43 0.57 0.71 0.86 1; echo RGB $crosshair_color_red $crosshair_color_green $crosshair_color_blue" bind KP_PGDN "toggle crosshair_color_blue 0 0.14 0.29 0.43 0.57 0.71 0.86 1; echo RGB $crosshair_color_red $crosshair_color_green $crosshair_color_blue" He's certainly got some good stuff on his site. You played the FPS in your browser? | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Fri Dec 05, 2008 9:50 pm | |
| Faster version of my script, basically 2 passes instead of 3 while encoding to a specific size. There's also a single pass VBR mode if no size is specified (recommended). - Code:
-
#!/bin/sh
#Script to capture demo, calculate bitrate, scale & encode to mp4 #uses ffmpeg presets within ~/.ffmpeg (-vpre fast/-vpre vhq) #examples: http://svn.mplayerhq.hu/ffmpeg/trunk/ffpresets #depends: faac, ffmpeg & x264 (>20081002 recommended) #use: ./dem2vid yourDemo.dem requiredWidth requiredSizeInMB
DEM="$1" WID="$2" MB="$3" DEST="${1%.*}.mp4"
capture() { LOC=`locate nexuiz-linux-sdl.sh | tail -1` ${LOC} -demo +cl_capturevideo 1 +cl_capturevideo_ogg 0 \ +cl_capturevideo_fps 24 +playdemo demos/${DEM} VID=`find ~/.nexuiz/data/video/ -iname "dpvideo*.avi" -print | tail -1` echo "Demo captured to ${VID}" }
info() { ffmpeg -i ${VID} 2> /tmp/$$ TH=`grep Duration /tmp/$$ | cut -d":" -f2 | cut -c 2-3` TM=`grep Duration /tmp/$$ | cut -d":" -f3` TS=`grep Duration /tmp/$$ | cut -d":" -f4 | cut -c 1-5` SEC=$(echo "( ${TH} * 3600 ) + ( ${TM} * 60 ) + ${TS}" | bc) RESX=`grep Video: /tmp/$$ | grep -o ....x | tr -d 'x '` RESY=`grep Video: /tmp/$$ | grep -o x.... | tr -d 'x,'` rm /tmp/$$ && echo ${RESX} ${RESY} ${SEC} }
height() { ASPECT=$(echo "scale=3; ${RESX} / ${RESY}" | bc) HEIGHT=$(echo "${WID} / ${ASPECT}" | bc) MOD16=$(( ${HEIGHT} / 16 * 16 )) echo ${MOD16} }
bitrate() { RATE=$(echo "(( "$MB" * 1024 ) / ${SEC}) - 16" | bc) R8=$(echo "(( ${RATE} * 8 ) * 1.02)" | bc) KBPS=`echo "tmp=${R8}; tmp /= 1; tmp" | bc` echo ${KBPS} }
encode() { ffmpeg -i ${VID} -pass 1 -s ${WID}x${MOD16} -vcodec libx264 -vpre fast \ -b ${KBPS}k -threads 0 -rc_eq 'blurCplx^(1-qComp)' -level 41 -an "$DEST" ffmpeg -i ${VID} -acodec libfaac -ac 2 -ab 128k -async 2 -pass 2 \ -s ${WID}x${MOD16} -vcodec libx264 -vpre vhq -b ${KBPS}k -threads 0 \ -rc_eq 'blurCplx^(1-qComp)' -level 41 -psnr -y "$DEST" }
vbr() { ffmpeg -i ${VID} -acodec libfaac -ac 2 -aq 100 -async 2 \ -s ${WID}x${MOD16} -vcodec libx264 -vpre vhq -crf 20 -threads 0 \ -rc_eq 'blurCplx^(1-qComp)' -level 41 -psnr "$DEST" }
capture; info; height; if [ -n "$3" ]; then bitrate; encode; rm *2pass*.log else vbr; fi rm ${VID} && echo "Finished! Saved as ${DEST}"
Last edited by lost on Mon Jun 01, 2009 8:30 pm; edited 8 times in total (Reason for editing : edited for use with 2.5.1 & removed mplayer dep) | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Fri Dec 05, 2008 11:15 pm | |
| My presets, if anyone's interested: libx264-fast.ffpreset: - Code:
-
coder=1 flags=+loop cmp=+chroma partitions=-parti8x8-parti4x4-partp8x8-partp4x4-partb8x8 me_method=dia subq=1 me_range=16 g=480 keyint_min=24 sc_threshold=40 i_qfactor=0.71 b_strategy=2 qcomp=0.6 qmin=10 qmax=51 qdiff=4 bf=3 refs=1 directpred=1 trellis=0 flags2=-bpyramid-wpred-mixed_refs-dct8x8+fastpskip libx264-vhq.ffpreset: - Code:
-
coder=1 flags=+loop cmp=+chroma partitions=+parti8x8+parti4x4+partp8x8+partp4x4+partb8x8 me_method=umh subq=9 me_range=32 g=480 keyint_min=24 sc_threshold=40 i_qfactor=0.71 b_strategy=2 qcomp=0.6 qmin=10 qmax=51 qdiff=4 bf=3 refs=6 directpred=3 trellis=2 flags2=+bpyramid+wpred+mixed_refs+dct8x8-fastpskip These presets only work with x264 & ffmpeg > 20081002 (a highly recommended update). | |
|
| |
Growl Side Admin
Posts : 980 Join date : 2008-07-20 Location : Germany
| Subject: Re: dem2vid bash script Sat Dec 06, 2008 2:25 am | |
| Thanks a lot, the crosshair script is reeeeeeeaaaaally cool I took the "exec script" way, but i will soon make an autoexec.cfg file. Just need to figure out how(but i think i can do it myself ) It also saves my settings about the fog? because i always have to type in fog 0, because it never saved it... Only thing in your script: it always worked for me, not only while pressing mouse 3. But thats no problem, i only had timenugde settings on my numpad and i don't know for what purpose they are.... edit: i dont know if it has something to do with the script, but i have heavy lags now, up to 2 secondes from a shot to the message that i was fragged. I will try it without the script soon, but at moment i am sick of the game :/ | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Sat Dec 06, 2008 3:52 am | |
| Mouse3 was only needed on Kanonmats original script, I just copied the relevant bits for you, binding them directly to the keypad. Timenudge on the keypad? Hehe, I think that was an old cfg from Jazz & myself that's been around the block a few times. I think timenudge was little more than a placebo anyhow. Nothing in any zoom/crosshair script would be accountable for lag. Maybe start with a fresh cfg if things don't improve. | |
|
| |
Growl Side Admin
Posts : 980 Join date : 2008-07-20 Location : Germany
| Subject: Re: dem2vid bash script Sat Dec 06, 2008 10:07 pm | |
| I copied the cfg from the 666 forum a long time ago and did some improvements for me. The lag only appeared at the PK-servers, on PB ones it was ok. So it's nothing about the script and i will use it for a long time i think Pretty cool my crosshair dont disappears at the bright levels anymore What is timenudge for? I have no idea and the tab-function in nexuiz also dont help | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Sat Dec 06, 2008 10:53 pm | |
| | |
|
| |
Growl Side Admin
Posts : 980 Join date : 2008-07-20 Location : Germany
| Subject: Re: dem2vid bash script Sun Dec 07, 2008 11:41 pm | |
| A fresh config helped a lot. Now everything is fine and your script still works well for me | |
|
| |
lost Side Admin
Posts : 1417 Join date : 2008-06-12 Location : England
| Subject: Re: dem2vid bash script Tue May 26, 2009 3:36 am | |
| Updated post #7 so that quality is maintained when using 2.5.1 & removed the mplayer dependency. Also made a very simple script to use the internal ogg/theora encoder. It's about twice as fast as my high quality script & requires no external dependencies. The down-side is less efficient encoding (resulting in a larger final video) but there's no disk thrashing & it doesn't require ~10GB free space. I guess the main reason for making videos is to upload to Youtube. For this reason there's 2 presets, hq & hd - should be self-explanatory: - Code:
-
#!/bin/sh
#simple script to encode a Nexuiz demo using the internal encoder #use: ./dem2ogv yourDemo.dem hq/hd
DEM="$1" CFG=~/.nexuiz/data/config.cfg
if [ "$2" == "hq" ]; then RESX="768" elif [ "$2" == "hd" ]; then RESX="1280" fi echo ${RESX}
aspect() { WIDTH=`grep vid_width $CFG | cut -d " " -f2 | tr -d '"'` HEIGHT=`grep vid_height $CFG | cut -d " " -f2 | tr -d '"'` ASPECT=$(echo "scale=3; ${WIDTH} / ${HEIGHT}" | bc) echo ${WIDTH} ${HEIGHT} ${ASPECT} }
height() { RESY=$(echo "${RESX} / ${ASPECT}" | bc) echo ${RESY} }
capture() { LOC=`locate nexuiz-linux-sdl.sh | tail -1` ${LOC} -demo +cl_capturevideo_width ${RESX} +cl_capturevideo_height ${RESY} \ +cl_capturevideo 1 +cl_capturevideo_ogg 1 +playdemo demos/${DEM} }
aspect; height; capture; echo "Finished! Your video is saved under ~/.nexuiz/data/video/" PS. mac users, an edited version that should work: http://playerkiller.toxicfarm.com/mac-os-f25/accessing-to-demos-and-converting-them-in-mac-os-t648.htm#8964 - If not, there's Red Baron's method. | |
|
| |
Sponsored content
| Subject: Re: dem2vid bash script | |
| |
|
| |
| dem2vid bash script | |
|