-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathnvidia_test.go
More file actions
executable file
·808 lines (698 loc) · 21.6 KB
/
Copy pathnvidia_test.go
File metadata and controls
executable file
·808 lines (698 loc) · 21.6 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
//go:build nvidia
// +build nvidia
package ffmpeg
import (
"fmt"
"os"
"path"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestNvidia_Transcoding(t *testing.T) {
codecsComboTest(t, supportedCodecsCombinations([]Acceleration{Nvidia}))
}
func TestNvidia_BadCodecs(t *testing.T) {
// Following test case validates that the transcoder throws correct errors for unsupported codecs
run, dir := setupTest(t)
defer os.RemoveAll(dir)
fname := dir + "/mpeg2.ts"
oname := dir + "/out.ts"
prof := P240p30fps16x9
cmd := `
cp "$1/../transcoder/test.ts" test.ts
# Generate an input file that uses unsupported codec MPEG2 and sanity check
ffmpeg -loglevel warning -i test.ts -an -c:v mpeg2video -t 1 mpeg2.ts
ffprobe -loglevel warning mpeg2.ts -show_streams | grep codec_name=mpeg2video
`
run(cmd)
// sanity check
err := Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Nvidia,
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Nvidia,
},
})
if err == nil || err.Error() != "Unsupported input codec" {
t.Error(err)
}
}
func TestNvidia_Pixfmts(t *testing.T) {
// Following test case validates pixel format at the decoding end
// Currently only YUV 4:2:0 is supported
run, dir := setupTest(t)
defer os.RemoveAll(dir)
prof := P240p30fps16x9
cmd := `
cp "$1/../transcoder/test.ts" test.ts
# sanity check original input type is 420p
ffmpeg -loglevel warning -i test.ts -an -c:v copy -t 1 in420p.mp4
ffprobe -loglevel warning in420p.mp4 -show_streams -select_streams v | grep pix_fmt=yuv420p
# generate unsupported 422p type
ffmpeg -loglevel warning -i test.ts -an -c:v libx264 -pix_fmt yuv422p -t 1 in422p.mp4
ffprobe -loglevel warning in422p.mp4 -show_streams -select_streams v | grep pix_fmt=yuv422p
`
run(cmd)
// sanity check
err := Transcode2(&TranscodeOptionsIn{
Fname: dir + "/in420p.mp4",
Accel: Nvidia,
}, []TranscodeOptions{
{
Oname: dir + "/out420p.mp4",
Profile: prof,
Accel: Nvidia,
},
})
if err != nil {
t.Error(err)
}
// check an input pixel format that is not GPU decodeable
err = Transcode2(&TranscodeOptionsIn{
Fname: dir + "/in422p.mp4",
Accel: Nvidia,
}, []TranscodeOptions{
{
Oname: dir + "/out422p.mp4",
Profile: prof,
Accel: Software,
},
})
if err == nil || err.Error() != "Unsupported input pixel format" {
t.Error(err)
}
cmd = `
# Check that 420p input produces 420p output for hw -> hw
ffprobe -loglevel warning out420p.mp4 -show_streams -select_streams v | grep pix_fmt=yuv420p
`
run(cmd)
// Check that yuvj420p is allowed (jpeg color range)
// TODO check for color range truncation?
cmd = `
ffmpeg -loglevel warning -i test.ts -an -c:v libx264 -pix_fmt yuvj420p -t 1 inj420p.mp4
ffprobe -loglevel warning inj420p.mp4 -show_streams -select_streams v | grep pix_fmt=yuvj420p
`
run(cmd)
err = Transcode2(&TranscodeOptionsIn{
Fname: dir + "/inj420p.mp4",
Accel: Nvidia,
}, []TranscodeOptions{{
Oname: dir + "/outj420p.mp4",
Profile: prof,
Accel: Nvidia,
},
})
if err != nil {
t.Error(err)
}
return
// Following test vaidates YUV 4:4:4 pixel format encoding which is only supported on limited set of devices for e.g. P100
// https://developer.nvidia.com/video-encode-decode-gpu-support-matrix
// check valid and invalid pixel formats
cmd = `
# generate semi-supported 444p type (encoding only)
ffmpeg -loglevel warning -i test.ts -an -c:v libx264 -pix_fmt yuv444p -t 1 in444p.mp4
ffprobe -loglevel warning in444p.mp4 -show_streams -select_streams v | grep pix_fmt=yuv444p
`
run(cmd)
// 444p is encodeable but not decodeable; produces a different error
// that is only caught at decode time. Attempt to detect decode bailout.
err = Transcode2(&TranscodeOptionsIn{
Fname: dir + "/in444p.mp4",
Accel: Nvidia,
}, []TranscodeOptions{
{
Oname: dir + "/out444p.mp4",
Profile: prof,
Accel: Nvidia,
},
})
if err == nil || err.Error() != "Invalid data found when processing input" {
t.Error(err)
}
// Software decode an and attempt to encode an invalid GPU pixfmt
// This implicitly selects a supported pixfmt for output
// The default Seems to be 444p for P100 but may be 420p for others
err = Transcode2(&TranscodeOptionsIn{
Fname: dir + "/in422p.mp4",
Accel: Software,
}, []TranscodeOptions{
{
Oname: dir + "/out422_to_default.mp4",
Profile: prof,
Accel: Nvidia,
},
})
if err != nil {
t.Error(err)
}
cmd = `
# 422p input (with sw decode) produces 444p on P100.
# Cards that don't do 444p may do 420p instead (untested)
ffprobe -loglevel warning out422_to_default.mp4 -show_streams -select_streams v | grep 'pix_fmt=\(yuv420p\|yuv444p\)'
# 422p input (with sw decode) produces 444p on P100.
# Cards that don't do 444p may do 420p instead (untested)
ffprobe -loglevel warning out422_to_default.mp4 -show_streams -select_streams v | grep 'pix_fmt=\(yuv420p\|yuv444p\)'
`
run(cmd)
}
func TestNvidia_Transcoding_Multiple(t *testing.T) {
// Tests multiple encoding profiles.
// May be skipped in 'short' mode.
if testing.Short() {
t.Skip("Skipping encoding multiple profiles")
}
run, dir := setupTest(t)
defer os.RemoveAll(dir)
cmd := `
# set up initial input; truncate test.ts file
ffmpeg -loglevel warning -i "$1"/../transcoder/test.ts -c:a copy -c:v copy -t 1 test.ts
# sanity check input dimensions for resolution pass through test
ffprobe -loglevel warning -show_streams -select_streams v test.ts | grep width=1280
ffprobe -loglevel warning -show_streams -select_streams v test.ts | grep height=720
`
run(cmd)
fname := dir + "/test.ts"
prof := P240p30fps16x9
orig := P720p30fps16x9
mkoname := func(i int) string { return fmt.Sprintf("%s/%d.ts", dir, i) }
out := []TranscodeOptions{
{
Oname: mkoname(0),
// pass through resolution has different behavior;
// basically bypasses the scale filter
Profile: orig,
Accel: Nvidia,
},
{
Oname: mkoname(1),
Profile: prof,
Accel: Nvidia,
},
{
Oname: mkoname(2),
Profile: orig,
Accel: Software,
},
{
Oname: mkoname(3),
Profile: prof,
Accel: Software,
},
// another gpu rendition for good measure?
{
Oname: mkoname(4),
Profile: prof,
Accel: Nvidia,
},
}
// generate the above outputs with the given decoder
test := func(decoder Acceleration) {
err := Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: decoder,
}, out)
if err != nil {
t.Error(err)
}
// XXX should compare ssim image quality of results
}
test(Nvidia)
test(Software)
}
func TestNvidia_Devices(t *testing.T) {
// XXX need to verify these are running on the correct GPU
// not just that the code runs
device := os.Getenv("GPU_DEVICE")
if device == "" {
t.Skip("Skipping device specific tests; no GPU_DEVICE set")
}
_, dir := setupTest(t)
defer os.RemoveAll(dir)
var err error
fname := "../transcoder/test.ts"
oname := dir + "/out.ts"
prof := P240p30fps16x9
// hw enc, sw dec
err = Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Nvidia,
Device: device,
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Software,
},
})
if err != nil {
t.Error(err)
}
// sw dec, hw enc
err = Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Software,
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Nvidia,
Device: device,
},
})
if err != nil {
t.Error(err)
}
// hw enc + dec
err = Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Nvidia,
Device: device,
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Nvidia,
},
})
if err != nil {
t.Error(err)
}
// hw enc + hw dec, separate devices
err = Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Nvidia,
Device: "0",
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Nvidia,
Device: "1",
},
})
if err != ErrTranscoderDev {
t.Error(err)
}
// invalid device for decoding
err = Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Nvidia,
Device: "9999",
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Software,
},
})
// if this fails with a generic error, it probably means
// ffmpeg error code from cuda init needs to be patched
if err == nil || err.Error() != "No such device" {
t.Error(fmt.Errorf(fmt.Sprintf("\nError being: '%v'\n", err)))
}
// invalid device for encoding
err = Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Software,
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Nvidia,
Device: "9999",
},
})
// if this fails with a generic error, it probably means
// ffmpeg error code from cuda init needs to be patched
if err == nil || err.Error() != "No such device" {
t.Error(fmt.Errorf(fmt.Sprintf("\nError being: '%v'\n", err)))
}
}
func TestNvidia_DrainFilters(t *testing.T) {
// Going from low fps to high fps has the potential to retain lots of
// GPU surfaces. Ensure this is not a problem anymore.
// May be skipped in 'short' mode.
if testing.Short() {
t.Skip("Skipping encoding multiple profiles")
}
run, dir := setupTest(t)
defer os.RemoveAll(dir)
cmd := `
# set up initial input; truncate test.ts file
ffmpeg -loglevel warning -i "$1"/../transcoder/test.ts -c:a copy -c:v copy -t 1 test.ts
`
run(cmd)
prof := P240p30fps16x9
prof.Framerate = 100
fname := dir + "/test.ts"
oname := dir + "/out.ts"
// hw enc + dec
err := Transcode2(&TranscodeOptionsIn{
Fname: fname,
Accel: Nvidia,
}, []TranscodeOptions{
{
Oname: oname,
Profile: prof,
Accel: Nvidia,
},
})
if err != nil {
t.Error(err)
}
cmd = `
# sanity check with ffmpeg itself
ffmpeg -loglevel warning -i test.ts -c:a copy -c:v libx264 -vf fps=100 -vsync 0 ffmpeg-out.ts
ffprobe -loglevel warning -show_streams -select_streams v -count_frames ffmpeg-out.ts > ffmpeg.out
ffprobe -loglevel warning -show_streams -select_streams v -count_frames out.ts > probe.out
# These used to be same, but aren't since we've diverged the flushing and PTS handling from ffmpeg
grep nb_read_frames=101 probe.out
grep duration=1.0100 probe.out
grep nb_read_frames=102 ffmpeg.out
grep duration=1.0200 ffmpeg.out
`
run(cmd)
}
func TestNvidia_CountFrames(t *testing.T) {
run, dir := setupTest(t)
defer os.RemoveAll(dir)
cmd := `
# run segmenter and sanity check frame counts . Hardcode for now.
ffmpeg -loglevel warning -i "$1"/../transcoder/test.ts -c:a copy -c:v copy -f hls test.m3u8
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test0.ts | grep nb_read_frames=120
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test1.ts | grep nb_read_frames=120
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test2.ts | grep nb_read_frames=120
ffprobe -loglevel warning -select_streams v -count_frames -show_streams test3.ts | grep nb_read_frames=120
`
run(cmd)
tc := NewTranscoder()
// Test decoding
for i := 0; i < 4; i++ {
in := &TranscodeOptionsIn{
Fname: fmt.Sprintf("%s/test%d.ts", dir, i),
Accel: Nvidia,
Device: "0",
}
res, err := tc.Transcode(in, nil)
if err != nil {
t.Error(err)
}
if res.Decoded.Frames != 120 {
t.Error(in.Fname, " Mismatched frame count: expected 120 got ", res.Decoded.Frames)
}
}
tc.StopTranscoder()
}
func TestNvidia_CountEncodedFrames(t *testing.T) {
countEncodedFrames(t, Nvidia)
}
func TestNvidia_RepeatedSpecialOpts(t *testing.T) {
_, dir := setupTest(t)
err := RTMPToHLS("../transcoder/test.ts", dir+"/out.m3u8", dir+"/out_%d.ts", "2", 0)
if err != nil {
t.Error(err)
}
// At some point we forgot to set the muxer type in reopened outputs
// This used to cause an error, so just check that it's resolved
in := &TranscodeOptionsIn{Accel: Nvidia}
out := []TranscodeOptions{{
Oname: "-",
Profile: P144p30fps16x9,
VideoEncoder: ComponentOptions{Opts: map[string]string{"zerolatency": "1"}},
Muxer: ComponentOptions{Name: "null"},
Accel: Nvidia}}
tc := NewTranscoder()
for i := 0; i < 4; i++ {
in.Fname = fmt.Sprintf("%s/out_%d.ts", dir, i)
_, err := tc.Transcode(in, out)
if err != nil {
t.Error(err)
}
}
tc.StopTranscoder()
// ALso test when a repeated option fails ?? Special behaviour for this?
}
func TestNvidia_API_MixedOutput(t *testing.T) {
run, dir := setupTest(t)
err := RTMPToHLS("../transcoder/test.ts", dir+"/out.m3u8", dir+"/out_%d.ts", "2", 0)
if err != nil {
t.Error(err)
}
profile := P144p30fps16x9
profile.Framerate = 123
tc := NewTranscoder()
for i := 0; i < 4; i++ {
in := &TranscodeOptionsIn{Fname: fmt.Sprintf("%s/out_%d.ts", dir, i)}
out := []TranscodeOptions{{
Oname: fmt.Sprintf("%s/%d.md5", dir, i),
AudioEncoder: ComponentOptions{Name: "drop"},
VideoEncoder: ComponentOptions{Name: "copy"},
Muxer: ComponentOptions{Name: "md5"},
}, {
Oname: fmt.Sprintf("%s/nv_%d.ts", dir, i),
Profile: profile,
AudioEncoder: ComponentOptions{Name: "copy"},
Accel: Nvidia,
}, {
Oname: fmt.Sprintf("%s/nv_audio_encode_%d.ts", dir, i),
Profile: profile,
Accel: Nvidia,
}, {
Oname: fmt.Sprintf("%s/sw_%d.ts", dir, i),
Profile: profile,
}}
res, err := tc.Transcode(in, out)
if err != nil {
t.Error(err)
}
if res.Decoded.Frames != 120 {
t.Error("Did not get decoded frames", res.Decoded.Frames)
}
if res.Encoded[1].Frames != res.Encoded[2].Frames {
t.Error("Mismatched frame count for hw/nv")
}
}
cmd := `
function check {
# Check md5sum for stream copy / drop
ffmpeg -loglevel warning -i out_$1.ts -an -c:v copy -f md5 ffmpeg_$1.md5
diff -u $1.md5 ffmpeg_$1.md5
ffmpeg -loglevel warning -i out_$1.ts -c:a aac -ar 44100 -ac 2 \
-vf hwupload_cuda,fps=123,scale_npp=w=256:h=144 -c:v h264_nvenc \
ffmpeg_nv_$1.ts
# sanity check ffmpeg frame count against ours
ffprobe -count_frames -show_streams -select_streams v ffmpeg_nv_$1.ts | grep nb_read_frames=246
ffprobe -count_frames -show_streams -select_streams v nv_$1.ts | grep nb_read_frames=245
ffprobe -count_frames -show_streams -select_streams v sw_$1.ts | grep nb_read_frames=245
ffprobe -count_frames -show_streams -select_streams v nv_audio_encode_$1.ts | grep nb_read_frames=245
# check image quality
ffmpeg -loglevel warning -i nv_$1.ts -i ffmpeg_nv_$1.ts \
-lavfi "[0:v][1:v]ssim=nv_stats_$1.log" -f null -
grep -Po 'All:\K\d+.\d+' nv_stats_$1.log | \
awk '{ if ($1 < 0.95) count=count+1 } END{ exit count > 5 }'
ffmpeg -loglevel warning -i sw_$1.ts -i ffmpeg_nv_$1.ts \
-lavfi "[0:v][1:v]ssim=sw_stats_$1.log" -f null -
grep -Po 'All:\K\d+.\d+' sw_stats_$1.log | \
awk '{ if ($1 < 0.95) count=count+1 } END{ exit count > 5 }'
# Really should check relevant audio as well...
}
check 0
check 1
check 2
check 3
`
run(cmd)
tc.StopTranscoder()
}
func TestNvidia_API_AlternatingTimestamps(t *testing.T) {
// Really should refactor this test to increase commonality with other
// tests that also check things like SSIM, MD5 hashes, etc...
// See TestNvidia_API_MixedOutput / TestTranscoder_EncoderOpts / TestTranscoder_StreamCopy
run, dir := setupTest(t)
err := RTMPToHLS("../transcoder/test.ts", dir+"/out.m3u8", dir+"/out_%d.ts", "2", 0)
if err != nil {
t.Error(err)
}
profile := P144p30fps16x9
profile.Framerate = 123
tc := NewTranscoder()
idx := []int{1, 0, 3, 2}
for _, i := range idx {
in := &TranscodeOptionsIn{Fname: fmt.Sprintf("%s/out_%d.ts", dir, i)}
out := []TranscodeOptions{{
Oname: fmt.Sprintf("%s/%d.md5", dir, i),
AudioEncoder: ComponentOptions{Name: "drop"},
VideoEncoder: ComponentOptions{Name: "copy"},
Muxer: ComponentOptions{Name: "md5"},
}, {
Oname: fmt.Sprintf("%s/nv_%d.ts", dir, i),
Profile: profile,
AudioEncoder: ComponentOptions{Name: "copy"},
Accel: Nvidia,
}, {
Oname: fmt.Sprintf("%s/nv_audio_encode_%d.ts", dir, i),
Profile: profile,
Accel: Nvidia,
}, {
Oname: fmt.Sprintf("%s/sw_%d.ts", dir, i),
Profile: profile,
}}
res, err := tc.Transcode(in, out)
if (i == 1 || i == 3) && err != nil {
t.Error(err)
}
if err != nil {
t.Error(err)
}
if res.Decoded.Frames != 120 {
t.Error("Did not get decoded frames", res.Decoded.Frames)
}
if res.Encoded[1].Frames != res.Encoded[2].Frames {
t.Error("Mismatched frame count for hw/nv")
}
}
cmd := `
function check {
# Check md5sum for stream copy / drop
ffmpeg -loglevel warning -i out_$1.ts -an -c:v copy -f md5 ffmpeg_$1.md5
diff -u $1.md5 ffmpeg_$1.md5
ffmpeg -loglevel warning -i out_$1.ts -c:a aac -ar 44100 -ac 2 \
-vf hwupload_cuda,fps=123,scale_npp=w=256:h=144 -c:v h264_nvenc \
-muxdelay 0 -copyts \
ffmpeg_nv_$1.ts
# sanity check ffmpeg frame count against ours
ffprobe -count_frames -show_streams -select_streams v ffmpeg_nv_$1.ts | grep nb_read_frames=246
ffprobe -count_frames -show_streams -select_streams v nv_$1.ts | grep nb_read_frames=245
ffprobe -count_frames -show_streams -select_streams v sw_$1.ts | grep nb_read_frames=245
ffprobe -count_frames -show_streams -select_streams v nv_audio_encode_$1.ts | grep nb_read_frames=245
# check image quality
ffmpeg -loglevel warning -i nv_$1.ts -i ffmpeg_nv_$1.ts \
-lavfi "[0:v][1:v]ssim=nv_stats_$1.log" -f null -
grep -Po 'All:\K\d+.\d+' nv_stats_$1.log | \
awk '{ if ($1 < 0.95) count=count+1 } END{ exit count > 5 }'
ffmpeg -loglevel warning -i sw_$1.ts -i ffmpeg_nv_$1.ts \
-lavfi "[0:v][1:v]ssim=sw_stats_$1.log" -f null -
grep -Po 'All:\K\d+.\d+' sw_stats_$1.log | \
awk '{ if ($1 < 0.95) count=count+1 } END{ exit count > 5 }'
# Really should check relevant audio as well...
}
check 0
check 1
check 2
check 3
`
run(cmd)
tc.StopTranscoder()
}
func TestNvidia_ShortSegments(t *testing.T) {
shortSegments(t, Nvidia, 1)
shortSegments(t, Nvidia, 2)
shortSegments(t, Nvidia, 3)
shortSegments(t, Nvidia, 5)
shortSegments(t, Nvidia, 6)
shortSegments(t, Nvidia, 10)
}
func TestNvidia_FractionalFPS(t *testing.T) {
fractionalFPS(t, Nvidia)
}
func TestNvidia_ConsecutiveMP4s(t *testing.T) {
consecutiveMP4s(t, Nvidia)
}
func TestNvidia_ConsecutiveMuxerOpts(t *testing.T) {
consecutiveMuxerOpts(t, Nvidia)
}
func TestNvidia_EncoderProfiles(t *testing.T) {
encodingProfiles(t, Nvidia)
}
func TestNvidia_SetGOPs(t *testing.T) {
setGops(t, Nvidia)
}
func TestNvidia_AudioOnly(t *testing.T) {
audioOnlySegment(t, Nvidia)
}
func TestNvidia_OutputFPS(t *testing.T) {
outputFPS(t, Nvidia)
}
func TestNvidia_NoKeyframe(t *testing.T) {
noKeyframeSegment(t, Nvidia)
}
func TestNvidia_NonMonotonicAudioSegment(t *testing.T) {
nonMonotonicAudioSegment(t, Nvidia)
}
func TestNvidia_DiscontinuityPixelFormat(t *testing.T) {
discontinuityPixelFormatSegment(t, Nvidia)
}
func TestNvidia_CompareVideo(t *testing.T) {
compareVideo(t, Nvidia)
}
func portraitTest(t *testing.T, input string, checkResults bool, profiles []VideoProfile) error {
wd, err := os.Getwd()
require.NoError(t, err)
outName := func(index int, resolution string) string {
return path.Join(wd, "..", "data", fmt.Sprintf("%s_%d_%s.ts", strings.ReplaceAll(input, ".", "_"), index, resolution))
}
fname := path.Join(wd, "..", "data", input)
in := &TranscodeOptionsIn{Fname: fname, Accel: Nvidia}
out := make([]TranscodeOptions, 0, len(profiles))
outFilenames := make([]string, 0, len(profiles))
for index, profile := range profiles {
filename := outName(index, profile.Resolution)
os.Remove(filename) // remove previous result if it exists
out = append(out, TranscodeOptions{
Oname: filename,
Profile: profile,
Accel: Nvidia,
})
outFilenames = append(outFilenames, filename)
}
_, resultErr := Transcode3(in, out)
if resultErr == nil && checkResults {
for _, filename := range outFilenames {
outInfo, err := os.Stat(filename)
if os.IsNotExist(err) {
require.NoError(t, err, fmt.Sprintf("output missing %s", filename))
} else {
defer os.Remove(filename)
}
require.NotEqual(t, outInfo.Size(), 0, "must produce output %s", filename)
}
}
return resultErr
}
func TestNvidia_Portrait(t *testing.T) {
hevc := VideoProfile{Name: "P240p30fps16x9", Bitrate: "600k", Framerate: 30, AspectRatio: "16:9", Resolution: "426x240", Encoder: H265}
// Usuall portrait input sample
require.NoError(t, portraitTest(t, "portrait.ts", true, []VideoProfile{
P360p30fps16x9, hevc, P144p30fps16x9,
}))
// Reported as not working sample, but transcoding works as expected
require.NoError(t, portraitTest(t, "videotest.mp4", true, []VideoProfile{
P360p30fps16x9, hevc, P144p30fps16x9,
}))
// Created one sample that is impossible to resize and fit within encoder limits and still keep aspect ratio:
notPossible := VideoProfile{Name: "P8K1x250", Bitrate: "6000k", Framerate: 30, AspectRatio: "1:250", Resolution: "250x62500", Encoder: H264}
err := portraitTest(t, "vertical-sample.ts", true, []VideoProfile{notPossible})
// We expect error
require.Error(t, err)
// Error should be `profile 250x62500 size out of bounds 146x146-4096x4096 input=16x4000 adjusted 250x62500 or 16x4096`
}
func TestNvidia_Resolution(t *testing.T) {
runResolutionTests_H264(t, Nvidia)
// TODO HEVC clamping
}
// XXX test bframes or delayed frames
func TestNvidia_DiscontinuityAudioSegment(t *testing.T) {
discontinuityAudioSegment(t, Nvidia)
}
func TestNvidia_Rotation(t *testing.T) {
runRotationTests(t, Nvidia)
}
func TestNvidia_Metadata(t *testing.T) {
// with nvenc we reopen the outputs so exercise that
runTestTranscoder_Metadata(t, Nvidia)
}