Skip to content

Ktotosh/cvbs-encode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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 PAL and NTSC. SECAM not supported yet.

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.

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. img = np.array(Image.open(path).convert("RGB")) for example
  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.

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)))

If that is not enough you can individually use gen_field1 and gen_field2.

Screenshots/Videos

NTSC full frame and video example

Frame
ezgif-19e494ceb11ce644

PAL full frame and video example

Frame
ezgif-1353e1ff719a1777

About

Software NTSC/PAL CVBS encoder written in python.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages