Skip to content

Instantly share code, notes, and snippets.

View matiaspl's full-sized avatar

Mateusz Starzak matiaspl

  • @Tellyo & Lodz University of Technology
  • Lodz, Poland
View GitHub Profile
@matiaspl
matiaspl / gist:23248eedc23b0890b8cadc59dc9a62c3
Last active November 5, 2023 21:00
gstreamer pipelines with Intel HW acceleration

TS: VAAPI H264 to H265 transcode with deinterlacing

gst-launch-1.0 --gst-debug=2 -ev mpegtsmux name="mux"
souphttpsrc location=http://stream/url ! parsebin ! queue ! vaapih264dec ! vaapipostproc deinterlace-mode=1 deinterlace-method=4 width=1280 height=720 ! vaapih265enc rate-control=vbr bitrate=2000 keyframe-period=50 max-bframes=0 quality-level=4 ! video/x-h265,stream-format=hvc1 ! queue ! h265parse config-interval=1 ! video/x-h265,alignment=au,stream-format=byte-stream ! mux. tcpserversink host=0.0.0.0 port=1234

TS: audio transcode

gst-launch-1.0 --gst-debug=2 -ev souphttpsrc location=http://stream/url ! tsparse ! tsdemux ! queue ! flump3dec ! audioconvert ! avenc_aac ! aacparse ! mpegtsmux ! tcpserversink host=0.0.0.0 port=1234

TS: audio remux

@matiaspl
matiaspl / ffmpeg_bmd_videotoolbox.md
Last active November 5, 2023 21:04
Stream RTMP with FFMPEG + BMD Ultrastudio Recorder on OSX (hardware accelerated encoding)

You might ask why would anyone do it in the first place? Well, OBS is the only reasonable free tool for OSX for streaming but it has a flaw which makes it impossible to stream 1080p50/p60 on my i5 MacBook Pro. It works if you disable preview, but then if you can't see the video there's no reason for using OBS ;)

You need ffmpeg-dl from ffmpegdecklink brew package by AMIA Open Source (brew install ffmpegdecklink). It's worth noting that unlike brew's regular ffmpeg this one allows building ffmpeg with additional libraries (e.g. brew install ffmpegdecklink -with-srt in case you need SRT).

/usr/local/opt/ffmpegdecklink/bin/ffmpeg-dl -f decklink -i 'UltraStudio Mini Recorder' -video_input hdmi -format_code Hi50 -audio_input embedded -channels 2 -vf yadif=1 -c:v h264_videotoolbox -profile:v main -b:v 6M -pix_fmt yuv420p -color_range 1 -coder cabac -c:a aac_at -b:a 192k -f flv rtmp://your_server/app/key

What this does is capture 1080i50 signal from HDMI input (use *-vi

@matiaspl
matiaspl / mpv_vectorscope_waveform.md
Last active November 5, 2023 21:22
mpv based vectorscope, waveform monitor and EBU-R128 audio meter

mpv --hwdec="no" --lavfi-complex="[aid1]asplit=3[sv][eb][av];[sv]showvolume=b=4:w=720:h=68[sv-v];[eb]ebur128=video=1:size=720x540:meter=18[eb-v][ao];[av]avectorscope=s=720x540:zoom=1.3:rc=2:gc=200:bc=10:rf=1:gf=8:bf=7[av-v];[sv-v][eb-v][av-v]vstack=3[1c];[vid1]split=4[v][wf][wfc][vs];[wf]waveform=m=1:d=0:r=0:c=7[wf-vus];[wf-vus][v]scale2ref=iw:1220-ih[wf-va][sig];[wf-va]setsar=1[wf-v];[wfc]waveform=m=0:d=0:r=0:c=7,scale=610x610,setsar=1[wfc-v];[vs]vectorscope=m=color3:g=color,scale=610x610,setsar=1[vs-v];[sig][wf-v]vstack[2c];[wfc-v][vs-v]vstack[3c];[1c][2c][3c]hstack=3,scale=1280:-1[vo]" rtmp://server/app/key

@matiaspl
matiaspl / preemphasis.ff
Last active December 13, 2023 13:32
Internet radio to regular radio with 50us (European) preemphasis and RDS using pifmrds - runs fine on RPi1 (sox firfit used as the audio processor)
20 0.000
50 0.001
100 0.004
400 0.068
1000 0.409
2000 1.445
3000 2.761
4000 4.115
5000 5.400
6000 6.583
@matiaspl
matiaspl / channels_to_scan_table.md
Last active December 17, 2023 00:59
Convert w_scan channels.conf list to a DVBv5 dtv-scan-tables for tvheadend

If you happen to have created a channels.conf after a lengthy scanning process using w_scan:

w_scan -f c -c PL -X -S 1 -v

(in this case a Polish DVB-C scan with SR 6875)

then you can use the following line to create your own scan table (you have to run it as root to write to /usr/share):

cut -d: -f2,3,4,5,6 channels.conf | sort -u | awk -F["/:"] '{ printf "[CHANNEL]\n\tDELIVERY_SYSTEM = DVBC/ANNEX_A\n\tFREQUENCY = %s\n\tSYMBOL_RATE =  %s\n\tINNER_FEC = %s\n\tMODULATION = %s\n\tINVERSION = %s\n\n", $1, $3, $4, $5, $2 }' > /usr/share/dvb/dvb-c/pl-Toya
@matiaspl
matiaspl / hi3521a_console_output.txt
Last active January 7, 2024 07:15
Hacking a Hi3521 ARBCV100 4x1 multiviewer / seamless switcher (see comments!)
U-Boot 2010.06 (Aug 11 2018 - 18:47:37)
Check Flash Memory Controller v100 ... Found
SPI Nor(cs 0) ID: 0xc2 0x20 0x17
Block:64KB Chip:8MB Name:"MX25L6436F"
SPI Nor total size: 8MB
Cannot found a valid SPI Nand Device
In: serial
Out: serial
Err: serial
@matiaspl
matiaspl / sync_bar_gen.sh
Last active February 21, 2024 13:43
moving bar testcard generator for synchronization testing based on timestamps
#!/bin/bash
fps=25
delay=2
width=640
height=360
bar_width=20
bar_height=$((height / 2))
bar_speed=4
Endeco's idea:
/etc/udev/rules.d/11-usb-hotplug.rules
ATTRS(idVendor)=="1edb", ATTRS(idProduct)=="be??", RUN+="/etc/udev/atem.sh"
/etc/udev/atem.sh
echo "1edb be55" | tee /sys/bus/usb/drivers/uvcvideo/new_id
echo "1edb be49" | tee /sys/bus/usb/drivers/uvcvideo/new_id
atem mini: be49
C:\ffmpeg\bin>ffplay -f lavfi testsrc=s=1080x1920:r=60 -vf format=yuv444p,transpose=1,scroll=horizontal=0.005,chromashift=cbh=-50:crh=-50,extractplanes=y+u+v[y][u][v],[y][u][v]hstack
C:\ffmpeg\bin>ffmpeg -f lavfi -i colorchart=patch_size=320x320:r=60:d=10 -vf format=yuv420p,scroll=horizontal=0.005:vertical=0.005 -c:v h264 -cq 0 -f mp4 chroma_motion_patch_test_420.mp4
#!/bin/bash
: ${1?"Usage: $0 FPS (i.e. 25, 29.97, 60000/1001)"}
fps=$1
samplerate=48000
size=1920x1080
debug="-hide_banner"
#debug="-loglevel debug" # verbose
fontfile="UbuntuMono-R.ttf"