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

[BUG] local variable 'progress_bar' referenced before assignment #6

Closed
abreumatheus opened this issue Oct 1, 2022 · 7 comments
Closed
Assignees

Comments

@abreumatheus
Copy link

abreumatheus commented Oct 1, 2022

HI, after runnning the primary example with some minor modifications I got an exception.
I'm running version 2.0.5.

Code:

from better_ffmpeg_progress import FfmpegProcess
# Pass a list of FFmpeg arguments, like you would if using subprocess.run()
process = FfmpegProcess(["ffmpeg", "-i", "./music/arctic.flac", "-c:a", "libopus", "-b:a", "64k", "arctic.mka"])
# Use the run method to run the FFmpeg command.
process.run()

Exception:

Traceback (most recent call last):
  File "[REDACTED].py", line 5, in <module>
    process.run()
  File "[REDACTED]/.venv/lib/python3.10/site-packages/better_ffmpeg_progress/better_ffmpeg_progress.py", line 114, in run
    progress_bar.close()
UnboundLocalError: local variable 'progress_bar' referenced before assignment
@CrypticSignal CrypticSignal self-assigned this Oct 3, 2022
@CrypticSignal
Copy link
Owner

CrypticSignal commented Oct 3, 2022

Thank you for reporting this. I'll check this out after I finish work today. This should be a simple fix.
By the way, and I know this is off topic but I'm curious - is there a reason why you're using the Matroska container (.mka) for the output file instead of .opus?

@CrypticSignal
Copy link
Owner

CrypticSignal commented Oct 3, 2022

With regards to getting local variable 'progress_bar' referenced before assignment on line 114, I believe this is because better-ffmpeg-progress is unable to determine the duration of artic.flac, and the progress_bar variable is only defined if the duration of the input file can be attained.

This error can be fixed by only executing progress_bar.close() in the except Exception as e block if self._can_get_duration is True, but the bigger issue is why it's going into this exception block.

If you run ffmpeg -i "./music/artic.flac" -c:a libopus -b:a 64k artic.mka directly in the terminal, do you get an error? If so, please share it.

@abreumatheus
Copy link
Author

No errors running ffmpeg directly in the terminal:

ffmpeg version N-108453-gb0c7352cd4 Copyright (c) 2000-2022 the FFmpeg developers
  built with Apple clang version 14.0.0 (clang-1400.0.29.102)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/HEAD-b0c7352 --enable-shared --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-demuxer=dash --enable-opencl --enable-audiotoolbox --enable-videotoolbox --enable-neon --disable-htmlpages --enable-libfdk-aac --enable-nonfree
  libavutil      57. 38.100 / 57. 38.100
  libavcodec     59. 49.100 / 59. 49.100
  libavformat    59. 33.100 / 59. 33.100
  libavdevice    59.  8.101 / 59.  8.101
  libavfilter     8. 49.100 /  8. 49.100
  libswscale      6.  8.112 /  6.  8.112
  libswresample   4.  9.100 /  4.  9.100
  libpostproc    56.  7.100 / 56.  7.100
Input #0, flac, from 'music/arctic.flac':
  Metadata:
    Language        : English
    track           : 6
    Artist          : Arctic Monkeys
    Title           : Four Out Of Five
    Rip Date        : 2018-05-07
    Date            : 2018
    Retail Date     : 2018-05-11
    Media           : CD (LP)
    Encoder         : LAME 3.98.4
    Ripping Tool    : EAC
    Release Type    : Normal release
    Genre           : Rock
    ORGANIZATION    : Domino
    Album           : Tranquility Base Hotel & Casino
  Duration: 00:05:12.35, start: 0.000000, bitrate: 966 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> opus (libopus))
Press [q] to stop, [?] for help
Output #0, matroska, to 'arctic.mka':
  Metadata:
    Language        : English
    PART_NUMBER     : 6
    Artist          : Arctic Monkeys
    Title           : Four Out Of Five
    Rip Date        : 2018-05-07
    Date            : 2018
    Retail Date     : 2018-05-11
    Media           : CD (LP)
    Album           : Tranquility Base Hotel & Casino
    Ripping Tool    : EAC
    Release Type    : Normal release
    Genre           : Rock
    ORGANIZATION    : Domino
    encoder         : Lavf59.33.100
  Stream #0:0: Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, stereo, s16, 64 kb/s
    Metadata:
      encoder         : Lavc59.49.100 libopus
size=    2524kB time=00:05:12.33 bitrate=  66.2kbits/s speed= 138x
video:0kB audio:2414kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.531828%

@abreumatheus
Copy link
Author

By the way, and I know this is off topic but I'm curious - is there a reason why you're using the Matroska container (.mka) for the output file instead of .opus?

Just following the recommendation on ffmpeg for maximum quality when there is no concern about compatiblity.

When compatibility with hardware players doesn't matter then use libopus in a MKV container when libfdk_aac isn't available.

Font

@CrypticSignal
Copy link
Owner

Just following the recommendation on ffmpeg for maximum quality when there is no concern about compatiblity.

That's if it's a video file that contains audio. It doesn't make sense to use the MKV for an audio file, because when you look at the file extension, it implies that it's a video file.

Whether you use the MKV container or the Ogg container with the .opus file extension will have no effect on the audio quality as they're just containers. A reduction in audio quality happens when you do lossy trancoding (which you are doing by converting to Opus with -c:a libopus). So if you want to convert an audio file to Opus, it makes more sense to use the .opus file extension as this indicates that it's an Opus audio file.

I'm assuming you want to convert to Opus to reduce the file size which is fine, but keep in mind that there will be a reduction in audio quality. Whether or not this will be noticeable to you is another matter, but you are using a pretty low bitrate of 64 kbps so there is a decent chance that this will be noticeable. When using Opus for stereo music, I'd probably go for a bitrate somewhere between 128 and 192 kbps.

Can you share the artic.flac file? Something like Google Drive will work and you can share the file with me only (my email is hshafiq96@gmail.com) or you can PM me the link on Discord - Cryptic Signal#4416

@abreumatheus
Copy link
Author

MKV is a container for video, MKA (the one I used) is a container for audio. But all of this shouldn't matter to the issue.
I just shared the file with you, check your email.

@CrypticSignal
Copy link
Owner

MKV is a container for video, MKA (the one I used) is a container for audio.

I was responding to the quote you shared where MKV was mentioned:

When compatibility with hardware players doesn't matter then use libopus in a MKV container when libfdk_aac isn't available.

Also, whether you use MKV or MKA, one of my points was that using the Matroska container has got nothing to do with achieving "maximum quality" (I'm quoting you here).

I just shared the file with you, check your email.

I haven't received the file.

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