Forums

FFmpeg Not Working Properly

One of the dependencies of my web application is FFmpeg. But the currently installed version of FFmpeg just gives errors like "Error: Conversion Failed". I don't really think its my application coz i've ran it about a thousand times locally and the results are fine. Could it be due to the old version currently installed ? Please help you know a get around to this problem

what is the conversion command that you are using?

I was muxing together a video mp4 file with an audio mp3 file.

Can you provide the exact command you're running so we could try to reproduce the error?

pip install ffmpeg-python #after installing at console and importing ffmpeg

import ffmpeg video_stream = ffmpeg.input("/home/vishnuji/Downloads/video.mp4") audio_stream = ffmpeg.input("/home/vishnuji/Downloads/audio.mp4")

ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run()

this is not woking

In what way does it not work? What are you expecting it to do and what is it doing instead?

same program runs on local server for merging video and audio..but it doesnot work at pythonanywhere...error is like "ffmpeg error (see stderr output for detail)"

Did you check the stderr output for details to see what might be failing?

where i will check stderr output???? please tell in simple way...

It depends how you're running the code. If it's in a Bash console, and you didn't redirect the stderr, you should see the output in the console, if it's in a web app, you should check error logs (in 'Log files' section of the Web app), if it's in a task -- in task logs.

This is error log..i still unable to figure out..why this is giving error..same code runs on visual studio code on local server.

2021-03-08 17:34:29,564: Internal Server Error: /youtube/complete/720p
Traceback (most recent call last):
  File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/vishnuji/blog/youtube/views.py", line 94, in download_complete
    ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run()
  File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/ffmpeg/_run.py", line 325, in run
    raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)

[edit by admin: formatting]

It looks like it's failing on this call ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run() -- maybe wrap this with try except statement, enable stderr capture with capture_stderr=True argument provided to run and try to catch that error.

this is not working even i tried with capture_stdout=True also.

outvideo.mp4 is created with o zero size

try:
    video_stream = ffmpeg.input("/home/vishnuji/Downloads/video.mp4")
    audio_stream = ffmpeg.input("/home/vishnuji/Downloads/audio.mp4")
    ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run(capture_stderr=True)

    response= FileResponse(open('/home/vishnuji/outvideo.mp4','rb'), as_attachment=True)
    return response

except ffmpeg.Error as e:
# except Exception as e:


    return render(request, 'error.html', {'url': url, 'error': e})

[edit by admin: formatting]

What happens if you print the captured stderr? Code to do that would look like this:

out, err = ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run(capture_stderr=True)
print("output")
print(out)
print("err")
print(err)

server log : not showing print statement after out,err however error log showing these result:

2021-03-09 08:33:43,569: Internal Server Error: /youtube/complete/720p
Traceback (most recent call last):
  File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/vishnuji/blog/youtube/views.py", line 100, in download_complete
    out, err = ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run(capture_stderr=True)
  File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/ffmpeg/_run.py", line 325, in run
    raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)

Do you still run it inside try/except block?

this above code has not executed try/except block...

Now i guess pythonanywhere has no solution for this ..

Try:

try:
    out, err = ffmpeg.output(audio_stream, video_stream, 'outvideo.mp4').run(capture_stderr=True)
except ffmpeg.Error as e:
    print("output")
    print(e.stdout)
    print("err")
    print(e.stderr)

server logs: below

2021-03-09 23:05:51 2021-03-09 23:05:51 output 2021-03-09 23:05:51 None 2021-03-09 23:05:51 err 2021-03-09 23:05:51 b"ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers\n built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609\n configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-l

Error log:

2021-03-09 23:04:17,013: /home/vishnuji/blog/youtube/views.py:48: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless). 2021-03-09 23:04:17,013: stream_all= yt.streams.all() 2021-03-09 23:04:28,421: Internal Server Error: /youtube/complete/720p Traceback (most recent call last): File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/django/core/handlers/base.py", line 181, in get_response response = wrapped_callback(request, callback_args, callback_kwargs) File "/home/vishnuji/blog/youtube/views.py", line 72, in download_complete s1 = YouTube(url).streams.filter(res=res) File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/pytube/main.py", line 90, in init self.video_id = extract.video_id(url) File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/pytube/extract.py", line 170, in video_id return regex_search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).", url, group=1) File "/home/vishnuji/.virtualenvs/python01/lib/python3.6/site-packages/pytube/helpers.py", line 40, in regex_search raise RegexMatchError(caller="regex_search", pattern=pattern) pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z-]{11}).* 2021-03-09 23:05:42,766: /home/vishnuji/blog/youtube/views.py:48: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless). 2021-03-09 23:05:42,766: stream_all= yt.streams.all()

please suggest

It looks like the error outpur from ffmpeg is being truncated by our logging system. Try printing the output like this:

print(e.stdout, file=sys.stderr)
print(e.stderr, file=sys.stderr)

outvideo.mp4 is created but its of 0 bytes..

Error log:

2021-03-10 07:44:11,114: /home/vishnuji/blog/youtube/views.py:48: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless). 2021-03-10 07:44:11,115: stream_all= yt.streams.all() 2021-03-10 07:44:52,483: /home/vishnuji/blog/youtube/views.py:48: DeprecationWarning: Call to deprecated function all (This object can be treated as a list, all() is useless). 2021-03-10 07:44:52,483: stream_all= yt.streams.all() 2021-03-10 07:45:00,251: None 2021-03-10 07:45:00,252: b"ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers\n built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609\n configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv\n libavutil 54. 31.100 / 54. 31.100\n libavcodec 56. 60.100 / 56. 60.100\n libavformat 56. 40.101 / 56. 40.101\n libavdevice 56. 4.100 / 56. 4.100\n libavfilter 5. 40.101 / 5. 40.101\n libavresample 2. 1. 0 / 2. 1. 0\n libswscale 3. 1.101 / 3. 1.101\n libswresample 1. 2.101 / 1. 2.101\n libpostproc 53. 3.100 / 53. 3.100\nInput #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/vishnuji/Downloads/audio.mp4':\n Metadata:\n major_brand : dash\n minor_version : 0\n compatible_brands: iso6mp41\n creation_time : 2020-01-28 19:11:09\n Duration: 00:04:39.71, start: 0.000000, bitrate: 129 kb/s\n Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 4 kb/s (default)\n Metadata:\n creation_time : 2020-01-28 19:11:09\n handler_name : ISO Media file produced by Google Inc.\nInput #1, mov,mp4,m4a,3gp,3g2,mj2, from '/home/vishnuji/Downloads/video.mp4':\n Metadata:\n major_brand : mp42\n minor_version : 0\n compatible_brands: isommp42\n creation_time : 2020-01-28 19:00:25\n Duration: 00:04:39.71, start: 0.000000, bitrate: 655 kb/s\n Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 556 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)\n Metadata:\n creation_time : 2020-01-28 19:00:25\n handler_name : ISO Media file produced by Google Inc. Created on: 01/28/2020.\n Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)\n Metadata:\n creation_time : 2020-01-28 19:00:25\n handler_name : ISO Media file produced by Google Inc. Created on: 01/28/2020.\n[aac @ 0x281d840] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.\n"

It looks like your issue may be:

The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.

Check the python ffmpeg documentation to see how you can pass that argument to ffmpeg.

i am not finding ways to do it separately. i think its loopholes at pythonanywhrere server which restricting this..kindly suggest how to overcome and any other way to do my job done.

It looks like you can add an extra_args argument to run that will add the arguments you provide.

not working...please suggest a way or any other package for this..Otherwise i have to leave this project..

Have you tried moviepy? I know about PythonAnywhere users using it.