Skip to content

Commit 65e8127

Browse files
committed
Fix VAAPI profile and audio stream mapping
1 parent 990bee6 commit 65e8127

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

internal/transcode/ffmpeg_args_test.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,28 @@ func TestBuildFFmpegArgsUsesVAAPIEncodeFallbackPipeline(t *testing.T) {
206206
}
207207
}
208208

209+
func TestBuildFFmpegArgsDoesNotForceVAAPIH264Profile(t *testing.T) {
210+
session := &Session{
211+
ID: "item123",
212+
Dir: t.TempDir(),
213+
}
214+
request := Request{InputURL: "http://upstream/stream"}
215+
216+
for _, pipeline := range []string{"vaapi-full", "vaapi-encode"} {
217+
t.Run(pipeline, func(t *testing.T) {
218+
args := buildFFmpegArgs(session, request, FFmpegOptions{
219+
HardwareDecode: "vaapi",
220+
HardwareDevice: "/dev/dri/renderD128",
221+
HardwarePipeline: pipeline,
222+
})
223+
224+
if slices.Contains(args, "-profile:v") {
225+
t.Fatalf("VAAPI pipeline should not force H.264 profile: %v", args)
226+
}
227+
})
228+
}
229+
}
230+
209231
func TestBuildFFmpegArgsCapsVideoOutputTo1080p(t *testing.T) {
210232
session := &Session{
211233
ID: "item123",
@@ -227,7 +249,7 @@ func TestBuildFFmpegArgsCapsVideoOutputTo1080p(t *testing.T) {
227249
}
228250
}
229251

230-
func TestBuildFFmpegArgsMapsFirstAudioStreamReturnedByEmby(t *testing.T) {
252+
func TestBuildFFmpegArgsMapsFirstAudioStreamWhenNoAudioStreamIndexRequested(t *testing.T) {
231253
session := &Session{
232254
ID: "item123",
233255
Dir: t.TempDir(),
@@ -238,6 +260,30 @@ func TestBuildFFmpegArgsMapsFirstAudioStreamReturnedByEmby(t *testing.T) {
238260
},
239261
},
240262
}
263+
request := Request{InputURL: "http://upstream/stream"}
264+
265+
args := buildFFmpegArgs(session, request)
266+
267+
mapIndexes := allIndexes(args, "-map")
268+
if len(mapIndexes) < 2 {
269+
t.Fatalf("missing map args: %v", args)
270+
}
271+
if got := args[mapIndexes[1]+1]; got != "0:a:0?" {
272+
t.Fatalf("audio map = %q, args=%v", got, args)
273+
}
274+
}
275+
276+
func TestBuildFFmpegArgsMapsRequestedAudioStreamIndex(t *testing.T) {
277+
session := &Session{
278+
ID: "item123",
279+
Dir: t.TempDir(),
280+
Media: MediaInfo{
281+
AudioStreams: []AudioStreamInfo{
282+
{Index: 1, Ordinal: 0, Codec: "aac"},
283+
{Index: 2, Ordinal: 1, Codec: "eac3"},
284+
},
285+
},
286+
}
241287
request := Request{
242288
InputURL: "http://upstream/stream?AudioStreamIndex=2",
243289
AudioStreamIndex: 2,
@@ -249,7 +295,7 @@ func TestBuildFFmpegArgsMapsFirstAudioStreamReturnedByEmby(t *testing.T) {
249295
if len(mapIndexes) < 2 {
250296
t.Fatalf("missing map args: %v", args)
251297
}
252-
if got := args[mapIndexes[1]+1]; got != "0:a:0?" {
298+
if got := args[mapIndexes[1]+1]; got != "0:a:1?" {
253299
t.Fatalf("audio map = %q, args=%v", got, args)
254300
}
255301
}

internal/transcode/manager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,6 @@ func appendVideoTranscodeArgs(args []string, options FFmpegOptions) []string {
12491249
case "vaapi-full":
12501250
return append(args,
12511251
"-c:v", "h264_vaapi",
1252-
"-profile:v", "high",
12531252
"-g", strconv.Itoa(lowLatencyGOP),
12541253
"-keyint_min", strconv.Itoa(lowLatencyGOP),
12551254
"-bf", "0",
@@ -1259,7 +1258,6 @@ func appendVideoTranscodeArgs(args []string, options FFmpegOptions) []string {
12591258
return append(args,
12601259
"-vf", softwareScaleFilter(maxTranscodeWidth, maxTranscodeHeight)+",format=nv12,hwupload",
12611260
"-c:v", "h264_vaapi",
1262-
"-profile:v", "high",
12631261
"-level", "4.1",
12641262
"-g", strconv.Itoa(lowLatencyGOP),
12651263
"-keyint_min", strconv.Itoa(lowLatencyGOP),
@@ -1291,6 +1289,13 @@ func softwareScaleFilter(width, height int) string {
12911289
}
12921290

12931291
func audioMapArg(session *Session, request Request) string {
1292+
if request.AudioStreamIndex != 0 && session != nil {
1293+
for _, audio := range session.Media.AudioStreams {
1294+
if audio.Index == request.AudioStreamIndex {
1295+
return fmt.Sprintf("0:a:%d?", audio.Ordinal)
1296+
}
1297+
}
1298+
}
12941299
return "0:a:0?"
12951300
}
12961301

0 commit comments

Comments
 (0)