You are not logged in.

#1 2014-09-19 17:16:49

rabcor
Banned
Registered: 2013-02-09
Posts: 500

[Solved]FFMPEG Hogging Alsa instead of recording it

I had a pretty sweet command line for recording video and audio with ffmpeg

ffmpeg -f alsa -ac 2 -i plughw:0,0 -async 1 -f x11grab -s 1920x1080 -i :0.0 -c:a libmp3lame -b:a 384k -c:v libx264 -b:v 4000k -profile:v high444 -r 30 -preset ultrafast output.mkv

In the near past it resulted in a pretty clean recording of a stereo version of whatever sound was output to my speakers, and a nice 1920x1080 high quality 30fps video recording with a nice and basic h264/avc compression.

Now however it doesn't record any sound, or moreover it hogs my soundcard all for itself and stops me from running anything that would output sound (as well as of course stopping all sound that currently exists) so youtube videos won't load and games won't launch. What do I do? sad

Dmixing didn't work, I got the same result when I used this alsa PCM:

 pcm.dmixed {
	type asym
	playback.pcm {
		# See plugin:dmix at http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
		type dmix

		# Don't block other users, e.g. the Timidity midi-player daemon
		# http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
		ipc_key_add_uid true

		ipc_key 5678293
		ipc_perm 0660
		ipc_gid audio

		slave {

			channels 6
		
			pcm {
				#format S16_LE
				#format S24_LE
				format S32_LE
				#format FLOAT_LE

				#rate 44100
				#rate 48000
				rate 96000

				# http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
				# Maybe helps
				nonblock true

				type hw
				card 0
				device 0
				subdevice 0
			}

			# period_size 512 with buffer_size 16384 stops crackling in xmame
			# 320 breaks flash - https://bbs.archlinux.org/viewtopic.php?id=129458
			#period_size 512
			period_size 1024

			# If too large, use CONFIG_SND_HDA_PREALLOC_SIZE=2048
			buffer_size 16384
		}
	}
	capture.pcm "hw:0"
}

Last edited by rabcor (2014-09-20 00:47:12)

Offline

#2 2014-09-19 19:05:07

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

 You use the hardware through plughw and that dmixed, which is probably the one from brebs, still uses type hw. Dmix is for multi playback, dsnoop for mutli recording. Use dsnoop instead. Try this:

ffmpeg -f alsa -ac 2 -i plug:dsnoop:'{CARD 0 DEV 0}' /tmp/test.wav

Offline

#3 2014-09-19 20:07:20

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

Sadly, no dice (but thanks for trying big_smile )

ffmpeg -f alsa -ac 2 -i plug:dsnoop:'{CARD 0 DEV 0}' -f x11grab -s 1920x1080 -i :0.0 -c:a libmp3lame -b:a 384k -c:v libx264 -b:v 4000k -profile:v high444 -r 30 -preset faster output.mkv

Gives me the exact same result it would seem.

For some more output from ffmpeg (this is what I get as soon as I start recording):

[alsa @ 0xf3f380] ALSA buffer xrun.
[libmp3lame @ 0xf9cf00] Queue input is backward in time
    Last message repeated 3 times
[matroska @ 0xf9aec0] Non-monotonous DTS in output stream 0:1; previous: 2020, current: 2013; changing to 2020. This may result in incorrect timestamps in the output file.
[matroska @ 0xf9aec0] Non-monotonous DTS in output stream 0:1; previous: 2020, current: 1987; changing to 2020. This may result in incorrect timestamps in the output file.
[matroska @ 0xf9aec0] Non-monotonous DTS in output stream 0:1; previous: 2020, current: 1978; changing to 2020. This may result in incorrect timestamps in the output file.
[matroska @ 0xf9aec0] Non-monotonous DTS in output stream 0:1; previous: 2020, current: 1974; changing to 2020. This may result in incorrect timestamps in the output file.
[matroska @ 0xf9aec0] Non-monotonous DTS in output stream 0:1; previous: 2020, current: 1988; changing to 2020. This may result in incorrect timestamps in the output file.
[matroska @ 0xf9aec0] Non-monotonous DTS in output stream 0:1; previous: 2020, current: 2010; changing to 2020. This may result in incorrect timestamps in the output file.

Last edited by rabcor (2014-09-19 20:11:13)

Offline

#4 2014-09-19 20:45:56

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

 There seems something wrong with your setup, ffmpeg should not use alsa output while recording. That does not make sense, at least not from my experience. You do not use pulseaudio, right? Show your entire alsa configuration. Test ffmpeg audio recording without video first.

 Have you ruled out the obvious parts, like rebooting after system upgrade?

Edit:

#before and during ffmpeg
fuser -v /dev/snd/*

Last edited by emeres (2014-09-19 20:46:55)

Offline

#5 2014-09-19 21:46:44

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

Pulseaudio is not even installed.

$ fuser -v /dev/snd/*
                     USER        PID ACCESS COMMAND
/dev/snd/controlC0:  xandis      530 F.... volumeicon
/dev/snd/pcmC0D0c:   xandis     9544 F...m ffmpeg
/dev/snd/pcmC0D0p:   xandis      657 F...m steam
/dev/snd/timer:      xandis      657 f.... steam

I already showed the meaty part of my alsa.conf which was the dmixed pcm from brebs (or my modifications to it anyhow) but the other relevant parts are

pcm.!default {	
		type plug
		slave.pcm {	@func getenv
				vars [ ALSA_DEFAULT_PCM ]
				default "stereo"
				}	

			}

#Upmix stereo to 5.1
pcm.stereo {
        slave.pcm "dmixed"
		type route

        # Front and rear
        ttable.0.0 0.9
        ttable.1.1 0.9
        ttable.2.2 1
        ttable.3.3 1

        # Center and LFE
        ttable.4.4 1
        ttable.5.5 1

        # Front left/right to center
        ttable.0.4 0.5
        ttable.1.4 0.5

        # Front left/right to rear
        ttable.0.2 0.5
        ttable.1.3 0.5
}

(Everything else in there except for a 7.1 downmix is set up as a plug with the dmixed pcm as a slave, but it's irrelevant since none of it is being used) still, for completeness sake, the whole thing is here in case I missed something.

Last edited by rabcor (2014-09-19 21:48:59)

Offline

#6 2014-09-19 21:52:51

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

 I would disable ~/.asoundrc and try again, just to make sure the configuration is not interfering. Should there be any improvement, comment out or inverse nonblock option in pcm.dmixed*. Ffmpeg uses the timer when I record audio. Kill steam and try again.

Edit: Again this should not matter at all. Could it be that there are some input audio settings in ffmpegs profiles?

Last edited by emeres (2014-09-19 21:55:05)

Offline

#7 2014-09-20 00:46:57

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

Seems you were right about the restart (a bit after I made that last post I restarted, but got caught up in a video game before I tested this again) works like a charm now with my previous settings smile

Thanks for your help either way, thanks to that I didn't end up going in endless circles before restarting.

For some reason I've misunderstood that Linux only requires restarts upon kernel updates and only to apply these said kernel updates, guess that just like windows some things will just magically fix when you restart smile

Last edited by rabcor (2014-09-20 00:48:22)

Offline

#8 2014-09-20 00:59:23

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

 You can check fuser again and see if anything changed. It usually does, but more complexity leads to a higher error probability, still being consequently logical. You are welcome.

Offline

#9 2014-09-20 13:23:46

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

$ fuser -v /dev/snd/*
                     USER        PID ACCESS COMMAND
/dev/snd/controlC0:  xandis      517 F.... volumeicon
/dev/snd/pcmC0D0c:   xandis     2897 F...m ffmpeg
/dev/snd/pcmC0D0p:   xandis      801 F...m chrome
/dev/snd/timer:      xandis      801 f.... chrome

Nothing seems to have changed really, although steam isn't on the list this time. I've caught steam breaking my sound before, although that time I was on Enlightenment which seemed to have more issues with it than Openbox which I am now using. It might be related.

Last edited by rabcor (2014-09-20 14:19:26)

Offline

#10 2014-09-20 15:24:42

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

rabcor wrote:

magically fix when you restart smile

No, the fix was to *close* your volumeicon and chrome processes - they would have been using your old ~/.asoundrc

This is why I use a simple volume control, which doesn't keep the soundcard continually open.

Offline

#11 2014-09-21 00:41:19

rabcor
Banned
Registered: 2013-02-09
Posts: 500

Re: [Solved]FFMPEG Hogging Alsa instead of recording it

Thanks for the tip brebs! I'll use it smile

Offline

Board footer

Powered by FluxBB