Skip to content

About

Software NTSC/PAL CVBS encoder written in python.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cvbs-encode

Overview

This is a software-defined Composite Video Baseband Signal (CVBS) encoder.
It is highly modular as the signal is generated from separate elements (frames, lines, separate pulses).
Supports all three video standards - NTSC, PAL, SECAM.
This project also includes a free PCM/IMA ADPCM encoder so it doesn't rely on FFmpeg or anything external.

Dependencies

cvbsgen.py

  • numpy
  • scipy
  • Pillow

encodingtool.py & pcm_lib.py

  • Pillow
  • opencv-python
  • numpy
  • numba

Usage

This encoder (cvbsgen.py) comes with a tool (encodingtool.py) that takes videos or pictures and generates a signal. But frames can be generated manually:

First, set your desired video syster:

cvbsgen.set_video_system(pal=False, secam=False) #NTSC
cvbsgen.set_video_system(pal=True) #PAL
cvbsgen.set_video_system(secam=True) #SECAM

Then, prepare your frame(s) and convert it to the right format. No image resampling required.

img = np.array(Image.open(path).convert("RGB"))

Finally, generate your frame:

#Frame gen usage:  
#gen_frame(frame_rgb, logo_img, color, progress, emph, filt, glob_sample):
#1. frame_rgb - the image to convert. It has to be a RGB numpy array of any width and height.
#2. logo_img - will display any logo in the upper left corner of the image (optional). It is not resized so make sure to resize it yourself
#3. color - excludes all color from the image if set to false
#4. progress - generates a progressive frame with both fields being the first.
#5. emph - applies a ~3MHz lowpass + HF emphasis filter that prevents cross-color
#6. filt - applies a lowpass filter to the color signal to prevent dot crawl on 1D decoders
#7. glob_sample - the starting sample for the frame. Can be always set to zero but for extra color stability put this
#The function returns the starting sample for the next frame and an 1D float32 numpy array.

cvbs_signal, glob_sample = cvbsgen.gen_frame(img, logo_img=None, color=True, progress=False, emph=False, filt=True, glob_sample=0)

If that is not enough you can individually use gen_field1 and gen_field2. I'm a bit lazy to further describe how to use them.

The sample rate for both standards is FIXED for simplicity (and because video system variables are a huge mess here):

#NTSC
F_SC = 3579545
FS = F_SC * 4.0 #14318180
SP_PER_LINE = 910.0
#PAL
FS = 14375000.0
SP_PER_LINE = 920.0

The levels are also fixed but can be edited easily:

#NTSC
IRE_WHITE = int(round(127+(0.714*128)))
IRE_BLACK = int(round(127+(0.054*128)))
IRE_BLANK = 127
IRE_SYNC  = int(round(127-(0.286*128)))
#PAL
IRE_WHITE = int(round(127+(0.7*128)))  
IRE_BLACK = 127  
IRE_BLANK = 127  
IRE_SYNC  = int(round(127-(0.3*128)))

Screenshots/Videos

NTSC full frame and video example

Frame
ezgif-19e494ceb11ce644

PAL full frame and video example

Frame
ezgif-1353e1ff719a1777

SECAM full frame and video example

Frame
ezgif-2f7514b6eaedcecb

About

Software NTSC/PAL CVBS encoder written in python.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Contributors

Languages