What are the limitations of accessing /dev/video0 on an android device?

Conceptually I can understand that Termux cant take a photo or video from a camera device because it doesnt have access to the camera drivers that Android has....

...except that the Termux API does allow you to take a photo. So why is video off limits?

27 points · 7 comments · view on lemmy.world

7 Comments

0xd34d@sh.itjust.works · 12 pts · 1y (1 reply)

Probably because it still uses the android camera API to do so rather than directly access /dev/video0.

https://github.com/termux/termux-api/blob/master/app%2Fsrc%2Fmain%2Fjava%2Fcom%2Ftermux%2Fapi%2Fapis%2FCameraPhotoAPI.java

I'm sure it is possible to add a video capture to the API 😉

tetris11@lemmy.ml · 3 pts · 1y

Yeah, I mean it's not like they're calling native Android functions there (in proceedWithOpenCamera), it looks like the CameraDevice object might offer a lot more capture modes that just aren't being tapped into. Is it just a programming issue, or does Android only offer Photo contexts but not Video ones, or...?

Zak@lemmy.world · 5 pts · 1y (2 replies)
# ls -l /dev/video0
crw-rw---- 1 system camera 81,   0 1974-07-26 10:09 /dev/video0

Android doesn't handle users and groups like standard Linux, but the user account assigned to Termux is not a member of the camera group.

tetris11@lemmy.ml · 7 pts · 1y (1 reply)

Is it just a permissions issue? On a rooted phone, could I not simply add termux user to the camera group

Zak@lemmy.world · 3 pts · 1y

That seems likely to work.

kionite231@lemmy.ca · 1 pts · 1y (1 reply)

here is the script that kinda does what you want: https://gist.github.com/tusharhero/1635bdcaf616e3c310a9492d993ec17c

tetris11@lemmy.ml · 3 pts · 1y

Yeah I have a bash script that does similar, using the notification API for interactivity

FOLD_CAMERA=CameraShots
TEMP_PID=~/.record_pid
APP_ID=record

mkdir -p $FOLD_CAMERA

function main {
    termux-notification \
        --id $APP_ID --group RECORD \
	    --priority max \
	    --button1 "Front" \
	    --button1-action "termux-notification-remove $APP_ID;bash $0 record 1" \
	    --button2 "Back"  \
	    --button2-action "termux-notification-remove $APP_ID;bash $0 record 0" \
	    --button3 "Quit" \
	    --button3-action "termux-notification-remove $APP_ID;exit" \
	    --title "Record"
	
}

function record {
    local cam=${1:-0}

    termux-notification \
        --id $APP_ID --group RECORD \
	    --priority max \
	    --button1 "Stop" \
	    --button1-action "termux-notification-remove $APP_ID; bash $0 killproc" \
	    --title "Rec. $cam"
    
    (while :; do
	     termux-camera-photo \
	         -c $cam \
	         $FOLD_CAMERA/$(date "+%Y%m%d-%H%M_${cam}_record.jpg")
     done) &

    local pid=$!
    echo -n $pid > $TEMP_PID
} 

function killproc {
    local last_pid=$(cat $TEMP_PID)
    if [ "$last_pid" == "" ]; then
	    termux-toast "Could not kill process. Restart the phone."
    else
	    kill $last_pid &&
	        bash $0 main
    fi
}


[ "$*" = "" ] && main || eval "$*"

It just needs ffmpeg tied to the exit function