Skip to content

Commit f60a360

Browse files
committed
fix ffmpeg output flags
1 parent 2a8b3f1 commit f60a360

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

encode.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,16 @@ func (e *Encoder) getVideoHandle(ctx context.Context, input, output, title strin
382382
"-v", "16", // log level
383383
"-rtsp_transport", "tcp",
384384
"-i", input,
385-
"-f", "mov",
386385
"-metadata", "title=" + title,
387386
"-y", "-map", "0",
388387
}
389388

389+
if output == "-" {
390+
arg = append(arg, "-f", "mp4", "-movflags", "frag_keyframe+empty_moov")
391+
} else {
392+
arg = append(arg, "-f", "mov")
393+
}
394+
390395
if e.config.Size > 0 {
391396
arg = append(arg, "-fs", strconv.FormatInt(e.config.Size, base10))
392397
}
@@ -400,12 +405,15 @@ func (e *Encoder) getVideoHandle(ctx context.Context, input, output, title strin
400405
"-profile:v", e.config.Prof,
401406
"-level", e.config.Level,
402407
"-pix_fmt", "yuv420p",
403-
"-movflags", "faststart",
404408
"-s", strconv.Itoa(e.config.Width)+"x"+strconv.Itoa(e.config.Height),
405409
"-preset", "superfast",
406410
"-crf", strconv.Itoa(e.config.CRF),
407411
"-r", strconv.Itoa(e.config.Rate),
408412
)
413+
414+
if output != "-" {
415+
arg = append(arg, "-movflags", "faststart")
416+
}
409417
} else {
410418
arg = append(arg, "-c", "copy")
411419
}

encode_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func TestSaveVideo(t *testing.T) {
5959
asert.Contains(cmd, "-metadata title=TITLE", "TITLE value appears to be missing.")
6060
asert.Contains(cmd, fmt.Sprintf("-vcodec libx264 -profile:v %v -level %v", DefaultProfile, DefaultLevel),
6161
"Level or Profile are missing or out of order.")
62+
asert.Contains(cmd, "-f mov", "File output should use mov container.")
63+
asert.Contains(cmd, "-movflags faststart", "File output should set faststart for mov.")
6264
asert.Contains(cmd, fmt.Sprintf("-crf %d", DefaultEncodeCRF), "CRF value is missing or malformed.")
6365
asert.Contains(cmd, fmt.Sprintf("-t %d", DefaultCaptureTime),
6466
"Capture Time value is missing or malformed.")
@@ -119,6 +121,9 @@ func TestGetVideoStreamLifecycle(t *testing.T) {
119121
require.NoError(t, readErr)
120122
require.NotEmpty(t, data)
121123
require.Contains(t, string(data), "-metadata title=TITLE")
124+
require.Contains(t, string(data), "-f mp4")
125+
require.Contains(t, string(data), "-movflags frag_keyframe+empty_moov")
126+
require.NotContains(t, string(data), "-movflags faststart")
122127
require.NoError(t, stream.Close())
123128
require.Contains(t, cmd, "-metadata title=TITLE")
124129
}

0 commit comments

Comments
 (0)