[FFmpeg-trac] #5718(avcodec:open): ffmpeg not remapping channels for libopus automatically
FFmpeg
trac at avcodec.org
Fri Jun 11 00:01:13 EEST 2021
#5718: ffmpeg not remapping channels for libopus automatically
-------------------------------------+-------------------------------------
Reporter: agressiv | Owner: (none)
Type: defect | Status: open
Priority: important | Component: avcodec
Version: git-master | Resolution:
Keywords: libopus | Blocked By:
regression |
Blocking: | Reproduced by developer: 1
Analyzed by developer: 0 |
-------------------------------------+-------------------------------------
Comment (by everlanes):
So I hacked together a quite complicated script to circumvent this issue
(hopefully), but I am not very proud of it and I think it's strange I have
to do it:
{{{
FILE="NameOfFileToConvert.mkv"
read -r -d "" PYTHONCODE << EOD
import sys, json
data = json.load(sys.stdin)
replace = {
"5.0(side)": "5.0",
"5.1(side)": "5.1",
# you can add more mappings here
}
filter_string = "[:%d]channelmap=channel_layout='%s'"
copy_string = "[:%d]anull"
maps = [filter_string % (stream["index"],
replace[stream["channel_layout"]])
if stream.get("channel_layout") in replace.keys() else
copy_string % (stream["index"])
for stream in data["streams"]
if stream["codec_type"] == "audio"]
print(";".join(maps))
EOD
ffmpeg -i "$FILE" -map 0 \
-c:v copy \
-c:a libopus -filter_complex \
`ffprobe -hide_banner -show_streams -print_format json "$FILE" | \
python3 -c "$PYTHONCODE"` \
-c:s copy \
"$OUT_FILE"
}}}
So basically I get all streams of the original file and pipe it into a
python script that creates the filter string that remaps all problematic
streams. This string is then printed and used as an argument for the
ffmpeg call...
Does it work? Hopefully. Is it nice? Definitely not! There should be some
kind of an (optionally) fallback mechanism in ffmpeg and/or libopus for
unsupported channel layouts.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/5718#comment:21>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list