File: ffmpeg_inline_encode_decode.liq

package info (click to toggle)
liquidsoap 2.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 11,912 kB
  • sloc: ml: 67,867; javascript: 24,842; ansic: 273; xml: 114; sh: 96; lisp: 96; makefile: 26
file content (103 lines) | stat: -rw-r--r-- 2,178 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
log.level.set(5)
settings.decoder.decoders.set(["ffmpeg"])

out_copy = "ffmpeg_inline_encode_decode_copy.mp4"
if file.exists(out_copy) then file.remove(out_copy) end
out_encode = "ffmpeg_inline_encode_decode_encode.mp4"
if file.exists(out_encode) then file.remove(out_encode) end

let {audio} = source.tracks(sine(duration=10.))
let {video} = source.tracks(video.testsrc.ffmpeg(duration=10.))
s = source({audio=audio, video=video})

s = once(s)
todo = ref(2)
done = ref(false)

def on_close(_) =
  def check(out) =
    process.run("sync")

    j =
      process.read(
        "ffprobe -v quiet -print_format json -show_streams #{
          process.quote(out)
        }"
      )

    let json.parse (parsed :
      {
        streams: [
          {
            channel_layout: string?,
            sample_rate: string?,
            sample_fmt: string?,
            codec_name: string?,
            pix_fmt: string?
          }
        ]
      }
    ) = j

    video_stream =
      list.find((fun (stream) -> null.defined(stream.pix_fmt)), parsed.streams)

    audio_stream =
      list.find(
        (fun (stream) -> null.defined(stream.sample_rate)), parsed.streams
      )

    null.get(video_stream.codec_name) == "h264"
  and
    null.get(video_stream.pix_fmt) == "yuv420p"
  and
    null.get(audio_stream.channel_layout) == "stereo"
  and
    null.get(audio_stream.codec_name) == "aac"
  and
    null.get(audio_stream.sample_fmt) == "fltp"
  and
    null.get(audio_stream.sample_rate) == "44100"
  end

  todo := !todo - 1
  if
    not done() and !todo == 0
  then
    done := true

    if
      check(out_copy) and check(out_encode)
    then
      test.pass()
    else
      test.fail()
    end
  end
end

s =
  ffmpeg.encode.audio_video(
    id="encoder",
    %ffmpeg(%video(codec = "libx264", b = "5m"), %audio(codec = "aac")),
    s
  )

output.file(
  fallible=true,
  on_close=on_close,
  %ffmpeg(%video.copy, %audio.copy),
  out_copy,
  s
)

s = ffmpeg.decode.audio_video(id="decoder", s)

#clock.assign_new(sync='none', [s])
output.file(
  fallible=true,
  on_close=on_close,
  %ffmpeg(%video(codec = "libx264", b = "5m"), %audio(codec = "aac")),
  out_encode,
  s
)