File: ffmpeg_raw_and_copy_decoder.liq

package info (click to toggle)
liquidsoap 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,372 kB
  • sloc: ml: 71,806; javascript: 27,320; ansic: 398; xml: 114; sh: 99; lisp: 96; makefile: 26
file content (92 lines) | stat: -rw-r--r-- 1,990 bytes parent folder | download | duplicates (2)
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
log.level.set(5)
settings.decoder.decoders.set(["ffmpeg"])

fname = argv(default="", 1)

out = {"#{fname}+ffmpeg_raw_and_copy_decoder-#{random.int()}.mp4"}

s = single(fname)
s = once(s)

done = ref(false)

#clock.assign_new(sync='none', [s])
def on_close(encoded_fname) =
  if
    not done()
  then
    done := true

    process.run("sync")

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

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

    let json.parse (iparsed :
      {
        streams: [
          {
            index: int,
            channel_layout: string?,
            sample_rate: string?,
            sample_fmt: string?,
            codec_type: string,
            pix_fmt: string?
          }
        ]
      }
    ) = ijson

    let json.parse (oparsed :
      {
        streams: [
          {
            index: int,
            channel_layout: string?,
            sample_rate: string?,
            sample_fmt: string?,
            codec_type: string,
            pix_fmt: string?
          }
        ]
      }
    ) = ojson

    filter = fun (type, l) -> list.filter(fun (s) -> s.codec_type == type, l)
    sort =
      fun (l) ->
        list.sort(fun (s1, s2) -> if s1.index < s2.index then -1 else 1 end, l)

    let [{index = _, ...iaudio}] = sort(filter("audio", iparsed.streams))
    let [{index = _, ...ivideo}] = sort(filter("video", iparsed.streams))
    let [{index = _, ...oaudio}] = sort(filter("audio", oparsed.streams))
    let [{index = _, ...ovideo}] = sort(filter("video", oparsed.streams))

    if
      iaudio == oaudio and ivideo == ovideo
    then
      test.pass()
    else
      test.fail()
    end
  end
end

output.file(
  fallible=true,
  on_close=on_close,
  %ffmpeg(format = "mkv", %audio.copy, %video.raw(codec = "libx264")),
  out,
  s
)