ffmpegmencoder

ffmpeg capture for usb v4l2 card


I have a Grabby Terratec USB card.

Bus 001 Device 006: ID 0ccd:10af TerraTec Electronic GmbH Terratec G1

With mencoder I capture fine video and audio using a script like this one

#!/bin/sh
#script for capture
#settings for pal 25 fps 720:576 normid=5
#settings for ntsc 30000/1001 fps normid 0 720:480
#settings for INPUT,0=composite,1=s-video,but depend on card

TITLE="MYMOVIE"
CROP="612:467:16:1"
SCALE="560:432"
DEVVID=0
INPUT=1
ADEVICE=hw.2,0
NORMID=5
WIDTH=640
HEIGHT=480
FPS=25
AUDIORATE=48000
ASPECT=4/3
VFS="yadif,crop=$CROP,scale=$SCALE,harddup"

mencoder tv:// -tv driver=v4l2:normid=$NORMID:width=$WIDTH:height=$HEIGHT:device=/dev/video$DEVVID:input=$INPUT:fps=$FPS:alsa:adevice=$ADEVICE:audiorate=${AUDIORATE}:amode=1:forceaudio:immediatemode=0 -of mpeg -mpegopts format=dvd -oac lavc -ovc lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=8000:vbitrate=6000:keyint=15:acodec=ac3:abitrate=320 -aspect $ASPECT -vf $VFS -o "$TITLE".mpg

The script capture audio because this line is present

:amode=1:forceaudio:immediatemode=0

Now the problem, I want to capture using ffmpeg with libx265 and aac

#!/bin/sh
SCALE=528:400
CROP=616:471:14:0
ASPECT=4:3
TITLE="MYTITLE"

#usbstream:CARD=Generic
#    HD-Audio Generic
#    USB Stream Output
#sysdefault:CARD=G1
#    Terratec G1, USB Audio
#    Default Audio Device
#front:CARD=G1,DEV=0
#    Terratec G1, USB Audio
#    Front output / input
#usbstream:CARD=G1
#    Terratec G1
#    USB Stream Output

ffmpeg -y -f video4linux2 -i /dev/video0  -thread_queue_size 512 -f alsa -i hw:CARD=G1 -ac 2 -vf yadif,crop=$CROP,scale=$SCALE -c:v libx265 -c:a aac -b:v 1200k -b:a 320k -metadata language=eng -metadata title="Mymovie" -aspect $ASPECT "$TITLE".mkv

The problem is.. video is captured but without audio, I have tried the line

 -f alsa -i hw:CARD=G1

and

 -f alsa -i hw:CARD=G1,DEV=0

and

 -f alsa -i hw:2,0

But no way. The option " :amode=1:forceaudio:immediatemode=0" doesn't exist on ffmpeg. Any suggestion?Thanks


Solution

  • Solution found, before running the script the capture card must be "unmute" with this command

    v4l2-ctl --set-ctrl mute=0
    

    I also use the hw:2 for audio device and set the queue size for alsa, the complete script is now like this

     #!/bin/sh
    SCALE=528:400
    CROP=616:471:14:0
    ASPECT=4:3
    TITLE="MYMOVIE"
    
    ffmpeg -y -f video4linux2 -i /dev/video0 -thread_queue_size 2048 -f alsa -i hw:2 -ac 2 -vf yadif,crop=$CROP,scale=$SCALE -c:v libx265 -c:a aac -b:v 1200k -b:a 320k -metadata language=eng -metadata title="My movie" -aspect $ASPECT "$TITLE".mkv