Skip to content

Commit 12704f7

Browse files
authored
Only print ffmpeg output on errors (#1190)
1 parent 4597484 commit 12704f7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

video/segment.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package video
22

33
import (
4+
"bytes"
45
"fmt"
56
"strings"
67

@@ -14,6 +15,7 @@ import (
1415
// Because of this, we download first and then clean up at the end.
1516
func Segment(sourceFilename string, outputManifestURL string, targetSegmentSize int64) error {
1617
// Do the segmenting, using the local file as source
18+
ffmpegErr := bytes.Buffer{}
1719
err := ffmpeg.Input(sourceFilename).
1820
Output(
1921
strings.Replace(outputManifestURL, ".m3u8", "", 1)+"%d.ts",
@@ -27,9 +29,9 @@ func Segment(sourceFilename string, outputManifestURL string, targetSegmentSize
2729
"segment_time": targetSegmentSize,
2830
"min_seg_duration": "2",
2931
},
30-
).OverWriteOutput().ErrorToStdOut().Run()
32+
).OverWriteOutput().WithErrorOutput(&ffmpegErr).Run()
3133
if err != nil {
32-
return fmt.Errorf("failed to segment source file (%s): %s", sourceFilename, err)
34+
return fmt.Errorf("failed to segment source file (%s) [%s]: %s", sourceFilename, ffmpegErr.String(), err)
3335
}
3436
return nil
3537
}

video/transmux.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ const (
2323
func MuxTStoMP4(tsInputFile, mp4OutputFile string) ([]string, error) {
2424
var transmuxOutputFiles []string
2525
// transmux the .ts file into a standalone MP4 file
26+
ffmpegErr := bytes.Buffer{}
2627
err := ffmpeg.Input(tsInputFile).
2728
Output(mp4OutputFile, ffmpeg.KwArgs{
2829
"analyzeduration": "15M", // Analyze up to 15s of video to figure out the format. We saw failures to detect the video codec without this
2930
"movflags": "faststart", // Need this for progressive playback and probing
3031
"c": "copy", // Don't accidentally transcode
3132
"bsf:a": "aac_adtstoasc", // Remove ADTS header (required for ts -> mp4 container conversion)
3233
}).
33-
OverWriteOutput().ErrorToStdOut().Run()
34+
OverWriteOutput().WithErrorOutput(&ffmpegErr).Run()
3435
if err != nil {
35-
return nil, fmt.Errorf("failed to transmux concatenated mpeg-ts file (%s) into a mp4 file: %w", tsInputFile, err)
36+
return nil, fmt.Errorf("failed to transmux concatenated mpeg-ts file (%s) into a mp4 file [%s]: %w", tsInputFile, ffmpegErr.String(), err)
3637
}
3738
// Verify the mp4 output file was created
3839
_, err = os.Stat(mp4OutputFile)
@@ -211,15 +212,16 @@ func concatStreams(segmentList, outputTsFileName string) error {
211212
}
212213
defer tsFile.Close()
213214
// Transmux the individual .ts files into a combined single ts file using stream based concatenation
215+
ffmpegErr := bytes.Buffer{}
214216
err = ffmpeg.Input(segmentList, ffmpeg.KwArgs{
215217
"f": "concat", // Use stream based concatenation (instead of file based concatenation)
216218
"safe": "0"}). // Must be 0 since relative paths to segments are used in segmentListTxtFileName
217219
Output(outputTsFileName, ffmpeg.KwArgs{
218220
"c": "copy", // Don't accidentally transcode
219221
}).
220-
OverWriteOutput().ErrorToStdOut().Run()
222+
OverWriteOutput().WithErrorOutput(&ffmpegErr).Run()
221223
if err != nil {
222-
return fmt.Errorf("failed to transmux multiple ts files from %s into a ts file: %w", segmentList, err)
224+
return fmt.Errorf("failed to transmux multiple ts files from %s into a ts file [%s]: %w", segmentList, ffmpegErr.String(), err)
223225
}
224226
// Verify the ts output file was created
225227
_, err = os.Stat(outputTsFileName)
@@ -237,13 +239,14 @@ func concatFiles(segmentList, outputTsFileName string) error {
237239
}
238240
defer tsFile.Close()
239241
// Transmux the individual .ts files into a combined single ts file using file based concatenation
242+
ffmpegErr := bytes.Buffer{}
240243
err = ffmpeg.Input(segmentList).
241244
Output(outputTsFileName, ffmpeg.KwArgs{
242245
"c": "copy", // Don't accidentally transcode
243246
}).
244-
OverWriteOutput().ErrorToStdOut().Run()
247+
OverWriteOutput().WithErrorOutput(&ffmpegErr).Run()
245248
if err != nil {
246-
return fmt.Errorf("failed to transmux multiple ts files from %s into a ts file: %w", segmentList, err)
249+
return fmt.Errorf("failed to transmux multiple ts files from %s into a ts file [%s]: %w", segmentList, ffmpegErr.String(), err)
247250
}
248251
// Verify the ts output file was created
249252
_, err = os.Stat(outputTsFileName)

0 commit comments

Comments
 (0)