Skip to content
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

--split-chapters with --add-metadata enabled produces incorrect metadata for m4a files #8363

Open
10 of 11 tasks
danilovsergei opened this issue Oct 17, 2023 · 5 comments · May be fixed by #8364
Open
10 of 11 tasks

--split-chapters with --add-metadata enabled produces incorrect metadata for m4a files #8363

danilovsergei opened this issue Oct 17, 2023 · 5 comments · May be fixed by #8364
Labels
bug Bug that is not site-specific external issue Issue with an external tool triage Untriaged issue

Comments

@danilovsergei
Copy link

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

  • I understand that I will be blocked if I intentionally remove or skip any mandatory* field

Checklist

Region

USA

Provide a description that is worded well enough to be understood

Run command

yt-dlp -f bestaudio[ext=m4a] --extract-audio  --add-metadata --split-chapters https://www.youtube.com/watch?v=UoY2jh-lHMU

It produces 3 files

[SplitChapters] Chapter 001; Destination: ADMO - 77 (Full EP) - 001 1. Chamomile Tea [UoY2jh-lHMU].m4a
[SplitChapters] Chapter 002; Destination: ADMO - 77 (Full EP) - 002 2. 77 [UoY2jh-lHMU].m4a
[SplitChapters] Chapter 003; Destination: ADMO - 77 (Full EP) - 003 3. Aftershock [UoY2jh-lHMU].m4a

the problem is ffmpeg appends all chapters to all split files. For example:

ffmpeg -i "ADMO - 77 (Full EP) - 003 3. Aftershock [UoY2jh-lHMU].m4a"
...
Chapters:
    Chapter #0:0: start 0.000000, end 0.000000
      Metadata:
        title           : 2. 77
    Chapter #0:1: start 0.000000, end 141.000000
      Metadata:
        title           : 3. Aftershock

Then add first file 'ADMO - 77 (Full EP) - 001 1. Chamomile Tea [UoY2jh-lHMU].m4a' to Deadbeef or haruna
Deadbeef adds it as three files .
Haruna displays 3 chapters for the single file and fails to play the 2 out of 3 because they are not exist.
Screenshot_20231610_221545

It's an ffmpeg problem since its used for splitting files and adding metadata and happens only for m4a files.
Opus works fine.

Provide verbose output that clearly demonstrates the problem

  • Run your yt-dlp command with -vU flag added (yt-dlp -vU <your command line>)
  • If using API, add 'verbose': True to YoutubeDL params instead
  • Copy the WHOLE output (starting with [debug] Command-line config) and insert it below

Complete Verbose Output

~/tmp$  yt-dlp -f bestaudio[ext=m4a] --extract-audio  --add-metadata --split-chapters --verbose https://www.youtube.com/watch?v=UoY2jh-lHMU
[debug] Command-line config: ['-f', 'bestaudio[ext=m4a]', '--extract-audio', '--add-metadata', '--split-chapters', '--verbose', 'https://www.youtube.com/watch?v=UoY2jh-lHMU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.09.24 [088add956] (zip)
[debug] Python 3.11.5 (CPython x86_64 64bit) - Linux-6.5.3-1rodete1-amd64-x86_64-with-glibc2.37 (OpenSSL 3.0.10 1 Aug 2023, glibc 2.37)
[debug] exe versions: ffmpeg 5.1.3-1 (setts), ffprobe 5.1.3-1
[debug] Optional libraries: Cryptodome-3.11.0, brotli-1.0.9, certifi-2022.09.24, pyxattr-0.8.1, secretstorage-3.3.3, sqlite3-3.42.0
[debug] Proxy map: {}
[debug] Post-Processor Plugins: SplitAndTagPP
[debug] Plugin directories: ['/home/sdanilov/.yt-dlp/plugins/SplitAndTag/yt_dlp_plugins']
[debug] Loaded 1886 extractors
[youtube] Extracting URL: https://www.youtube.com/watch?v=UoY2jh-lHMU
[youtube] UoY2jh-lHMU: Downloading webpage
[youtube] UoY2jh-lHMU: Downloading ios player API JSON
[youtube] UoY2jh-lHMU: Downloading android player API JSON
[youtube] UoY2jh-lHMU: Downloading m3u8 information
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec:vp9.2, channels, acodec, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id
[info] UoY2jh-lHMU: Downloading 1 format(s): 140
[debug] Invoking http downloader on "https://rr4---sn-o097znse.googlevideo.com/videoplayback?expire=1697541440&ei=4BguZbjSEO2VsfIPxdOr0Aw&ip=73.231.186.144&id=o-AFVVNjgy-SxknZhHwIXylb-fmDdXxksUvJYGMyw707h5&itag=140&source=youtube&requiressl=yes&mh=av&mm=31%2C29&mn=sn-o097znse%2Csn-n4v7snll&ms=au%2Crdu&mv=m&mvi=4&pl=23&initcwndbps=1698750&vprv=1&svpuc=1&mime=audio%2Fmp4&gir=yes&clen=7658144&dur=473.129&lmt=1565410361577101&mt=1697519581&fvip=2&keepalive=yes&fexp=24007246&beids=24350017&c=IOS&txp=5311222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Csvpuc%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AGM4YrMwRgIhALy7_V395NRWoFdZr_suVnllIctjhzFt-8RFjxVHVTLjAiEApZ3uA1_lKzyBPVwHgu-DxJUwqR-oFRNYcbPXRGrcx3Y%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AK1ks_kwRgIhAOCo4uShgxnXrOsgbknpcvkSKDE8rYzea7NEFE7vT-D1AiEA-KwHG91z7sAvb378unbzuqiNFtbtS4CTxBwBa9w7gwQ%3D"
[download] ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a has already been downloaded
[download] 100% of    7.30MiB
[ExtractAudio] Not converting audio ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a; the file is already in a common audio format
[Metadata] Adding metadata to "ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a' -i 'file:ADMO - 77 (Full EP) [UoY2jh-lHMU].meta' -map 0 -dn -ignore_unknown -vn -acodec copy -map_metadata 1 -write_id3v1 1 -metadata 'title=ADMO - 77 (Full EP)' -metadata date=20190808 -metadata 'description=ADMO'"'"'s brand new EP dropped today featuring a more acoustic and laid back style with more indie elements than his previous work.

► https://open.spotify.com/album/6Ow6ZKzYPjeTCR2HcqJi3v
► https://soundcloud.com/admoyo/sets/77-ep
► https://admoyo.bandcamp.com/album/77

► Polychora Merch: https://polychora.xyz/merch
► Follow my Spotify playlist: https://open.spotify.com/playlist/7yvr3Cp48xRQ5BzGTTimJh
► Discord: https://polychora.xyz/discord
► Second channel: https://youtube.com/Polychora2

Follow me:
► https://twitter.com/PolychoraYT
► https://soundcloud.com/PolychoraYT

Track List:
1. Chamomile Tea - 0:00
2. 77 - 2:57
3. Aftershock - 5:32' -metadata 'synopsis=ADMO'"'"'s brand new EP dropped today featuring a more acoustic and laid back style with more indie elements than his previous work.

► https://open.spotify.com/album/6Ow6ZKzYPjeTCR2HcqJi3v
► https://soundcloud.com/admoyo/sets/77-ep
► https://admoyo.bandcamp.com/album/77

► Polychora Merch: https://polychora.xyz/merch
► Follow my Spotify playlist: https://open.spotify.com/playlist/7yvr3Cp48xRQ5BzGTTimJh
► Discord: https://polychora.xyz/discord
► Second channel: https://youtube.com/Polychora2

Follow me:
► https://twitter.com/PolychoraYT
► https://soundcloud.com/PolychoraYT

Track List:
1. Chamomile Tea - 0:00
2. 77 - 2:57
3. Aftershock - 5:32' -metadata 'purl=https://www.youtube.com/watch?v=UoY2jh-lHMU' -metadata 'comment=https://www.youtube.com/watch?v=UoY2jh-lHMU' -metadata artist=Polychora -movflags +faststart 'file:ADMO - 77 (Full EP) [UoY2jh-lHMU].temp.m4a'
[SplitChapters] Splitting video by chapters; 3 chapters found
[SplitChapters] Chapter 001; Destination: ADMO - 77 (Full EP) - 001 1. Chamomile Tea [UoY2jh-lHMU].m4a
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -ss 0.0 -t 177.0 -i 'file:ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a' -map 0 -dn -ignore_unknown -c copy -movflags +faststart 'file:ADMO - 77 (Full EP) - 001 1. Chamomile Tea [UoY2jh-lHMU].m4a'
[SplitChapters] Chapter 002; Destination: ADMO - 77 (Full EP) - 002 2. 77 [UoY2jh-lHMU].m4a
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -ss 177.0 -t 155.0 -i 'file:ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a' -map 0 -dn -ignore_unknown -c copy -movflags +faststart 'file:ADMO - 77 (Full EP) - 002 2. 77 [UoY2jh-lHMU].m4a'
[SplitChapters] Chapter 003; Destination: ADMO - 77 (Full EP) - 003 3. Aftershock [UoY2jh-lHMU].m4a
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -ss 332.0 -t 141.0 -i 'file:ADMO - 77 (Full EP) [UoY2jh-lHMU].m4a' -map 0 -dn -ignore_unknown -c copy -movflags +faststart 'file:ADMO - 77 (Full EP) - 003 3. Aftershock [UoY2jh-lHMU].m4a'
@danilovsergei danilovsergei added site-bug Issue with a specific website triage Untriaged issue labels Oct 17, 2023
danilovsergei added a commit to danilovsergei/yt-dlp that referenced this issue Oct 17, 2023
@danilovsergei
Copy link
Author

I added a simple pull request #8364 which replaces all metadata copying from parent file to split files with directly setting title which is present in chapter

@gamer191
Copy link
Collaborator

According to https://superuser.com/questions/1674960/splitting-mp4-with-ffmpeg-does-not-remove-chapters, passing -map_metadata -1 should fix this, but your verbose log suggests that that is already passed (unless the 1 has to be proceeded by a -)

Does this bug occur on all FFmpeg versions? I'll look into submitting a bug report if this is definitely an ffmpeg bug

@gamer191 gamer191 added the external issue Issue with an external tool label Oct 17, 2023
@danilovsergei
Copy link
Author

danilovsergei commented Oct 17, 2023

Passing map_metadata -1 to ffmpeg fixes it. But as far as I understand there is no direct way to pass this parameter to the ffmpeg split chapters post processor. map_metadata argument you see in the log related to the main downloaded file , not to split files produced by ffmpeg postprocessor.

The only known to me way is to remove --add-metadata argument from yt-dlp.
That fully removes all the metadata including title , artist and other from parent file and all split files.
That is sub optimal solution since we don't want to loose useful metadata for tagging purposes

My pull request 8364 passes map_metadata -1 to split chapters post processor and sets selected metadata , eg. track title from the chapter title

I checked both on ffmpeg 5-1.3 and latest ffmpeg from git. Both have this issue

@bashonly
Copy link
Member

Is this specific only to m4a files? I'd think it would impact other formats as well

@danilovsergei
Copy link
Author

danilovsergei commented Oct 17, 2023

Same file but downloaded as opus works as intended in players.
however when I checked its information , there are also all chapters present in split files

~/tmp$ ffmpeg -i 'ADMO - 77 (Full EP) - 002 2. 77 [UoY2jh-lHMU].opus'
ffmpeg version 5.1.3-1+build1 Copyright (c) 2000-2022 the FFmpeg developers
Input #0, ogg, from 'ADMO - 77 (Full EP) - 002 2. 77 [UoY2jh-lHMU].opus':
  Duration: 00:02:35.02, start: 0.000000, bitrate: 134 kb/s
  Chapters:
    Chapter #0:0: start 0.000000, end 155.020000
      Metadata:
        title           : 1. Chamomile Tea
    Chapter #0:1: start 0.000000, end 155.000000
      Metadata:
        title           : 2. 77
    Chapter #0:2: start 155.000000, end 155.020000
      Metadata:
        title           : 3. Aftershock

Deadbeef , haruna , all ignore not relevant chapters. Probably there is some other metadata in opus instructs players there is only one actual chapter for opus.
But it's not happening for m4a

Another difference is title&artist metadata is properly filled for opus file , which is not happening for m4a
So ffmpeg does behave differently for m4a and opus
Screenshot_20231710_092141

@bashonly bashonly added bug Bug that is not site-specific and removed site-bug Issue with a specific website labels Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is not site-specific external issue Issue with an external tool triage Untriaged issue
Projects
None yet
3 participants