Skip to content

Commit b12217c

Browse files
committed
ffprobe should never be fatal
1 parent 3e71f15 commit b12217c

File tree

8 files changed

+215
-58
lines changed

8 files changed

+215
-58
lines changed

.github/workflows/build.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
name: Build for ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
- os: ubuntu-latest
14+
file: transcoder-linux-amd64
15+
args: --best --lzma
16+
strip: true
17+
cgo: 0
18+
- os: windows-latest
19+
file: transcoder-win-amd64.exe
20+
args: -9
21+
strip: false
22+
cgo: 1
23+
- os: macos-latest
24+
file: transcoder-osx-amd64
25+
args: --best
26+
strip: false
27+
cgo: 1
28+
steps:
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v1
32+
with:
33+
go-version: 1.17
34+
35+
- name: Check out code into the Go module directory
36+
uses: actions/checkout@v2
37+
38+
- name: Build
39+
run: go build -ldflags="-s -w" -v -o ${{ matrix.file }} .
40+
env:
41+
CGO_ENABLED: ${{ matrix.cgo }}

.github/workflows/release.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
12+
jobs:
13+
release:
14+
name: Release
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
steps:
20+
- name: Set up Go
21+
uses: actions/setup-go@v1
22+
with:
23+
go-version: 1.17
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v2
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v1
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Run GoReleaser
38+
uses: goreleaser/goreleaser-action@v2
39+
with:
40+
version: latest
41+
args: release --rm-dist
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
goarch:
13+
- amd64
14+
- 386
15+
- arm
16+
- arm64
17+
- ppc64le
18+
- s390x
19+
goarm:
20+
- 6
21+
- 7
22+
23+
archives:
24+
- replacements:
25+
darwin: Darwin
26+
linux: Linux
27+
windows: Windows
28+
386: i386
29+
amd64: x86_64
30+
allow_different_binary_count: true
31+
32+
checksum:
33+
name_template: 'checksums.txt'
34+
35+
snapshot:
36+
name_template: "{{ .Tag }}-next"
37+
38+
changelog:
39+
sort: asc
40+
filters:
41+
exclude:
42+
- '^docs:'
43+
- '^test:'
44+
45+
dockers:
46+
- image_templates:
47+
- "ghcr.io/vilsol/transcoder-go:{{ .Tag }}"
48+
- "ghcr.io/vilsol/transcoder-go:v{{ .Major }}"
49+
- "ghcr.io/vilsol/transcoder-go:v{{ .Major }}.{{ .Minor }}"
50+
- "ghcr.io/vilsol/transcoder-go:latest"
51+
build_flag_templates:
52+
- "--pull"
53+
- "--label=org.opencontainers.image.created={{.Date}}"
54+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
55+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
56+
- "--label=org.opencontainers.image.version={{.Version}}"

Dockerfile

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
FROM golang:1.15-alpine AS builder
2-
3-
RUN apk add --no-cache git build-base
4-
5-
WORKDIR $GOPATH/src/github.com/Vilsol/transcoder-go/
6-
7-
ENV GO111MODULE=on
8-
9-
COPY go.mod go.mod
10-
COPY go.sum go.sum
11-
RUN go mod download
12-
13-
COPY . .
14-
15-
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /transcoder main.go
16-
17-
FROM vilsol/ffmpeg-alpine as ffmpeg
1+
FROM ghcr.io/vilsol/ffmpeg-alpine:latest as ffmpeg
182

193
FROM alpine:edge
204

@@ -37,6 +21,6 @@ RUN apk add --no-cache \
3721
numactl \
3822
nasm
3923

40-
COPY --from=builder /transcoder /transcoder
24+
COPY transcoder-go /transcoder
4125

4226
ENTRYPOINT ["/transcoder"]

cmd/root.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ var rootCmd = &cobra.Command{
9090
}
9191

9292
log.Infof("Transcoding: %s", fileName)
93-
metadata := transcoder.ReadFileMetadata(fileName)
93+
metadata, err := transcoder.ReadFileMetadata(fileName)
94+
95+
if err != nil {
96+
log.Infof("failed reading metadata: %s", err)
97+
continue
98+
}
9499

95100
tempFileName := fileName + ".transcode-temp"
96101

97-
_, err := os.Stat(tempFileName)
102+
_, err = os.Stat(tempFileName)
98103

99104
if err != nil && !os.IsNotExist(err) {
100105
log.Errorf("Error reading file %s: %s", tempFileName, err)
@@ -165,7 +170,12 @@ var rootCmd = &cobra.Command{
165170
continue
166171
}
167172

168-
resultMetadata := transcoder.ReadFileMetadata(tempFileName)
173+
resultMetadata, err := transcoder.ReadFileMetadata(tempFileName)
174+
if err != nil {
175+
log.Infof("failed reading metadata: %s", err)
176+
notifications.NotifyEnd(nil, lastReport, models.ResultError)
177+
continue
178+
}
169179

170180
if viper.GetBool("keep-old") && resultMetadata.Format.SizeInt() > metadata.Format.SizeInt() {
171181
// Transcoded file is bigger than original

go.mod

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
module github.com/Vilsol/transcoder-go
22

3-
go 1.15
3+
go 1.17
44

55
require (
66
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
7+
github.com/pkg/errors v0.8.1
78
github.com/sirupsen/logrus v1.7.0
89
github.com/spf13/cobra v1.1.1
910
github.com/spf13/viper v1.7.1
1011
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
1112
)
13+
14+
require (
15+
github.com/fsnotify/fsnotify v1.4.7 // indirect
16+
github.com/hashicorp/hcl v1.0.0 // indirect
17+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
18+
github.com/magiconair/properties v1.8.1 // indirect
19+
github.com/mitchellh/mapstructure v1.1.2 // indirect
20+
github.com/pelletier/go-toml v1.2.0 // indirect
21+
github.com/spf13/afero v1.1.2 // indirect
22+
github.com/spf13/cast v1.3.0 // indirect
23+
github.com/spf13/jwalterweatherman v1.0.0 // indirect
24+
github.com/spf13/pflag v1.0.5 // indirect
25+
github.com/subosito/gotenv v1.2.0 // indirect
26+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
27+
golang.org/x/text v0.3.2 // indirect
28+
gopkg.in/ini.v1 v1.51.0 // indirect
29+
gopkg.in/yaml.v2 v2.2.8 // indirect
30+
)

go.sum

+1-8
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
105105
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
106106
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
107107
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
108-
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
109108
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
110109
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
111110
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -136,6 +135,7 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
136135
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
137136
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
138137
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
138+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
139139
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
140140
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
141141
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -155,7 +155,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
155155
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
156156
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
157157
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
158-
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
159158
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
160159
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
161160
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@@ -173,7 +172,6 @@ github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
173172
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
174173
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
175174
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
176-
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
177175
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
178176
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
179177
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
@@ -182,7 +180,6 @@ github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
182180
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
183181
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
184182
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
185-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
186183
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
187184
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
188185
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -200,7 +197,6 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/
200197
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
201198
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
202199
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
203-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
204200
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
205201
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
206202
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -250,7 +246,6 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
250246
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
251247
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
252248
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
253-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
254249
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
255250
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
256251
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -260,7 +255,6 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w
260255
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
261256
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
262257
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
263-
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
264258
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
265259
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
266260
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
@@ -316,7 +310,6 @@ gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
316310
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
317311
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
318312
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
319-
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
320313
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
321314
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
322315
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

transcoder/info.go

+39-28
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,55 @@ package transcoder
33
import (
44
"encoding/json"
55
"github.com/Vilsol/transcoder-go/models"
6+
"github.com/pkg/errors"
67
log "github.com/sirupsen/logrus"
78
"io/ioutil"
89
"os/exec"
910
"strings"
1011
)
1112

12-
func ReadFileMetadata(file string) *models.FileMetadata {
13+
func ReadFileMetadata(file string) (*models.FileMetadata, error) {
1314
params := []string{"-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", file}
1415

1516
log.Tracef("Executing ffprobe %s", strings.Join(params, " "))
1617

17-
c := exec.Command("ffprobe", params...)
18-
19-
pipe, err := c.StdoutPipe()
20-
if err != nil {
21-
log.Fatalf("Failed hooking ffprobe stdout: %s", err)
22-
}
23-
24-
err = c.Start()
25-
if err != nil {
26-
log.Fatalf("Failed running ffprobe: %s", err)
27-
}
28-
29-
stdoutData, err := ioutil.ReadAll(pipe)
30-
if err != nil {
31-
log.Fatalf("Failed reading ffprobe response: %s", err)
32-
}
33-
34-
err = c.Wait()
35-
if err != nil {
36-
log.Fatalf("ffprobe exited: %s", err)
37-
}
38-
39-
var metadata models.FileMetadata
40-
err = json.Unmarshal(stdoutData, &metadata)
41-
if err != nil {
42-
log.Fatalf("Failed parsing ffprobe output: %s", err)
18+
var outerErr error
19+
for i := 0; i < 3; i++ {
20+
c := exec.Command("ffprobe", params...)
21+
22+
pipe, err := c.StdoutPipe()
23+
if err != nil {
24+
outerErr = errors.Wrap(err, "failed hooking ffprobe stdout")
25+
continue
26+
}
27+
28+
err = c.Start()
29+
if err != nil {
30+
outerErr = errors.Wrap(err, "failed running ffprobe")
31+
continue
32+
}
33+
34+
stdoutData, err := ioutil.ReadAll(pipe)
35+
if err != nil {
36+
outerErr = errors.Wrap(err, "failed reading ffprobe response")
37+
continue
38+
}
39+
40+
err = c.Wait()
41+
if err != nil {
42+
outerErr = errors.Wrap(err, "ffprobe exited")
43+
continue
44+
}
45+
46+
var metadata models.FileMetadata
47+
err = json.Unmarshal(stdoutData, &metadata)
48+
if err != nil {
49+
outerErr = errors.Wrap(err, "failed parsing ffprobe output")
50+
continue
51+
}
52+
53+
return &metadata, nil
4354
}
4455

45-
return &metadata
56+
return nil, outerErr
4657
}

0 commit comments

Comments
 (0)