1

I need to extract audio from video and save it. FFmpeg has command for this purpose. I wonder if it is a right way to execute ffmpeg from my code and not to write code with their API functions.

The lack of this approach is that I use Qt Framework and need cross-platform application. Sometimes (especially in windows, because PATH variable doesn't set up automatically so call ffmpeg won't work) a user will need to indicate path to executable file to run in command line.

So both variants are possible to realize, but which is the best and correct one?

I don't really want to use their API because it is not so easy to understand and will take time to write my own code.

Thanks for any advice!

  • You can also use a wrapper library for this, which provides an easier API. A quick search gave me this: https://github.com/astoeckel/acinerella but there's probably others too. There's also https://vlc-qt.tano.si which is for VLC, and is made for Qt specifically (so might be a good choice.) VLC uses ffmpeg under the hood. – Nikos C. Jul 19 '17 at 00:36

2 Answers2

3

Using standalone ffmpeg seems to be preferred in your case. You will have to bundle ffmpeg and it's dependencies along with your application. However there is no need to set or use PATH or other environment variables to launch ffmpeg. You should do it by supplying full path to ffmpeg executable.

Using libav API is indeed rather tricky. And I would like to mention that in general (depending on codec) ffmpeg and libav should not be considered stable and you should spawn a separate process to protect main executable from potential crash in this case as well. So complexity of this approach is much higher compared to first one.

user7860670
  • 35,849
  • 4
  • 58
  • 84
  • What do you mean under "bundle ffmpeg along with your application"? I just need ffmpeg installed on the user's machine and find full path to ffmpeg executable, as you said. Then run something like that: QProcess savingProcess; ... savingProcess.start("\"C:/Program Files/FFmpeg/ffmpeg.exe\" -i \"C:/Users/Mikhail/Downloads/video.wmv\" -f mp3 -vn \"C:/Users/Mikhail/Videos/extract_audio.mp3\""); – Michael Pravilov Jul 18 '17 at 12:43
  • Well, finding ffmpeg on user's machine may be rather tricky. Probably a better solution in this case would be to allow user to manually specify ffmpeg location. – user7860670 Jul 18 '17 at 17:25
0

Disclaim: I never used Qt with ffmpeg together myself, but have much experience with Qt especially.

Qt tends to try having everything in their library, wrapping many other content for convenience. Most of the time (All those I tested), it is still possible quite easily to use the original library without troubles, but the Qt facilitate integration.

As an example: QOpenGLWidget is a wrapper for OpenGL with their widget system, adding signals and slots, etc. I made some test using normal OpenGL and it worked fine.

In another project, we(my team, not me particularly) used ffmpeg to display video on a QtWidget. It works with limited problems (due to other architectural requirements).

Considering your use case, and especially that you are using ffmpeg for background processing and not for displaying video, you may IMO go ahead with high probability of success.

Adrian Maire
  • 14,354
  • 9
  • 45
  • 85