테이프 액션?

테이프 액션?

소음이나 움직임이 감지되면 소리와 함께 동영상 녹화를 시작하는 데몬을 설정하고 싶습니다. 이를 개별적으로 수행할 수 있는 도구가 있지만 동시에 수행할 수 있습니까? 모션이 감지되면 스크립트가 실행되도록 모션을 설정할 수 있나요? SOX에서도 동일한 작업을 수행할 수 있나요?

답변1

이것은 매우 오래된 질문이라는 것을 알고 있지만 검색 중에 이 질문을 우연히 발견한 사람에게 도움이 될 수 있습니다(예: 몇 년 전)... 오디오를 녹음하고 스트리밍하려면 Ridgy로 시작합니다. Motion에서 위의 답변을 찾았고 적어도 나에게는 성공적인 솔루션 개발을 시작할 수 있었습니다. 내 사용 사례는 둥지 상자에서 소리를 녹음하는 것입니다. Pi 3B+ 실행 모션에 연결된 팬/틸트 마운트에 MS LifeCam 웹캠을 장착했습니다. 해결책은 실제로 동영상 녹화를 시작하기 위해 모션이 트리거될 때 스크립트를 실행하는 것이지만 웹캠에서 오디오를 스트리밍하는 지속적으로 실행되는 스크립트도 있습니다. 그런 다음 VLC를 사용하여 네트워크 비디오 스트림을 보고 오디오 스트림을 재생합니다. 세부사항은 다음과 같습니다:

오디오 및 비디오 파일을 처리하기 위해 세 개의 디렉터리가 설정되어 있습니다 /home/pi/motion/videos./home/pi/motion/videosB/home/pi/videos/pre-mergevideos

motion.conf.mkv 비디오가 저장되도록 구성됨/home/pi/motion/videos

영화가 시작되면 Motion은 Record_s.sh라는 스크립트를 실행합니다. 이 스크립트는 .mkv 비디오와 동일한 이름으로 60초 오디오 파일을 녹음하고/home/pi/motion/videos

영화가 닫히면 Motion은 .mkv 및 .mp3 파일을 병합하고 /home/pi/motion/videos병합된 파일을 /home/pi/motion/pre-mergevideos.mkv 및 .mp3 소스 파일을 삭제하고 파일을 병합하는 merge_sv.sh라는 스크립트를 실행합니다. 권한은 777로 변경되었고, 소유자는 루트에서 모션으로 변경되었으며, 마지막으로 병합된 파일은 다음으로 이동되었습니다./home/pi/motion/videosB

crontab은 2분마다 rsync를 실행하여 "videosB"의 콘텐츠를 NAS 공유(/home/pi/motion/media)로 이동합니다.

후자는 어떤 이유로든 NAS 공유를 사용할 수 없게 될 경우 "motion"이 충돌하는 것을 방지하기 위한 것입니다. "motion"은 해당 파일을 로컬 디렉터리에 기록하고 crontab은 NAS 공유에 대한 출력을 담당합니다.

#!/bin/bash
# record_s.sh
# 15/4/18: Created
# 25/11/20: libav-tools no longer available in 'Buster', 'avconv' replaced by 'ffmpeg'
filename="$1"
echo "$1" &> /home/pi/motion/filename.txt  # filename.txt will contain /home/pi/motion/videos/xxxxxxxxxxxxxx.mkv
#remove ".mkv" file extension - "${filename%.*}  (parameter expansion)
#Use of 'sudo' is only possible if user motion is in the sudoers file and in the sudo group
sudo ffmpeg -y -f alsa -ac 1 -i default -acodec mp3 -b:a 64k -t 60 "${filename%.*}".mp3 &> /home/pi/motion/record_s.txt
#!/bin/bash
# merge_sv.sh
# 19/04/18: Created

# Call arguments: %f %Y%H%d%T where %f is filename with full path (eg) /home/pi/motion/videos/9403-20180511053500.mkv
# Allow record_s.sh to finish writing the .mp3 sound file (which will have the same name & path as above except .mp3)

sleep 10
filename="$1"
# The 'if' statement below will reject timelapse files '*.avi'
if [[ ${filename##*\.} != avi ]] # See answer 5 in https://stackoverflow.com/questions/407184/how-to-check-the-extension-of-a-filename-in-a-bash-script
then
    #Change output file address from /home/pi/motion/videos to /home/pi/motion/pre-mergevideos (/home/pi/motion/pre-mergevideos is a directory for temporarily holding the unmerged files)
    tempfolder="pre-mergevideos"
    outputfolder="videosB" # This is the folder containing the merged mkv & mp3 video and the jpg files from 'motion'. This folder is rsync'd to network share 'media'.
    # Replaces 'videos' in $filename with the text in $tempfolder (ie) 'pre-mergevideos' so $output becomes (eg) /home/pi/motion/pre-mergevideos/9403-20180511053500.mkv, whilst
    # $filename remains (eg) /home/pi/motion/videos/9403-20180511053500.mkv
    temp_locn="${filename/videos/$tempfolder}"
    final_locn="${filename/videos/$outputfolder}"
    #
    #
    # Merge video and audio into one file. Note the mp3 file has to be converted to aac for an mkv container.  Error and stdout messages are redirected to merge_sv.txt.  For
    # 'sudo' to work user 'motion' has to be added to the sudoers file and to the sudo group.
    # The expression "${filename%.*} removes ".mkv" file extension (parameter expansion)
    # -itsoffset option offsets the timestamps of all streams by (in this case) 0.8 seconds in the input file following the option (without it the audio leads the video by about 0.8s).
    sudo ffmpeg -y -i $filename -itsoffset 0.80 -i "${filename%.*}".mp3 -c:v copy -c:a aac $temp_locn &> /home/pi/motion/merge_sv.txt
    #Delete the source files
    sudo rm $filename
    sudo rm "${filename%.*}".mp3
    # change the file permissions on the merged file (otherwise it's root 644 rw.r..r..)
    sudo chmod 777 $temp_locn
    # change the owner to 'motion'
    sudo chown motion:motion $temp_locn
    #move the recently merged file into the 'videosB' folder. Remember both $temp_locn and $final_locn contain path and filename
    sudo mv $temp_locn $final_locn 
fi

tldr 버전:

record_s.shMotion이 비디오를 녹화할 때 웹캠의 오디오도 녹음합니다. 비디오 녹화가 완료되면 merge_sv.sh오디오와 비디오 파일을 함께 병합하고 소스 파일을 삭제하십시오. 스크립트는 오디오에 오프셋을 적용하여(시행 착오를 통해 결정됨) 파일을 함께 동기화된 상태로 유지합니다. 테더링을 사용할 수 없는 경우 움직임이 충돌하는 것을 막기 위한 일부 디더링도 있습니다.

오디오 스트리밍: 시작 시 호출되는 간단한 스크립트를 실행하여 crontab -e를 통해 sound_on.shrtp 스트림을 생성합니다 .

#!/bin/bash
# sound_on.sh
# 13/1/18
# 
# killall -9 avconv
#Pre Buster version:
#avconv -f alsa -ac 1 -re -i default -acodec mp3 -ac 1 -f rtp rtp://234.5.5.5:5004 2> /tmp/mylog.log
# default was hw:1,0

#Buster version onwards:
ffmpeg -f alsa -channels 1 -i hw:1,0 -acodec mp3 -f rtp rtp://234.5.5.5:5004 2> /home/pi/motion/sound_on.log

VLC를 사용하여 다음 설정으로 재생할 수 있습니다.

미디어/오픈 네트워크 스트리밍: 네트워크 URL:http://192.168.1.122:8081(라즈베리파이가 모션을 실행하는 주소)

더 많은 옵션 표시/추가 미디어 동시 재생: "추가 미디어" rtp://234.5.5.5:5004

그런 다음 "재생"을 누르세요

이것은 VLC의 Ubuntu 버전에서만 작동합니다. 이 작업을 시도할 때마다 Windows 10 버전이 충돌합니다.

관련 정보