code cleanup
This commit is contained in:
parent
917be1687f
commit
5336968e05
34 changed files with 193 additions and 115 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
ffmpeg "github.com/u2takey/ffmpeg-go"
|
||||
)
|
||||
|
||||
|
@ -12,7 +13,7 @@ func MergeSegments(
|
|||
outputPath string,
|
||||
) (string, error) {
|
||||
if len(segmentPaths) == 0 {
|
||||
return "", fmt.Errorf("no segments to merge")
|
||||
return "", errors.New("no segments to merge")
|
||||
}
|
||||
listFilePath := outputPath + ".segments.txt"
|
||||
listFile, err := os.Create(listFilePath)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/asticode/go-astiav"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func RemuxFile(inputFile string) error {
|
||||
|
@ -29,7 +30,7 @@ func RemuxFile(inputFile string) error {
|
|||
|
||||
inputCtx := astiav.AllocFormatContext()
|
||||
if inputCtx == nil {
|
||||
return fmt.Errorf("failed to alloc input format context")
|
||||
return errors.New("failed to alloc input format context")
|
||||
}
|
||||
defer inputCtx.Free()
|
||||
|
||||
|
@ -59,7 +60,7 @@ func RemuxFile(inputFile string) error {
|
|||
}
|
||||
outStream := outCtx.NewStream(nil)
|
||||
if outStream == nil {
|
||||
return fmt.Errorf("failed to create new stream in output context")
|
||||
return errors.New("failed to create new stream in output context")
|
||||
}
|
||||
if err := inCP.Copy(outStream.CodecParameters()); err != nil {
|
||||
return fmt.Errorf("failed to copy codec parameters: %w", err)
|
||||
|
@ -69,7 +70,7 @@ func RemuxFile(inputFile string) error {
|
|||
inToOutIdx[inIdx] = len(inToOutIdx)
|
||||
}
|
||||
if len(inToOutIdx) == 0 {
|
||||
return fmt.Errorf("no supported streams to remux")
|
||||
return errors.New("no supported streams to remux")
|
||||
}
|
||||
|
||||
if !outCtx.OutputFormat().Flags().Has(astiav.IOFormatFlagNofile) {
|
||||
|
@ -89,7 +90,7 @@ func RemuxFile(inputFile string) error {
|
|||
defer packet.Free()
|
||||
for {
|
||||
if err := inputCtx.ReadFrame(packet); err != nil {
|
||||
if err == astiav.ErrEof {
|
||||
if errors.Is(err, astiav.ErrEof) {
|
||||
break
|
||||
}
|
||||
return fmt.Errorf("error reading frame: %w", err)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/jpeg"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/asticode/go-astiav"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func ExtractVideoThumbnail(videoPath string, imagePath string) error {
|
||||
|
@ -65,7 +65,7 @@ func ExtractVideoThumbnail(videoPath string, imagePath string) error {
|
|||
err := formatCtx.ReadFrame(packet)
|
||||
if err != nil {
|
||||
if errors.Is(err, astiav.ErrEof) {
|
||||
return fmt.Errorf("end of file reached before finding video frame")
|
||||
return errors.New("end of file reached before finding video frame")
|
||||
}
|
||||
return fmt.Errorf("failed reading frame: %w", err)
|
||||
}
|
||||
|
@ -113,5 +113,5 @@ func ExtractVideoThumbnail(videoPath string, imagePath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("timeout while waiting for video frame")
|
||||
return errors.New("timeout while waiting for video frame")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue