tips:video

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tips:video [2015/11/08 12:00] – [MKV] scipiotips:video [2020/09/02 15:59] (current) – [from images to video] scipio
Line 26: Line 26:
 <code> <code>
 # 5 images per seconds # 5 images per seconds
-ffmpeg -y -framerate 5 -pattern_type glob -i '*.jpg' -c:v libx264 -vf "fps=25,scale=720:-1" out.mp4+ffmpeg -y -framerate 5 -pattern_type glob -i '*.jpg' -c:v libx264 -vf "fps=25,scale=720:trunc(ow/a/2)*2" out.mp4
 </code> </code>
 +
 +
 +<code>
 +ffmpeg -r 30 -s 1080x1080 -i imgs/%05d.jpg -vcodec libx264 -crf 15 -pix_fmt yuv420p out.mkv
 +</code>
 +  * crf: quality, minor is better
 +
 +===== from video to images =====
 +
 +
 +<code>
 +ffmpeg -i input.mp4 -qscale:v 2 imgs/%05d.jpg
 +</code>
 +  * qscale:v is quality, 2-15 minor is better
  
 ===== MKV===== ===== MKV=====
Line 44: Line 58:
 <code> <code>
 mkvmerge -o output.mkv $(echo *.mp4 | sed "s| | +|g") mkvmerge -o output.mkv $(echo *.mp4 | sed "s| | +|g")
 +</code>
 +
 +===== x264 =====
 +
 +From x265 to x264
 +<code>
 +ffmpeg -xerror -i input.mkv -hide_banner -threads 0 -map 0 -c:a copy -c:s copy -c:v libx264 -pix_fmt yuv420p output.mkv
 </code> </code>
  
Line 83: Line 104:
 </code> </code>
  
 +===== lates =====
  
 +<code bash>
 +#!/bin/bash
 +
 +CHATID=$1
 +BASEpath='/media/camere'
 +
 +[ -z "${CHATID}" ] && exit 1
 +
 +
 +for folder in $(find /media/camere/ -maxdepth 1 -name "camera*" -type d); do
 +
 + for video in $(find $folder -newer $folder.jpg -name "*mp4"); do
 + i=$(echo "$folder" | tail -c 2)
 +            preview=$BASEpath/preview$i.mp4
 +
 + ago_seconds=$(( $(date +%s) - $(stat -c %Y $video ) ))
 + if [ $ago_seconds -le 3600 ]; then
 + ago="$(( $ago_seconds / 60 )) minutes"
 + else
 + ago="$(( $ago_seconds / 3600 )) hours"
 + fi
 + echo "video $video is $ago"
 +
 + ( ffmpeg -i $video -r 0.5 -c:v libx264 -an -t 30 -y $preview </dev/null >/dev/null 2>/tmp/preview$i.log ; \
 + ~/telegram.sh "$ago (camera $i)" "${preview}" $CHATID ) &
 + sleep 1
 + done
 +done
 +</code>
 +
 +===== on motion =====
 +
 +<code>
 +#!/bin/bash
 +
 +CHROOT=/media/camere/
 +
 +FILENAME=$1
 +
 +# name of the first folder level inside CHROOT
 +INPUT=$(cut -d'/' -f1 <<<"${FILENAME/$CHROOT/}")
 +
 +# lowercase
 +INPUT=${INPUT,,}
 +
 +LOCK=${CHROOT}${INPUT}.lock
 +[ -f $FILENAME ] && ln -sf $FILENAME ${CHROOT}${INPUT}.jpg
 +
 +
 +[ -f $LOCK ] && exit 0
 +
 +touch $LOCK
 +name="`date +%Y-%m-%d_%H.%M`"
 +i=${INPUT/camera/}
 +video=$CHROOT/camera$i/$name.mp4
 +
 +echo "acquire from camera $i"
 +( ffmpeg -i rtsp://admin:test@192.168.0.9$i/12 -timeout 10 -stimeout 5000000 -c:v copy -an -t 300 -y $video </dev/null >/dev/null 2>/tmp/camera$i.log ; rm -f $LOCK ) &
 +</code>
 +
 +===== telegram =====
 +
 +<code>
 +#!/bin/sh
 +
 +set -x
 +
 +caption=$1
 +video=$2
 +CHATID=$3
 +
 +
 +TOKEN="xxxx:xxxx"
 +
 +[ -z "$CHATID" ] && exit 1
 +
 +
 +curl -F chat_id="$CHATID" \
 + -F document=@"${video}" \
 + -F caption="$caption" https://api.telegram.org/bot${TOKEN}/sendDocument
 +
 +</code>
 +
 +===== preview day =====
 +
 +<code>
 +#!/bin/bash
 +
 +set -x 
 +
 +CHATID=$1
 +CHATID=${CHATID:=xxxxxx}
 +i=$2
 +i=${i:=1}
 +SPEED=${3}
 +SPEED=${SPEED:=50}
 +
 +INVSPEED=$(echo "1/$SPEED" | bc -l)
 +
 +[ -z "$CHATID" ] && exit 1
 +
 +BASE=/media/camere
 +
 +DAY=$(date +"%Y-%m-%d")
 +video=$BASE/day-$i-$DAY.mp4
 +
 +echo "create $video"
 +
 +# 0.02: 20 volte la velocita
 +
 +if [ ! -f $video ]; then
 + ffmpeg -f concat -safe 0 \
 + -i <(find "$BASE/camera$i" -mmin -1440 -name "*mp4" -printf "%AT file '%p'\n" | sort -k1.1n | cut -c 21- ) \
 + -c:v libx264 -filter:v "setpts=$INVSPEED*PTS" -an -y $video
 + # -r 0.1 -c:v libx264 -an -y $video
 +fi
 +
 +
 +~/telegram.sh "Camera $i" "${video}" $CHATID
 +</code>
 +
 +===== camera motion =====
 +
 +<code>
 +INPUT=rtsp://foscam:foscam1@192.168.2.14/videoMain
 +ffprobe -i $INPUT
 +</code>
 +
 +<code>
 +ffmpeg -rtsp_transport tcp -i $INPUT -c:v libx264 -an -y test.mp4
 +</code>
 +
 +shinobi
 +<code>
 +ffmpeg -loglevel warning -analyzeduration 5000000 -probesize 5000000 \
 + -rtsp_transport tcp -i rtsp://admin:admin@192.168.2.29:554/12 \
 + -preset ultrafast -crf 15 -an -c:v libx264 -r 2 -f hls -s 640x380 \
 + -max_muxing_queue_size 1024 \
 + -tune zerolatency -g 1 -hls_time 2 -hls_list_size 3 -start_number 0 -hls_allow_cache 0 \
 + -hls_flags +delete_segments+omit_endlist "/dev/shm/streams/8Pkk5cE2xY/LIBm503cxy/s.m3u8" \
 + -f singlejpeg -vf fps=0.5 -s 640x380 pipe:0 \
 + -update 1 -r 1 "/dev/shm/streams/8Pkk5cE2xY/LIBm503cxy/s.jpg" \
 + -y -f mpegts -c:v libx264 http://127.0.0.1:8080/streamIn/8Pkk5cE2xY/LIBm503cxy/1
 +</code>
  • tips/video.1446980412.txt.gz
  • Last modified: 2015/11/08 12:00
  • by scipio