Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: RegisCasey/Baird-Encoder
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: mainline
Choose a base ref
...
head repository: RegisCasey/Baird-Encoder
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 12, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    addaleax Anna Henningsen
    Copy the full SHA
    f917d0a View commit details

Commits on Jul 15, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    jasnell James M Snell
    Copy the full SHA
    2729dce View commit details
  2. Delete BairdEncoder-v1-RegisC.py

    Outdated version.
    RegisCasey authored Jul 15, 2023

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    danielleadams Danielle Adams
    Copy the full SHA
    dc11fe9 View commit details
Showing with 43 additions and 48 deletions.
  1. +42 −47 BairdEncoder-v1-RegisC.py → BairdEncoder-v1.1-RegisC.py
  2. +1 −1 README.md
89 changes: 42 additions & 47 deletions BairdEncoder-v1-RegisC.py → BairdEncoder-v1.1-RegisC.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Baird Encoder - Image to Mechanical TV Signal Converter v1 - July 11, 2023
# By Regis "Casey" C.
# Baird Encoder - Image to Mechanical TV Signal Converter v1.10 - July 15, 2023
# By Regis "Casey" C., opimized by "Sylvia".

# REQUIRES THE PIL/PILLOW AND PYSOUNDFILE PYTHON LIBRARIES (NOT INCLUDED)

@@ -59,6 +59,9 @@
Combine = False # If False, saves every frame as an individual audio file.
# Setting it to True combines all the frames to one audio.
# IMAGES MUST BE IN THE SAME RESOLUTION AS EACH OTHER!
allow_mega_conversions = False # If True, the program will be able to convert large
# image to audio (such as 1080p pics), but the audio will be larger than 1 second.
# *SLD_MODE* AND *COMBINE* MUST BE SET TO FALSE!
sld_mode = False # Scanline data (.sld), file format container.

# .SLD SETTINGS - sld_mode MUST BE SET TO "TRUE" TO USE THESE SETTINGS>
@@ -70,13 +73,11 @@
# (Color data is trimmed at best.)


from ctypes import resize
from PIL import Image
import soundfile as sf
import os
import sys
import time
#import shutil

MediaPerameters = {'FPS': 30, # LEAVE DICTIONARY AS IS! The script will correct
'ColorVid': False, # the values for you!
@@ -104,21 +105,33 @@
def measureResizeCheck(ImgArea, FPS, Samplerate):
FrameMax = Samplerate/ImgArea
FrameMax = round(FrameMax)
if FrameMax < 1:
FrameMax = 3
HypoMax = round(96000/ImgArea,1)
SampRequire = ImgArea * FPS
print(f'This sample rate of {Samplerate} can only support a max of about {round(FrameMax)} frames at this resolution.')
if FPS > FrameMax:
print(f'I am unable to create an audio with the current sample rate of {Samplerate}hz.')
print(f'You will at least need a sample rate of {round(SampRequire)}hz to create this video...')
if SampRequire > 96000: # Typical max sample rate for PCM recorders.
if FrameMax < 1 and allow_mega_conversions == True:
print(f'I can do this conversion, but the final audio will be {ImgArea/Samplerate} seconds long.')
possibleAction = True
return possibleAction
elif Batch == True and Combine == True or allow_mega_conversions == False:
HypoMax = round(94000/ImgArea,1)
SampRequire = ImgArea * FPS
print(f'This sample rate of {Samplerate} can only support a max of about {round(FrameMax)} frames at this resolution.')
if FPS > FrameMax:
print(f'I am unable to create an audio with the current sample rate of {Samplerate}hz.')
print(f'You will at least need a sample rate of {round(SampRequire)}hz to create this video...')
if SampRequire > 96000: # Typical max sample rate for PCM recorders.
print('...which is not possible seeing how large the sample rate would need to be.')
print(f'The most that could be done with this image is {HypoMax} frames per second at 96000hz.')
time.sleep(10)
possibleAction = False
return possibleAction
elif FrameMax < 1:
print('...which is not possible seeing how large the sample rate would need to be.')
print(f'The most I can do with this image is {HypoMax} frames per second at 96000hz.')
print(f'You will need to set the *allow_mega_conversions* to True to convert this image,')
print ('or switch to .sld mode.')
time.sleep(10)
possibleAction = False
return possibleAction


# Code to create an .sld file.
def CreateFile(mediaPerams, xnum, ynum, mediaSamples,addSamp2=None, addSamp3=None):
filename = outDir+outName
with open(filename, 'w') as media_container:
@@ -160,8 +173,17 @@ def CreateFile(mediaPerams, xnum, ynum, mediaSamples,addSamp2=None, addSamp3=Non
comp_mode = 3
MediaPerameters['Compression'] = compName

if allow_mega_conversions == True and Combine == True:
Combine == False
print('*allow_mega_conversions* is enabled, *Combine* is now disabled.')
time.sleep(5)


for nextPic in backlog:
inName = inFile + nextPic # Your source image, please include extentsion.
if Batch == True:
inName = inFile + nextPic # Your source image, please include extentsion.
else:
inName = inFile

debugMode = False
# If True, displays the image that is being written to the audio.
@@ -184,7 +206,7 @@ def CreateFile(mediaPerams, xnum, ynum, mediaSamples,addSamp2=None, addSamp3=Non
Ynum = ToConvert.size[1]

if sld_mode == False and PossibleActionFlag == False:
PossibleAction = measureResizeCheck(OutSample,FPS,48000)
PossibleAction = measureResizeCheck(OutSample,FPS,44100)
if PossibleAction == False:
sys.exit()
break
@@ -197,11 +219,11 @@ def CreateFile(mediaPerams, xnum, ynum, mediaSamples,addSamp2=None, addSamp3=Non
Shades = []
GreenSound = []
Blue = []
if ColorMode == False:
ReadPix = ToConvert.convert('L')
for pix1 in range(ToConvert.size[0]): # Reads each pixel, vertically.
for pix2 in range(ToConvert.size[1]):
#Vert += 1\
if ColorMode == False:
ReadPix = ToConvert.convert('L')
ReadPix = ToConvert.getpixel((pix1,pix2))

R,G,B = ReadPix
@@ -301,41 +323,14 @@ def CreateFile(mediaPerams, xnum, ynum, mediaSamples,addSamp2=None, addSamp3=Non
totalLoop +=1
AmpVals = NewAmp[:]
if Combine == False and sld_mode == False:
if allow_mega_conversions == True:
OutSample == 44100
outAud = sf.write(f"{outDir}{outName}_{Xnum}x{Ynum}_{loopnum}.wav", AmpVals, OutSample, 'PCM_24')
elif Combine == True:
collectSamples += AmpVals[:]
collectSamples2 += GreenVals[:]
collectSamples3 += BlueVals[:]

#loopnum +=1

# decompressImg = []

# if debugDecomp == True:
# for valM in AmpVals:
# if "^" in AmpVals[0]:
# print('Compression detected!')
# repeatVal = ((AmpVals[0])[1:5])
# compVal = ((AmpVals[0])[6:])
# print(repeatVal.lstrip('0'))
# repeatVal = repeatVal.lstrip('0')
# repeatVal = int(repeatVal)
# for valN in range(repeatVal):
# decompressImg.append(float(compVal))
# try:
# decompressImg.append(float(AmpVals[0])) # Converts the audio samples into
# # floating point numbers
# except:
# print("This string cannot be made into a float.")
# Shades = []
# for val2 in decompressImg:
# val2 = val2 * -255 # The magic number modifier, also contrast control.
# if val2 >= 255:
# val2 == 255 # Caps image values
# val2 = int(round(val2))
# val2 = 255 - val2 - 164 # Inverts image to a positive, add/subtract for brightness.
# Shades.append(val2)


if debugMode == True: # Displays the converted image
FrameConvert = Image.new('RGB',(ToConvert.size[0], ToConvert.size[1]))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ Open the `BairdEncoder-v1-RegisC.py` script in a code editor, and modify the val
that will tell you how many audio samples are required for one frame. Multiply that number by your frame rate, and that will tell you how many audio samples are required to store one second of that. If the value is greater than 48000 (or 96000),
then it won't fit in the `.wav` format.), you may need to save your file under the `.sld` container instead.

*See dictionary for more documentaion*
*See [wiki](https://github.com/RegisCasey/Baird-Encoder/wiki)(WIP) for more documentaion*

## .sld File Format
`.sld` is a label based on .txt and audio, which allows you to convert images that are too big, or has too high of a framerate, for a .wav file to support, thus extending the limits on the videos you can convert.