Scripts

Uit Projectgroep .540
Ga naar: navigatie, zoeken
#!/bin/sh

echo "\n\n*** Digilite-ZL starting... ***\n"
./si_gen_101_102.py
sleep 1
# WinTV-PVR USB2 settings..
v4l2-ctl -d 1 -c audio_layer_ii_bitrate=9 	# 192Kbps
v4l2-ctl -d 1 -c audio_stereo_mode=0 		# stereo
v4l2-ctl -d 1 -c stream_type=0			# MPEG-2 DVD = 3, MPEG-2 Program Stream=0
v4l2-ctl -d 1 -c video_bitrate=1383800		# set video bitrate 
v4l2-ctl -d 1 -c video_bitrate_mode=1		# constant bitrate = 1, variable bitrate = 0
v4l2-ctl -d 1 -c video_aspect=1			# 4:3

# resolution 720x576, 352x576
v4l2-ctl -d 1 --set-fmt-video=width=720,height=576
								
# television input = 0, composite input = 1, s-video input = 2, radio input = 1
v4l2-ctl -d 1	--set-input=1	>/dev/null			

# debug settings
#v4l2-ctl --list-devices
#v4l2-ctl -d 1 --log-status				

# Make named pipes in /tmp folder for sending data between programs
mkfifo /tmp/video.es 
mkfifo /tmp/audio.es 
mkfifo /tmp/video.pes 
mkfifo /tmp/audio.pes 
mkfifo /tmp/video.ts 
mkfifo /tmp/audio.ts
mkfifo /tmp/mux.ts
mkfifo /tmp/buffer.ts

# Encoding
#  
# Start ffmpeg to split MPEG-2 Program Stream into separate elementary streams, re-encode audio to lower bitrate (128k)

ffmpeg -loglevel quiet -i /dev/video1 -acodec mp2 -ab 128k -f mp2 -y /tmp/audio.es -vcodec copy -f mpeg2video -y /tmp/video.es >/dev/null 2>&1 & 

# Convert elementary streams into program streams
/usr/local/bin/esaudio2pes /tmp/audio.es 1152 48000 384 0 > /tmp/audio.pes &  
/usr/local/bin/esvideompeg2pes /tmp/video.es > /tmp/video.pes &

# Convert program streams into transport streams, Video PID= 256, Audio PID= 257
/usr/local/bin/pesaudio2ts 102 1152 48000 384 0 /tmp/audio.pes > /tmp/audio.ts &
/usr/local/bin/pesvideo2ts 101 25 64 1628000 0 /tmp/video.pes > /tmp/video.ts &

# Mux the Audio, Video and SI transport streams together to generate DVB TS mux
/usr/local/bin/tscbrmuxer b:1628000 /tmp/video.ts b:188000 /tmp/audio.ts b:4000 $HOME/digilite-zl/pat.ts b:4000 $HOME/digilite-zl/pmt.ts b:4000 $HOME/digilite-zl/sdt.ts b:4000 $HOME/digilite-zl/nit.ts b:4000 $HOME/digilite-zl/eit.ts b:4000 $HOME/digilite-zl/tdt.ts b:3137 null.ts > /tmp/mux.ts &


# Insert current Date/Time information (optional)
/usr/local/bin/tstdt /tmp/mux.ts > /tmp/buffer.ts &
/usr/local/bin/tspcrstamp /tmp/buffer.ts 1843137 > /dev/ttyUSB0 &

# send final buffer.ts to digilite-zl
#cp /tmp/mux.ts /dev/ttyUSB0 &

echo "\n"
echo -n "\n*** Press enter to stop the process at any time ***\n\n"
read var_n

killall esaudio2pes
killall esvideompeg2pes
killall pesaudio2ts
killall pesvideo2ts
killall ffmpeg
killall tscbrmuxer
killall tstdt


rm /tmp/video.ts
rm /tmp/audio.ts
rm /tmp/video.pes
rm /tmp/video.es
rm /tmp/audio.es
rm /tmp/audio.pes
rm /tmp/mux.ts
rm /tmp/buffer.ts

sleep 1

echo "\n\nStopped encoding.\n\n"