In short, I have 1 video.mkv and 1 subtitle.ass. Using ffmpeg, I am adding subtitles to the video without removing the previous subtitles that came with the video. The problem is that some videos' output.mkv files are getting a duplicate video stream. Not all the videos I tested have this issue. I have added the log of one of those for reference.
Here is my code:
ffmpeg -i input_video.mkv -i subtitle_path.ass -c:v copy -c:a copy -c:s copy -map 0:v:0
-map 0:m:language:jpn -map 0:s -map 1 -metadata:s:s:3 language=ara -max_interleave_delta 0 -y output_path.mkv
\TEST> ffmpeg -i input_video.mkv -i subtitle_path.ass -c:v copy -c:a copy -c:s copy -map 0:v:0 -map 0:m:language:jpn -map 0:s -map 1 -metadata:s:s:3 language=ara -max_interleave_delta 0 -y output_path.mkv
ffmpeg version 2023-12-28-git-c1340f3439-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 58. 36.100 / 58. 36.100
libavcodec 60. 36.100 / 60. 36.100
libavformat 60. 20.100 / 60. 20.100
libavdevice 60. 4.100 / 60. 4.100
libavfilter 9. 14.102 / 9. 14.102
libswscale 7. 6.100 / 7. 6.100
libswresample 4. 13.100 / 4. 13.100
libpostproc 57. 4.100 / 57. 4.100
Input #0, matroska,webm, from 'input_video.mkv':
Metadata:
encoder : libebml v1.3.5 + libmatroska v1.4.8
creation_time : 2018-04-21T21:21:39.000000Z
Duration: 00:24:26.56, start: 0.000000, bitrate: 2453 kb/s
Stream #0:0(jpn): Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn (default)
Metadata:
BPS-eng : 2291326
DURATION-eng : 00:24:26.465000000
NUMBER_OF_FRAMES-eng: 35160
NUMBER_OF_BYTES-eng: 420018724
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
Metadata:
BPS-eng : 159375
DURATION-eng : 00:24:26.560000000
NUMBER_OF_FRAMES-eng: 68745
NUMBER_OF_BYTES-eng: 29216626
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2(eng): Subtitle: ass (default)
Metadata:
BPS-eng : 99
DURATION-eng : 00:21:35.870000000
NUMBER_OF_FRAMES-eng: 302
NUMBER_OF_BYTES-eng: 16109
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:3(spa): Subtitle: ass
Metadata:
BPS-eng : 92
DURATION-eng : 00:20:05.580000000
NUMBER_OF_FRAMES-eng: 254
NUMBER_OF_BYTES-eng: 13877
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:4(por): Subtitle: ass
Metadata:
BPS-eng : 91
DURATION-eng : 00:20:05.580000000
NUMBER_OF_FRAMES-eng: 254
NUMBER_OF_BYTES-eng: 13846
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Input #1, ass, from 'subtitle_path.ass':
Duration: N/A, bitrate: N/A
Stream #1:0: Subtitle: ass
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:0 -> #0:1 (copy)
Stream #0:1 -> #0:2 (copy)
Stream #0:2 -> #0:3 (copy)
Stream #0:3 -> #0:4 (copy)
Stream #0:4 -> #0:5 (copy)
Stream #1:0 -> #0:6 (copy)
Output #0, matroska, to 'output_path.mkv':
Metadata:
encoder : Lavf60.20.100
Stream #0:0(jpn): Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn (default)
Metadata:
BPS-eng : 2291326
DURATION-eng : 00:24:26.465000000
NUMBER_OF_FRAMES-eng: 35160
NUMBER_OF_BYTES-eng: 420018724
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:1(jpn): Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn (default)
Metadata:
BPS-eng : 2291326
DURATION-eng : 00:24:26.465000000
NUMBER_OF_FRAMES-eng: 35160
NUMBER_OF_BYTES-eng: 420018724
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:2(jpn): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp (default)
Metadata:
BPS-eng : 159375
DURATION-eng : 00:24:26.560000000
NUMBER_OF_FRAMES-eng: 68745
NUMBER_OF_BYTES-eng: 29216626
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:3(eng): Subtitle: ass (default)
Metadata:
BPS-eng : 99
DURATION-eng : 00:21:35.870000000
NUMBER_OF_FRAMES-eng: 302
NUMBER_OF_BYTES-eng: 16109
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:4(spa): Subtitle: ass
Metadata:
BPS-eng : 92
DURATION-eng : 00:20:05.580000000
NUMBER_OF_FRAMES-eng: 254
NUMBER_OF_BYTES-eng: 13877
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:5(por): Subtitle: ass
Metadata:
BPS-eng : 91
DURATION-eng : 00:20:05.580000000
NUMBER_OF_FRAMES-eng: 254
NUMBER_OF_BYTES-eng: 13846
_STATISTICS_WRITING_APP-eng: mkvmerge v22.0.0 ('At The End Of The World') 32-bit
_STATISTICS_WRITING_DATE_UTC-eng: 2018-04-21 21:21:39
_STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream #0:6(ara): Subtitle: ass
Press [q] to stop, [?] for help
[out#0/matroska @ 000002995bf18bc0] video:820349kB audio:28532kB subtitle:65kB other streams:0kB global headers:5kB muxing overhead: 0.122471%
size= 849986kB time=00:23:40.86 bitrate=4900.6kbits/s speed= 326x
I am very Clueless as the command is working on some videos
Your fixed command is something like this:
ffmpeg -i input_video.mkv -i subtitle_path.ass -c:v copy -c:a copy -c:s copy -map 0:v:0 -map 0:a -map 0:s -map 1 -metadata:s:s:3 language=ara -max_interleave_delta 0 -y output_path.mkv
This command:
-map 0:v:0
).-map 0:a
).-map 0:s
).-map 1
).Also, in order to copy just the jp (Japanese) audio from the input_file.mkv
, you can use this command:
ffmpeg -i input_video.mkv -i subtitle_path.ass -c:v copy -c:a copy -c:s copy -map 0:v:0 -map 0:a:m:language:jpn -map 0:s -map 1 -metadata:s:s:3 language=ara -max_interleave_delta 0 -y output_path.mkv