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

Enhance FFmpeg option handling and add new flexibility #41

Merged
merged 2 commits into from
Aug 24, 2024

Conversation

mitsuki31
Copy link
Owner

Overview

This refactor introduces enhanced flexibility in the audioconv module by refining the way options are handled and applied within the convertAudio function. The changes allow users to specify minimal configurations while still leveraging the full capabilities of ffmpeg.

Changes Made

  • Enhanced resolveOptions Logic:

    • The resolveOptions function now returns defaultOptions if the input is either an empty object or a non-object. This improvement ensures a more robust handling of edge cases where invalid or empty options are passed.
    • Default value of useDefault are now set to false for compatibility with minimal FFmpeg options.
  • Selective Application of FFmpeg Audio Options:

    • The convertAudio function has been updated to apply audio options (bitrate, codec, channels, frequency) only if they are explicitly provided by the user. This enhancement allows users to convert audio files with just the necessary settings, reducing the need for redundant configurations and prevent an error thrown by ffmpeg due to undefined option has given.
    • The output format remains a mandatory option, ensuring that the conversion process is correctly executed with the specified format. Additionally, users can now specify the same format as the input file, potentially copying the input file with the same codec and format, if desired.

Benefits

  • Increased Flexibility: Users can now perform conversions with minimal configurations, specifying only the options they need.
  • Simplified Usage: The refactor reduces complexity for users by automatically handling default settings when no specific options are provided.
  • Better Error Handling: The update in resolveOptions enhances the module’s robustness, avoiding potential issues from invalid inputs.

It's now possible to convert an audio file by specifying only the output format, for examples:

  • Using ytmp3 CLI:

    ytmp3 <URL> -C --format opus
  • Using convertAudio API function:

    import { convertAudio } from 'ytmp3-js';
    
    // Convert an audio file to opus format
    await convertAudio('/path/to/audio.mp3', {
      // Only specify the output format
      format: 'opus'
    });
    // Or you can use 'outputOptions' instead
    await convertAudio('/path/to/audio.mp3', {
      outputOptions: '-f opus'
    });

- Updated `resolveOptions` to return `defaultOptions` when the input is an empty object or not an object.
- Set the default value of `useDefault` parameter in `resolveOptions` to false.
- Refined `convertAudio` function to apply `ffmpeg` audio options only when specified, allowing for more flexible conversion with minimal configurations.
@mitsuki31 mitsuki31 added refactor Refactor and enhancement changes feature Bring new features minor Minor changes labels Aug 24, 2024
@mitsuki31 mitsuki31 self-assigned this Aug 24, 2024
Copy link

codecov bot commented Aug 24, 2024

Codecov Report

Attention: Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 41.78%. Comparing base (c2bc654) to head (d796eb2).
Report is 3 commits behind head on master.

Files Patch % Lines
lib/audioconv.js 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
- Coverage   42.05%   41.78%   -0.27%     
==========================================
  Files           7        7              
  Lines         409      414       +5     
==========================================
+ Hits          172      173       +1     
- Misses        237      241       +4     
Flag Coverage Δ
Ubuntu 41.78% <16.66%> (-0.27%) ⬇️
Windows 41.78% <16.66%> (-0.27%) ⬇️
macOS 41.78% <16.66%> (-0.27%) ⬇️
unittests 41.78% <16.66%> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mitsuki31 mitsuki31 merged commit 8b08c73 into master Aug 24, 2024
18 of 20 checks passed
@mitsuki31 mitsuki31 deleted the refactor/audioconv-option-handling-and-ffmpeg-setup branch August 24, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Bring new features minor Minor changes refactor Refactor and enhancement changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant