savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.39k stars 127 forks source link

Bad error reporting + blank video generation. #2710

Open smimram opened 1 year ago

smimram commented 1 year ago

The script

a = sine()
b = video.color(0x0000ff)
s = add([a, b])
output.audio_video(s)

reports the error

Error 5: this value has type
  source(...)
  .{
    duration : _,
    elapsed : _,
    fallible : _,
    id : _,
    is_active : _,
    is_ready : _,
    is_up : _,
    last_metadata : _,
    log : _,
    on_get_ready : _,
    on_leave : _,
    on_metadata : _,
    on_shutdown : _,
    on_track : _,
    remaining : _,
    seek : _,
    self_sync : _,
    skip : _,
    time : _
  } (inferred at ./src/libs/video.liq, line 537, char 2-34)
but it should be a subtype of the type of the value at ./blue-sine.liq, line 4, char 8-14
  source(...)
  .{
    duration : _,
    elapsed : _,
    fallible : _,
    id : _,
    is_active : _,
    is_ready : _,
    is_up : _,
    last_metadata : _,
    log : _,
    on_get_ready : _,
    on_leave : _,
    on_metadata : _,
    on_shutdown : _,
    on_track : _,
    remaining : _,
    seek : _,
    self_sync : _,
    skip : _,
    time : _
  } (inferred at ./blue-sine.liq, line 2, char 4-10)

This is unfortunate for two reasons

  1. the real cause of the typing error is elided (the ... in source(...))
  2. it used to work and should work out of the box: sine source should be able to produce blank video, which costs almost nothing now that we have canvas.
toots commented 1 year ago

The type reporting issue is a problem indeed. However, I disagree with the rest. Now that we're preparing ourselves for multi-track content, there's no telling what tracks will be available. Why not support 2 blank video tracks out of the box? Or 3? And 2 blank tracks too?

I kept the empty audio track for image decoders which, frankly, is the most important use case. For all other cases, we are gonna want the user to be explicit. I don't think that these simple examples are reflective of real-life use of the operators.

In fact, your example you become, when the API is complete the way I see it:

audio = sine().tracks.audio
video = video.color(0x0000ff).tracks.video
s = source({audio, video})