OSS Audioloop - DesktopRecording in the Cloud EC2

OSS specific Linux discussion (x86/amd64)

Moderators: hannu, dev, cesium, kodachi

OSS Audioloop - DesktopRecording in the Cloud EC2

Postby dsterz » Mon Oct 04, 2010 2:17 pm

Hi Everyone,

i have a Setup on a physical Server where I can grab Audio(oss_audioloop) and Video (using x11grab) with ffmpeg.
It works good, but I want it to run on a EC2 Instance at Amazon.
I alreade compiled the OSS Modules osscore+oss_audioloop (Ver.: 2002,2003) and the Server works so far but one big Problem exists:

On EC2 Instance Audio/Video are always async.

ffmpeg Options like -async (Sync but Crackling and Frequency Changes or Sound Speedup) or -vsync (No effect) does not help.

I've tried a lot of Kernel Settings 1000HZ Timer (CONFIG_HZ=1000), Tickles (NO_HZ=y) or High Resolution Timer (CONFIG_HIGH_RES_TIMERS=y)
but nothing works.

Can anyone tell me how OSS does its Timing? Is it based on Interrupts (IRQ8?)

Does a available Realtime Clock (dev/rtc) improves the Timing from OSS?

How can I improve OSS working more accurate like it does on a physical Machine?

Any Help would be great!


----
Infos:

I use the following to initialize the audioloop:

Code: Select all

echo "Restarting OSS..."
soundoff
soundon

echo "Configuring Audioloop..."
modprobe oss_audioloop
ossdetect -vd

rm /dev/dsp
ln -s /dev/oss/oss_audioloop0/server0 /dev/dsp

sleep 2

echo "Initializing Audioloop..."
ossplay -l /var/www/worker/videoexport/devicecheck.wav &
sleep 2
ossrecord -d /dev/oss/oss_audioloop0/pcm0 -O /tmp/ossrecord.wav &
sleep 4
killall ossrecord





Here are some output right from the EC2 Instance:

Code: Select all
# ossinfo
Version info: OSS 4.2 (b 2002/201010031239) (0x00040100) GPL
Platform: Linux/i686 2.6.35-22-virtual #33-Ubuntu SMP Sun Sep 19 23:54:13 UTC 2010 (ip-10-48-37-97)

Number of audio devices:        2
Number of audio engines:        2
Number of MIDI devices:         0
Number of mixer devices:        0


Device objects
0: osscore0 OSS core services
1: oss_audioloop0 audioloop

MIDI devices (/dev/midi*)

Mixer devices

Audio devices
Audio loopback 0 server side      /dev/oss/oss_audioloop0/server0  (device index 0)
(Audio loopback 0                  /dev/oss/oss_audioloop0/pcm0 ) (device index 1)

Nodes
  /dev/dsp -> /dev/oss/oss_audioloop0/server0
  /dev/dsp_in -> /dev/oss/oss_audioloop0/server0
  /dev/dsp_out -> /dev/oss/oss_audioloop0/server0
  /dev/dsp_mmap -> /dev/oss/oss_audioloop0/server0
  /dev/dsp_multich -> /dev/oss/oss_audioloop0/server0


Code: Select all
# ossdetect -dv
mknod /dev/sndstat c 251 0 -m 20666
mknod /dev/midi c 251 1 -m 20666
mknod /dev/mixer c 251 2 -m 20666
mknod /dev/oss/oss_audioloop0/server0 c 250 3 -m 20666
mknod /dev/oss/oss_audioloop0/pcm0 c 250 5 -m 20666


Code: Select all
# cat /boot/config-2.6.35-22-virtual |grep HZ
CONFIG_RCU_FAST_NO_HZ=y
CONFIG_NO_HZ=y
# CONFIG_HZ_100 is not set
CONFIG_HZ_250=y
# CONFIG_HZ_300 is not set
# CONFIG_HZ_1000 is not set
CONFIG_HZ=250
CONFIG_MACHZ_WDT=m


Code: Select all
# cat /boot/config-2.6.35-22-virtual |grep HIGH
CONFIG_HIGH_RES_TIMERS=y
# CONFIG_NOHIGHMEM is not set
# CONFIG_HIGHMEM4G is not set
CONFIG_HIGHMEM64G=y
CONFIG_HIGHMEM=y
CONFIG_HIGHPTE=y
# CONFIG_DEBUG_HIGHMEM is not set
dsterz
 
Posts: 5
Joined: Mon Oct 04, 2010 1:14 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby igorzwx » Mon Oct 04, 2010 2:35 pm

Have you tried a simple solution, a kind of script?

You may record audio and video separately with ffmpeg, for example.

There is an old script for this:

Code: Select all
# A simple bash script to capture screencast with audio. It works on Ubuntu 9.04

# To run the script you should install ffmpeg, mencoder, SoX, and Steve Harris's LADSPA plugins (swh-plugins)
#
# sudo apt-get install sox
#
# sudo apt-get install swh-plugins
#
# sudo apt-get install mencoder
#
# See -> How to make Ubuntu 9.04 (Jaunty Jackalope) Multimedia Ready
# http://shibuvarkala.blogspot.com/2009/04/howto-make-ubuntu-904-jaunty-jackalope.html
#
#
#
# Supply two arguments:
# (1) name of the file [baseName]
# (2) size of the screen to record [screenIN]

# Run the script by command:
#
# my-shooting-script-norm-lossless.sh [name-of-the-file] [screenIN]
#
# EXAMPLE:
#
# my-shooting-script-norm-lossless.sh mumu-usb-00011 1392x1040
#
# DEFAULT Values:
#
# my-shooting-script-norm-lossless.sh my-screencast 1392x1040
#
# -s 1392x1040  - width and height should be divisible by 16, otherwise compression may suffer.

#       How to crop the video with ffmpeg:

#       -croptop size          Set top crop band size (in pixels).

#       -cropbottom size       Set bottom crop band size (in pixels).

#       -cropleft size         Set left crop band size (in pixels).

#       -cropright size        Set right crop band size (in pixels).


#       QUOTE from "man ffmpeg":
#
#       0.0 is display.screen number of your X11 server, same as the DISPLAY
#       environment variable.
#
#               ffmpeg -f x11grab -s cif -i :0.0+10,20 /tmp/out.mpg
#
#       0.0 is display.screen number of your X11 server, same as the DISPLAY
#       environment variable. 10 is the x-offset and 20 the y-offset for the
#       grabbing.



# ********************************
# Press ENTER to finish recording.
# ********************************


# Reads the parameters from the command line.
baseName=$1

screenIN=$2

# Tests if the base name was specified. If not, take default value
if [ "$baseName" = "" ]; then
   baseName="my-screencast"
fi

# Tests if the screenIN was specified. If not, take default value
if [ "$screenIN" = "" ]; then
   screenIN="1392x1040"
fi

# Start recording video - x11grab
ffmpeg -an -f x11grab -r 25 -s "$screenIN" -i :0.0 -vcodec ffv1 -sameq "$baseName-lossless-ffv1-nosound.avi" &
pidV=$(ps -ef | grep "[f]fmpeg" | awk '{print $2}')
echo "Video recording started with process ID $pidV"

# Start recording oss-audio from /dev/dsp  internal soundcard
ffmpeg -f oss -ar 44100 -ac 1 -i /dev/dsp -acodec pcm_s16le "$baseName.wav" &
pidA=$(ps -ef | grep "[f]fmpeg" | awk '{print $2}')
echo "Audio recording started with process ID $pidA"

# Waits for the user to press enter.
echo ""
echo "Press ENTER to finish recording."
read nothing

# Kill ffmpeg
# echo "Terminating process $pidV $pidA ..."
echo "Terminating ffmpeg ..."
killall ffmpeg

# Wait for ffmpeg to finish.
wait
echo ""
echo "Filtering and normalizing sound ..."
sox "$baseName.wav" "$baseName-norm.wav" ladspa highpass_iir_1890 100 2 ladspa lowpass_iir_1891 9000 1 norm -1 ladspa lowpass_iir_1891 11000 10

# Wait for SoX to finish.
wait
echo ""
echo "Encoding to FFV1 lossless avi ..."
ffmpeg -isync -i "$baseName-lossless-ffv1-nosound.avi" -i "$baseName-norm.wav" -map 0:0 -map 1:0 -acodec copy -vcodec copy "$baseName-lossless-ffv1-final.avi"

# Wait for FFmpeg to finish.
wait
echo ""
echo "Encoding to mp4, video codec libx264 ..."
ffmpeg -r 25 -i "$baseName-lossless-ffv1-final.avi" -acodec libmp3lame -ab 224k -r 25 -vcodec libx264 -sameq "$baseName-final-libx264.mp4"

# Wait for FFmpeg to finish.
wait
echo ""
echo "Encoding to mpeg4 ..."
ffmpeg -i "$baseName-lossless-ffv1-final.avi" -acodec libmp3lame -ab 224k -sameq "$baseName-final-mpeg4.avi"

# Wait for FFmpeg to finish.
wait
echo ""
echo "Encoding to XviD ..."
ffmpeg -i "$baseName-lossless-ffv1-final.avi" -acodec libmp3lame -ab 224k -vcodec libxvid -aspect 1.3333 -sameq "$baseName-final-XviD.avi"

# Wait for FFmpeg to finish.
wait
echo ""
echo "Encoding to Windoze mpeg4 ..."
mencoder -mc 0 -ovc lavc -lavcopts vcodec=msmpeg4v2:vhq -oac mp3lame -o "$baseName-final-windoze-mpeg4.avi" "$baseName-lossless-ffv1-final.avi"

echo ""
echo "DONE! Audio and video files were written to the folder"


You may try to adapt it for your needs.
igorzwx
 
Posts: 966
Joined: Sun Jun 28, 2009 9:31 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby cesium » Mon Oct 04, 2010 3:11 pm

Several ideas:
A. You can try editing /usr/lib/oss/conf/osscore.conf and setting "max_intrate" to an higher value (see "man osscore" for explanation of setting). You'll need to restart OSS (sudo soundoff && sudo soundon) for it to take effect. This should reduce minimum latency.
B. You can try using oss_userdev which is pretty similar to oss_audioloop (it has a vmix layer in middle, so it allows different rates).
C. Btw, I think you could load oss_audioloop more easily - you can edit /usr/lib/oss/etc/installed_drivers and add "oss_audioloop" line, so soundon loads it. Not sure whether you need to init it.
cesium
 
Posts: 903
Joined: Sun Aug 12, 2007 12:51 am

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby dsterz » Tue Oct 05, 2010 6:53 pm

Thank you for the Script, unfortunately I need Audio+Video in Realtime in one Container. Here is how it works on the physical Machine:
Code: Select all

ffmpeg -f oss -ac 2 -async 2 -isync -i /dev/oss/oss_audioloop0/pcm0 -f x11grab -s 640x400 -r 30 -i :2.0 -vcodec mpeg4 -r 30 -g 1 -vdt 2000 -b 50000k -bt 2000k -acodec pcm_s16le -y capture.avi


Also tried the ffv1 videocodec which is used in the script to capture video.

Thanks also for the Ideas you shared.
I already tried a 250 Value on a CONFIG_HZ=250 Kernel with no success.
I will build a new 1000HZ Kernel Timer to increase the int_maxrate Value from the osscore to 1000HZ

I will try the oss_userdev I hope this brings better Results...

Can you give me some details how to use the oss_userdev Module with the mixer and the different rates?

The following Message also appears when loading osscore:
[16874.309801] osscore: This processor architecture is not compatible with vmix (info=0) - Not enabled.
I guess thats why oss_userdev does not work?

Does oss benefit from a available Realtime clock at /dev/rtc, because currently there is none.

Thanks for your support!
dsterz
 
Posts: 5
Joined: Mon Oct 04, 2010 1:14 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby igorzwx » Tue Oct 05, 2010 7:33 pm

Hi!

I am not a specialist on OSS modules.

As far as I remember, it was problematic to record video and audio with one ffmpeg instance on a particular computer. That script was designed to fix the problem.

What is the frame rate of the recorded video?

tcprobe (transcode package)
http://www.transcoding.org/transcode?Tcprobe

The command tcprobe -i foo.avi will print interesting
information about the AVI file itself and its video and
audio content.
igorzwx
 
Posts: 966
Joined: Sun Jun 28, 2009 9:31 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby dsterz » Tue Oct 05, 2010 8:07 pm

Framerate is set to 30.

The single ffmpeg Instance works on a physical Server but Things are different in this Xen DomU but I will
try the Script, maybe it helps.

Thanks for the tcpprobe Link, i will try it out on the input Streams.
dsterz
 
Posts: 5
Joined: Mon Oct 04, 2010 1:14 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby igorzwx » Tue Oct 05, 2010 8:31 pm

dsterz wrote:Framerate is set to 30.


It might be deceptive.
You may set fps to 30000, and the result might be 3fps (on an old computer).

You have to watch the terminal and/or tcprobe
igorzwx
 
Posts: 966
Joined: Sun Jun 28, 2009 9:31 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby cesium » Wed Oct 06, 2010 10:50 pm

Can you give me some details how to use the oss_userdev Module with the mixer and the different rates?

The following Message also appears when loading osscore:
[16874.309801] osscore: This processor architecture is not compatible with vmix (info=0) - Not enabled.
I guess thats why oss_userdev does not work?


Yep. However, you can get around this, by rebuilding OSS and providing --config-vmix=FIXEDPOINT option to configure. (See here on how to rebuild oss). Also, does using int_maxrate help at all?

Does oss benefit from a available Realtime clock at /dev/rtc, because currently there is none.


IIRC, OSS lets the kernel decide these matters. So the answer is "maybe".
cesium
 
Posts: 903
Joined: Sun Aug 12, 2007 12:51 am

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby dsterz » Thu Oct 07, 2010 4:16 pm

Hi again,

i've tried tcprobe unfortunately it cant read the /dev/dsp or audioloop from oss.

I've tried the oss_userdev which seems to give better results not with syncing but sound quality when using the ffmpeg -async 1 but now there are very short sound stops, you hear in the recorded sync avi file....

I cant attach the Mixer to the oss_userdev dont know why....

I did not tried the 1000HZ option yet so I guess increasing does not have any effect as mentioned in the osscore.conf config.

My next Steps are:
- 2002/2003 stables (currently using the RC3)
- 1000HZ Kernel Timer and increasing int_max
- 64Bit Instance Large/XLarge with good CPU Power
- some more ffmpeg switches, maybe i find some sound filtering for this issue....

We will see...

Greetings
dsterz
 
Posts: 5
Joined: Mon Oct 04, 2010 1:14 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby igorzwx » Thu Oct 07, 2010 4:27 pm

dsterz wrote:Hi again,

i've tried tcprobe unfortunately it cant read the /dev/dsp or audioloop from oss.


If I am not mistaken, tcprobe was designed to be applied to an avi file, and not to /dev/dsp

Code: Select all
tcprobe -i foo.avi


When you record desktop with ffmpeg, you may see on the terminal what is the actual frame rate of recoded video.
igorzwx
 
Posts: 966
Joined: Sun Jun 28, 2009 9:31 pm

Re: OSS Audioloop - DesktopRecording in the Cloud EC2

Postby cesium » Fri Oct 08, 2010 1:02 am

"Attaching the mixer"? You mean "vmixctl attach..."? I don't think that's needed for oss_userdev - IIRC, vmix is already attached, and you can have multiple clients.. Also, you can try increasing "int_maxrate" a bit before rebuilding the kernel - default is 100, which is probably lower than the kernel default...
cesium
 
Posts: 903
Joined: Sun Aug 12, 2007 12:51 am


Return to Linux

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests