Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mxf file: play 8 mono tracks as 4 stereo tracks #14070

Closed
SimpelMe opened this issue May 5, 2024 · 4 comments
Closed

mxf file: play 8 mono tracks as 4 stereo tracks #14070

SimpelMe opened this issue May 5, 2024 · 4 comments

Comments

@SimpelMe
Copy link

SimpelMe commented May 5, 2024

I do have mxf files with 8 mono tracks inside. We always use them as stereo. So when I want to control my exported files I want to check them in stereo.

Tried a lot. At least I could play the first 2 mono files together as mono:

--lavfi-complex="[aid1][aid2]amix=inputs=2[ao]"

But that's not what we need.

Technical Information

  • mpv version
mpv 0.37.0 Copyright © 2000-2023 mpv/MPlayer/mplayer2 projects
 built on Nov 22 2023 01:45:29
libplacebo version: v6.338.2
FFmpeg version: 6.1.1
FFmpeg library versions:
   libavutil       58.2.100 (runtime 58.29.100)
   libavcodec      60.3.100 (runtime 60.31.102)
   libavformat     60.3.100 (runtime 60.16.100)
   libswscale      7.1.100 (runtime 7.5.100)
   libavfilter     9.3.100 (runtime 9.12.100)
   libswresample   4.10.100 (runtime 4.12.100)
  • Platform and Version
22.6.0 Darwin Kernel Version 22.6.0: Mon Feb 19 19:45:09 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_ARM64_T6000 arm64
  • Source of the mpv binary: home brew

Expected behavior

Show 4 audio tracks at on screen display and cycle them with #. All 4 tracks are stereo made from the 8 mono tracks.

Actual behavior

Has 8 mono audio tracks.

@kasper93
Copy link
Contributor

kasper93 commented May 6, 2024

You could use amerge [1] to merge tracks into one and pan [2] to select which channels to map to output.
[1] https://ffmpeg.org/ffmpeg-filters.html#amerge-1
[2] https://ffmpeg.org/ffmpeg-filters.html#pan-1

(not tested, not sure it would work in mpv)

@SimpelMe
Copy link
Author

This syntax is at least executed but does not lead to the desired result:

--lavfi-complex="[aid1] [aid2] amerge [a1];[aid3] [aid4] amerge [a2];[aid5] [aid6] amerge [a3];[aid7] [aid8] amerge [a4];[a1] pan=stereo [ao1];[a2] pan=stereo [ao2];[a3] pan=stereo [ao3];[a4] pan=stereo [ao4]; [ao1] [ao2] [ao3] [ao4] amerge=inputs=4"

But it shows some warnings I don't understand:

[ffmpeg] Parsed_amerge_0: No channel layout for input 1
[ffmpeg] Parsed_amerge_1: No channel layout for input 1
[ffmpeg] Parsed_amerge_2: No channel layout for input 1
[ffmpeg] Parsed_amerge_3: No channel layout for input 1
[ffmpeg] Parsed_amerge_8: Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[ffmpeg] Parsed_amerge_0: Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[ffmpeg] Parsed_amerge_1: Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[ffmpeg] Parsed_amerge_2: Input channel layouts overlap: output layout will be determined by the number of distinct input channels
[ffmpeg] Parsed_amerge_3: Input channel layouts overlap: output layout will be determined by the number of distinct input channels

mpv shows audio tracks in gui _/8.

@SimpelMe
Copy link
Author

One running ffmpeg line is:

ffmpeg -i input.mxf -filter_complex '[a:0][a:1] amerge [st1]; [a:2][a:3] amerge [st2]; [a:4][a:5] amerge [st3]; [a:6][a:7] amerge [st4]' -map v:0 -map '[st1]' -map '[st2]' -map '[st3]' -map '[st4]' output.mxf

Any chance to get this translated into mpv syntax?

@SimpelMe
Copy link
Author

At the end I did it this way.

mpv \
    videofile.mxf \
    --scripts=tracks.lua \
    --lavfi-complex="[aid1] [aid2] amerge [ao]"

tracks.lua is:

options = require 'mp.options'

-- define keys
local opts = {
  -- audio
  a_zero = '0',
  a_one = '1',
  a_two = '2',
  a_three  = '3',
  a_four = '4'
}

options.read_options(opts)

-- info
CLEAR_OSD_TIMEOUT = .01 -- Hack for clearing OSD message upon OSC toggle
osc_always_on = true

function toggle_osc_auto_always()
  osc_always_on = not osc_always_on
  mp.commandv('script-message', 'osc-visibility',
    osc_always_on and 'always' or 'auto'
  )
  mp.add_timeout(CLEAR_OSD_TIMEOUT, function ()
    mp.osd_message('')
  end)
end

-- audio
function select_audio_0()
  mp.set_property("lavfi-complex", "")
  local track = mp.get_property_number("aid")
  if not track then
    track = 0
  end
  track = track + 1
  if track > 8 then
    track = 1
  end
  mp.set_property_number("aid", track)
  mp.set_property("audio-channels", "mono")
  if track == 1 then mp.command('show-text "Track 1"') end
  if track == 2 then mp.command('show-text "Track 2"') end
  if track == 3 then mp.command('show-text "Track 3"') end
  if track == 4 then mp.command('show-text "Track 4"') end
  if track == 5 then mp.command('show-text "Track 5"') end
  if track == 6 then mp.command('show-text "Track 6"') end
  if track == 7 then mp.command('show-text "Track 7"') end
  if track == 8 then mp.command('show-text "Track 8"') end
end

function select_audio_1()
  mp.command('show-text "Tracks 1 + 2"')
  mp.set_property("lavfi-complex", ("[aid1] [aid2] amerge [ao]"):format(1, 2))
  mp.set_property("audio-channels", "stereo")
end

function select_audio_2()
  mp.command('show-text "Tracks 3 + 4"')
  mp.set_property("lavfi-complex", ("[aid3] [aid4] amerge [ao]"):format(1, 2))
  mp.set_property("audio-channels", "stereo")
end

function select_audio_3()
  mp.command('show-text "Tracks 5 + 6"')
  mp.set_property("lavfi-complex", ("[aid5] [aid6] amerge [ao]"):format(1, 2))
  mp.set_property("audio-channels", "stereo")
end

function select_audio_4()
  mp.command('show-text "Tracks 7 + 8"')
  mp.set_property("lavfi-complex", ("[aid7] [aid8] amerge [ao]"):format(1, 2))
  mp.set_property("audio-channels", "stereo")
end

-- info
mp.add_key_binding(nil, 'toggle-osc-auto-always', toggle_osc_auto_always)
-- audio
mp.add_forced_key_binding(opts.a_zero, "Select_Audio_0", select_audio_0)
mp.add_forced_key_binding(opts.a_one, "Select_Audio_1", select_audio_1)
mp.add_forced_key_binding(opts.a_two, "Select_Audio_2", select_audio_2)
mp.add_forced_key_binding(opts.a_three, "Select_Audio_3", select_audio_3)
mp.add_forced_key_binding(opts.a_four, "Select_Audio_4", select_audio_4)

@mpv-player mpv-player locked and limited conversation to collaborators May 19, 2024
@kasper93 kasper93 converted this issue into discussion #14181 May 19, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants