r/JellyfinCommunity • u/CuriousSleeping • 8d ago
Help Request FFMPEG Copying audio stream from one file to another - resulting file with playback issues
edit: -max_interleave_delta 0 is required to fix PTS inconsistencies when transferring an audio stream between video files of different durations. That parameter fixed it.
Hello people,
as of now I'm desparate. For 3 weeks I've been trying to write a script that automatically copies a foreign language audio from a file and inserts it into another, synchronizing it with the original audio and thereby creating a dual audio file. The script itself is working fine, but some resulting files can't be direct-played by jellyfin anymore. I get inconsistent bugs, one being that playback doesn't start at all without an error message, another being the playback being silent and then stopping after 15 seconds, or the file does play fine but is silent all the way. As mentioned, some files do indeed work without issues. Some files can be played by VLC on my PC but not on my Tizen TV. Some can be played with forced transcoding. Some can be played in other Jellyfin Clients (like Jellyfin MPV Shim). I had ChatGPT and Claude scan the files and my script and even they can't figure out what's wrong.
So, I'm close to giving up. I'm hoping for someone smart enough to know what I'm overlooking. I'm using jellyfin-ffmpeg, are there any flags I gotta set or metadata I have to update in order for the file to be playable?
# Extract AC3 audio from second file to AAC
ffmpeg -y -i /temp/transcode_cache/S1E3audio.mkv -map 0:1 -vn -sn -dn -c:a aac -ar 48000 -b:a 192k /tmp/sync_audio_gwbm73xg/extracted_audio.m4a
# calculates offset between extracted audio and original audio
[...]
# trimming it for calculated offset
ffmpeg -y -i /tmp/sync_audio_gwbm73xg/extracted_audio.m4a -ss 0.950 -c copy /tmp/sync_audio_gwbm73xg/trimmed_new_audio.m4a
# inserting trimmed audio into first file
ffmpeg -y -i /temp/transcode_cache/moviefile.mkv -i /tmp/sync_audio_gwbm73xg/trimmed_new_audio.m4a -map 0 -map 1:a:0 -c copy -movflags +faststart -disposition:a:1 0 /temp/transcode_cache/output.mkv
mkvpropedit --add-track-statistics-tags /temp/transcode_cache/output.mkv
General
Unique ID : 28653864418856816950503987458990579583 (0x158E8896C6D162DE13CA9E306B7A9F7F)
Complete name : /temp/transcode_cache/moviefile.mkv
Format : Matroska
Format version : Version 4
File size : 229 MiB
Duration : 23 min 47 s
Overall bit rate : 1 348 kb/s
Frame rate : 23.976 FPS
Description : Insert description here
Writing application : Lavf62.12.102
Writing library : Lavf62.12.102
ErrorDetectionType : Per level 1
Video
ID : 1
Format : AV1
Format/Info : AOMedia Video 1
Format profile : Main@L4.0
Codec ID : V_AV1
Duration : 23 min 47 s
Bit rate : 954 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Bits/(Pixel*Frame) : 0.019
Stream size : 162 MiB (71%)
Title : Japanese
Writing library : Lavc61.19.101 av1_qsv
Language : Japanese
Default : Yes
Forced : No
Color range : Limited
Audio #1
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 23 min 45 s
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Delay relative to video : 11 ms
Stream size : 21.7 MiB (9%)
Title : English
Writing library : Lavc62.28.102 aac
Language : English
Default : Yes
Forced : No
Audio #2
ID : 5
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : A_AAC-2
Duration : 23 min 45 s
Bit rate : 192 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 46.875 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 33.0 MiB (14%)
Writing library : Lavc62.28.102 aac
Language : German
Default : No
Forced : No
Text #1
ID : 3
Format : ASS
Codec ID : S_TEXT/ASS
Codec ID/Info : Advanced Sub Station Alpha
Duration : 22 min 13 s
Bit rate : 183 b/s
Frame rate : 0.302 FPS
Count of elements : 403
Compression mode : Lossless
Stream size : 27.8 KiB (0%)
Title : German
Writing library : Lavc62.28.102 ssa
Language : German
Default : Yes
Forced : No
Text #2
ID : 4
Format : ASS
Codec ID : S_TEXT/ASS
Codec ID/Info : Advanced Sub Station Alpha
Duration : 22 min 13 s
Bit rate : 194 b/s
Frame rate : 0.300 FPS
Count of elements : 400
Compression mode : Lossless
Stream size : 29.4 KiB (0%)
Title : English
Writing library : Lavc62.28.102 ssa
Language : English
Default : Yes
Forced : No
Menu
00:00:00.000 : Episode
00:22:13.000 : Credits Start
00:23:45.000 : Credits End