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

Merge existing split .opus files instead of re-encoding them? #9

Open
steve8x8 opened this issue Feb 1, 2023 · 2 comments
Open

Merge existing split .opus files instead of re-encoding them? #9

steve8x8 opened this issue Feb 1, 2023 · 2 comments

Comments

@steve8x8
Copy link

steve8x8 commented Feb 1, 2023

May we have a --merge option (the opposite of --split which doesn't touch the stream data) that just merges existing .opus files (after checking their encoding parameters are OK, of course), to avoid extra loss?

@steve8x8
Copy link
Author

steve8x8 commented Feb 1, 2023

Currently, the results of --split from a genuine tonie file cannot even be processed,

[01/24] ./01_500304E0.opus
Traceback (most recent call last):
  File ".../opus2tonie.py", line 1058, in <module>
    create_tonie_file(out_filename, files, args.no_tonie_header, args.user_timestamp,
  File ".../opus2tonie.py", line 675, in create_tonie_file
    copy_first_and_second_page(handle, out_file, timestamp, sha1)
  File ".../opus2tonie.py", line 524, in copy_first_and_second_page
    check_identification_header(page)
  File ".../opus2tonie.py", line 495, in check_identification_header
    assert unpacked[4] == SAMPLE_RATE_KHZ * 1000, "Sample rate needs to be 48 kHz"
AssertionError: Sample rate needs to be 48 kHz

(the files seem to be marked as 44100 Hz). Strangely enough, renaming the .opus files to .ogg allows to process them, and the resulting "tonie" file can be split, and the parts can be re-processed as they are now 48000 Hz.

mpv sees/plays all files as 48000 Hz stereo (it apparently doesn't use the rate encoded at 0x28 in the file?) - and I can't hear a pitch/speed difference?

Update: If I pass genuine tonie files through dd if=500304E0 bs=4096 skip=1 | file - I mostly get 44100 Hz, only a few tonie copies have 48000 Hz (which is supposed to be the right value?). Even a creative tonie yields 44100 (0x0000ac44 confirmed from the file/stream). opus2tonie, when given an .opus file, expects 48000 (0x0000bb80) ...

@bailli
Copy link
Owner

bailli commented Feb 11, 2023

When I started the project I was under the impression all genuine content was sampled at 48 kHz.
Therefore when you supply files with .opus extension the script assumes you supply already correctly prepared sound files but still checks that they are sampled at 48 kHz.
Also, when you supply "anything else" it will get transcoded to opus at 48 kHz.

If you really want 44.1 kHz content you could probably get away with just changing the constant at the start of the script and the three occurrences of "48000".

Right now I do not feel like adding support for 44.1 kHz sample rate properly, but feel free to do it and post a merge request.

Also to answer your original statement: When you supply 48 kHz ".opus" files the script will not transcode anything. So this basically the --merge option you are looking for - only with missing 44.1 kHz support...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants