@@ -28,6 +28,7 @@ import (
28
28
"time"
29
29
"unicode"
30
30
31
+ "github.com/asticode/go-astiav"
31
32
"github.com/davidbyttow/govips/v2/vips"
32
33
"github.com/gabriel-vasile/mimetype"
33
34
"github.com/kenshaw/colors"
@@ -137,7 +138,7 @@ func open(name string) ([]string, error) {
137
138
return nil , fmt .Errorf ("unable to open directory %q: %v" , name , err )
138
139
}
139
140
for _ , entry := range entries {
140
- if s := entry .Name (); ! entry .IsDir () {
141
+ if s := entry .Name (); ! entry .IsDir () && extensions [ strings . TrimPrefix ( filepath . Ext ( s ), "." )] {
141
142
v = append (v , filepath .Join (name , s ))
142
143
}
143
144
}
@@ -188,9 +189,9 @@ func (args *Args) renderFile(name string) (image.Image, string, error) {
188
189
switch ext := strings .ToLower (strings .TrimPrefix (filepath .Ext (name ), "." )); {
189
190
case typ == "image/svg" :
190
191
g = args .renderResvg
191
- case isImageBuiltin (typ ):
192
+ case isImageBuiltin (typ ): // builtin
192
193
g = args .renderImage
193
- case isLibreOffice (typ , ext ):
194
+ case isLibreOffice (typ , ext ): // soffice
194
195
g , notStream = args .renderLibreOffice , true
195
196
case isVipsImage (typ ): // use vips
196
197
g = args .renderVips
@@ -295,9 +296,31 @@ func (args *Args) renderVips(r io.Reader, name string) (image.Image, error) {
295
296
}
296
297
297
298
// renderAstiv renders the image using the astiav (ffmpeg) library.
298
- func (args * Args ) renderAstiav (r io.Reader , name string ) (image.Image , error ) {
299
+ func (args * Args ) renderAstiav (_ io.Reader , name string ) (image.Image , error ) {
299
300
astiavOnce .Do (astiavInit (args .logger , args .Verbose ))
300
- return nil , nil
301
+ in := astiav .AllocFormatContext ()
302
+ defer in .Free ()
303
+ if err := in .OpenInput (name , nil , nil ); err != nil {
304
+ return nil , err
305
+ }
306
+ defer in .CloseInput ()
307
+ if err := in .FindStreamInfo (nil ); err != nil {
308
+ return nil , err
309
+ }
310
+ for i , is := range in .Streams () {
311
+ p := is .CodecParameters ()
312
+ typ := p .MediaType ()
313
+ if typ != astiav .MediaTypeVideo {
314
+ continue
315
+ }
316
+ args .logger ("stream %d: %s" , i , typ )
317
+ rate := ox .NewRate (p .BitRate (), time .Second )
318
+ args .logger (
319
+ " bit rate: %s, pixel format: %v, time base: %v, duration: %v, frames: %v" ,
320
+ rate , p .PixelFormat (), is .TimeBase (), is .Duration (), is .NbFrames (),
321
+ )
322
+ }
323
+ return nil , errors .New ("oops!" )
301
324
}
302
325
303
326
// renderLibreOffice renders the image using the `soffice` command.
@@ -506,6 +529,20 @@ func vipsLevel(level vips.LogLevel) string {
506
529
// astiavInit initializes the astiav package.
507
530
func astiavInit (logger func (string , ... any ), verbose bool ) func () {
508
531
return func () {
532
+ level := astiav .LogLevelQuiet
533
+ if verbose {
534
+ level = astiav .LogLevelDebug
535
+ }
536
+ astiav .SetLogLevel (level )
537
+ astiav .SetLogCallback (func (c astiav.Classer , l astiav.LogLevel , fmt , msg string ) {
538
+ var cs string
539
+ if c != nil {
540
+ if cl := c .Class (); cl != nil {
541
+ cs = "class: " + cl .String ()
542
+ }
543
+ }
544
+ logger ("astiav %d: %s%s" , l , strings .TrimSpace (msg ), cs )
545
+ })
509
546
}
510
547
}
511
548
@@ -661,7 +698,74 @@ func isLibreOffice(typ, ext string) bool {
661
698
return false
662
699
}
663
700
664
- var urlRE = regexp .MustCompile (`(?i)^https?` )
701
+ // extensions are the extensions to check for directories.
702
+ var extensions = map [string ]bool {
703
+ "3g2" : true ,
704
+ "3gp" : true ,
705
+ "asf" : true ,
706
+ "avif" : true ,
707
+ "avi" : true ,
708
+ "bmp" : true ,
709
+ "bpg" : true ,
710
+ "csv" : true ,
711
+ "doc" : true ,
712
+ "docx" : true ,
713
+ "dvb" : true ,
714
+ "dwg" : true ,
715
+ "eot" : true ,
716
+ "flv" : true ,
717
+ "gif" : true ,
718
+ "heic" : true ,
719
+ "heif" : true ,
720
+ "ico" : true ,
721
+ "jp2" : true ,
722
+ "jpeg" : true ,
723
+ "jpf" : true ,
724
+ "jpg" : true ,
725
+ "jxl" : true ,
726
+ "jxs" : true ,
727
+ "m4v" : true ,
728
+ "markdown" : true ,
729
+ "md" : true ,
730
+ "mj2" : true ,
731
+ "mkv" : true ,
732
+ "mov" : true ,
733
+ "mp4" : true ,
734
+ "mpeg" : true ,
735
+ "mpg" : true ,
736
+ "odc" : true ,
737
+ "odf" : true ,
738
+ "odg" : true ,
739
+ "odp" : true ,
740
+ "ods" : true ,
741
+ "odt" : true ,
742
+ "otf" : true ,
743
+ "otg" : true ,
744
+ "otp" : true ,
745
+ "ots" : true ,
746
+ "ott" : true ,
747
+ "pdf" : true ,
748
+ "png" : true ,
749
+ "ppt" : true ,
750
+ "pptx" : true ,
751
+ "pub" : true ,
752
+ "rtf" : true ,
753
+ "svg" : true ,
754
+ "tiff" : true ,
755
+ "tsv" : true ,
756
+ "ttc" : true ,
757
+ "ttf" : true ,
758
+ "txt" : true ,
759
+ "webm" : true ,
760
+ "webp" : true ,
761
+ "woff2" : true ,
762
+ "woff" : true ,
763
+ "xls" : true ,
764
+ "xlsx" : true ,
765
+ "xpm" : true ,
766
+ }
767
+
768
+ var urlRE = regexp .MustCompile (`(?i)^https?://` )
665
769
666
770
var (
667
771
vipsOnce sync.Once
0 commit comments