Recherche avancée

Médias (1)

Mot : - Tags -/copyleft

Autres articles (68)

Sur d’autres sites (11230)

  • Why AudioSegment doesn't read 'mp3' ?

    22 octobre 2020, par freshITmeat

    I tried to read file that I give with absolute path.
When I run my code first that I see is this message :

    


    D:\prog\datascience\anaconda\lib\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)


    


    I tried this :

    


    PATH_TO_FFMPEG = 'D:\\prog\\ffmpeg-win-2.2.2\\ffmpeg.exe'
pydub.AudioSegment.converter = r'D:\\prog\\ffmpeg-win-2.2.2\\ffmpeg.exe'


    


    And I separately installed ffmpeg with pip. But it didn't help.
When I try this :

    


    raw_sound = pydub.AudioSegment.from_mp3(file=track_path)


    


    where track_path is correct absolute path generated automatically.
So I got this this error :

    


    Traceback (most recent call last):&#xA;  File "D:\prog\PyCharm Community Edition 2020.2.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1448, in _exec&#xA;    pydev_imports.execfile(file, globals, locals)  # execute the script&#xA;  File "D:\prog\PyCharm Community Edition 2020.2.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile&#xA;    exec(compile(contents&#x2B;"\n", file, &#x27;exec&#x27;), glob, loc)&#xA;  File "D:/testtask2/test_task/testtask/get_mffc.py", line 165, in <module>&#xA;    slice_all_in_a_dir(&#x27;May 27 2020 LNC/Hydrophone 1/raw_records&#x27;)&#xA;  File "D:/testtask2/test_task/testtask/get_mffc.py", line 70, in slice_all_in_a_dir&#xA;    slice_samples(track_path= [file],&#xA;  File "D:/testtask2/test_task/testtask/get_mffc.py", line 48, in slice_samples&#xA;    raw_sound = pydub.AudioSegment.from_mp3(file=track_path)&#xA;  File "D:\prog\datascience\anaconda\lib\site-packages\pydub\audio_segment.py", line 738, in from_mp3&#xA;    return cls.from_file(file, &#x27;mp3&#x27;, parameters=parameters)&#xA;  File "D:\prog\datascience\anaconda\lib\site-packages\pydub\audio_segment.py", line 680, in from_file&#xA;    stdin_data = file.read()&#xA;AttributeError: &#x27;list&#x27; object has no attribute &#x27;read&#x27;&#xA;python-BaseException&#xA;</module>

    &#xA;

    Full code when I use it :

    &#xA;

    def slice_samples(track_path: list, save_path: str,&#xA;                  sample_folder_name: str, interval: float, given_format, name: str = "part", export_format = &#x27;wav&#x27;):&#xA;    """&#xA;    This metod slice given track to parts.&#xA;    :param track_path: str, a path to the track you want to slice&#xA;    :param save_path: str, a path to folder, where you want save sliced tracks&#xA;    :param sample_folder_name: str, you don&#x27;t need to create a folder for sliced tracks,&#xA;    you can just write the name of the folder in this argument where you want to save tracks&#xA;    :param interval: float, measure in seconds, the length of sliced tracks&#xA;    :param name: str, name of sliced tacks&#xA;    :param given_format: str, I strongly recommend use .wav format initially, when you record sounds&#xA;    :return: folder with sliced tracks&#xA;    """&#xA;&#xA;    # it cuts a file in mp3 or wav formats (wav recommended)&#xA;&#xA;    interval_secs = interval * 10 ** 3&#xA;    raw_sound = None&#xA;    if given_format == "WAV":&#xA;        raw_sound = pydub.AudioSegment.from_wav(file=track_path)&#xA;    elif given_format == "MP3":&#xA;        raw_sound = pydub.AudioSegment.from_mp3(file=track_path)&#xA;    else:&#xA;        raise Exception("It&#x27;s temporarily unsupported given_format: " &#x2B; given_format)&#xA;    start = 0&#xA;    end = interval_secs&#xA;    i = 0&#xA;    while end &lt; len(raw_sound):&#xA;        save_to = save_path &#x2B; sample_folder_name &#x2B; "/" &#x2B; name &#x2B; str(i)&#xA;        part = raw_sound[start:end]&#xA;        part.export(save_to, format=export_format)&#xA;        i &#x2B;= 1&#xA;        start &#x2B;= interval_secs&#xA;        end &#x2B;= interval_secs&#xA;    return save_path &#x2B; sample_folder_name&#xA;&#xA;def slice_all_in_a_dir(tracks_folder: str):&#xA;    files = os.listdir(tracks_folder)&#xA;    for file in files:&#xA;        folder_name = file.split(&#x27;.&#x27;)&#xA;        f_name = folder_name[0]&#xA;        file = tracks_folder&#x2B;&#x27;/&#x27;&#x2B;file&#xA;        file = os.path.abspath(file)&#xA;        slice_samples(track_path= [file],&#xA;                      save_path= PATH_FOR_SLICED,&#xA;                      sample_folder_name= f_name,&#xA;                      interval=5,&#xA;                      given_format=folder_name[1])&#xA;&#xA;if __name__ == "__main__":&#xA;    slice_all_in_a_dir(&#x27;May 27 2020 LNC/Hydrophone 1/raw_records&#x27;)&#xA;

    &#xA;

  • Laravel FFMpeg - FFMpeg cannot edit existing files in-place

    28 septembre 2020, par wlaskovic

    After I wanted to upload a video in the queue was returned a failed job.

    &#xA;

     [2020-09-25 13:24:25][125] Processing: App\Jobs\ConvertVideoForStreaming <br /> [2020-09-25 13:24:26][125] Failed:     App\Jobs\ConvertVideoForStreaming&#xA;

    &#xA;

    So I've took from the DB failed_jobs table the response and run the following :

    &#xA;

      C:\ffmpeg\bin\ffmpeg.exe -y -i "C:\wamp64\www\laravel-stream\storage\app/public\WF3UL8fJTSE7BMxa.mp4" -threads 12 -vcodec libx264 -acodec libmp3lame -b:v 500k -refs 6 -coder 1 -sc_threshold 40 -flags &#x2B;loop -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -trellis 1 -b:a 128k -vf "[in]scale=720:360 [out]" -pass 1 -passlogfile "C:\Users\wlask\AppData\Local\Temp\ffmpeg-passes5f6dd36a4519fd1fev/pass-5f6dd36a452c9" "C:\wamp64\www\laravel-stream\storage\app/public\WF3UL8fJTSE7BMxa.mp4"&#xA;

    &#xA;

    Which returned the following :

    &#xA;

    ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers&#xA;  built with gcc 10.2.1 (GCC) 20200726&#xA;  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf&#xA;  libavutil      56. 51.100 / 56. 51.100&#xA;  libavcodec     58. 91.100 / 58. 91.100&#xA;  libavformat    58. 45.100 / 58. 45.100&#xA;  libavdevice    58. 10.100 / 58. 10.100&#xA;  libavfilter     7. 85.100 /  7. 85.100&#xA;  libswscale      5.  7.100 /  5.  7.100&#xA;  libswresample   3.  7.100 /  3.  7.100&#xA;  libpostproc    55.  7.100 / 55.  7.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;C:\wamp64\www\laravel-stream\storage\app/public\WF3UL8fJTSE7BMxa.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : mp42&#xA;    minor_version   : 0&#xA;    compatible_brands: mp42mp41isomavc1&#xA;    creation_time   : 2015-08-07T09:13:02.000000Z&#xA;  Duration: 00:00:30.53, start: 0.000000, bitrate: 411 kb/s&#xA;    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 480x270 [SAR 1:1 DAR 16:9], 301 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc (default)&#xA;    Metadata:&#xA;      creation_time   : 2015-08-07T09:13:02.000000Z&#xA;      handler_name    : L-SMASH Video Handler&#xA;      encoder         : AVC Coding&#xA;    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 112 kb/s (default)&#xA;    Metadata:&#xA;      creation_time   : 2015-08-07T09:13:02.000000Z&#xA;      handler_name    : L-SMASH Audio Handler&#xA;

    &#xA;

    &#xA;

    Output C :\wamp64\www\laravel-stream\storage\app/public\WF3UL8fJTSE7BMxa.mp4 same as Input #0 - exiting

    &#xA;

    FFmpeg cannot edit existing files in-place.

    &#xA;

    &#xA;

    This was returned after i've run the command from DB failed jobs table return.

    &#xA;

    How should I solve this ?

    &#xA;

  • FFmpeg return 'invalid argument' only for some runs, even tought is the same code

    20 septembre 2021, par Gustavo Marinho

    I have a code in python where i need to use FFmpeg to merge a audio and a video downloaded using pytube together :

    &#xA;

            for video in p.videos:&#xA;            video.streams.filter(file_extension=&#x27;mp4&#x27;,resolution=&#x27;480p&#x27;)[0].download(parent_dir&#x2B;&#x27;/mp4/processing/video&#x27;)&#xA;            print(video.streams.filter(only_audio=True)[1].download(parent_dir&#x2B;&#x27;/mp4/processing/audio&#x27;))&#xA;&#xA;            subprocess.run([&#xA;&#xA;                r&#x27;c:\FFmpeg\bin\ffmpeg&#x27;, &#x27;-i&#x27;,&#xA;                os.path.join(parent_dir&#x2B;&#x27;/mp4/processing/video&#x27;,video.streams.filter(file_extension=&#x27;mp4&#x27;,resolution=&#x27;480p&#x27;)[0].default_filename)&#xA;                ,&#x27;-i&#x27;,&#xA;                os.path.join(parent_dir&#x2B;&#x27;/mp4/processing/audio&#x27;,video.streams.filter(only_audio=True)[1].default_filename),&#xA;                &#x27;-c:v&#x27;,&#x27;copy&#x27;,&#x27;-c:a&#x27;,&#x27;copy&#x27;,&#xA;                os.path.join(parent_dir&#x2B;&#x27;/mp4&#x27;,video.streams.filter(file_extension=&#x27;mp4&#x27;,resolution=&#x27;480p&#x27;)[0].title&#x2B;&#x27;.mp4&#x27;)&#xA;&#xA;            ])&#xA;

    &#xA;

    I tought the code was working perfectly, but in some cases, the FFmpeg returns "invalid argument", like this example :

    &#xA;

    ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers&#xA;  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)&#xA;  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint&#xA;  libavutil      56. 70.100 / 56. 70.100&#xA;  libavcodec     58.134.100 / 58.134.100&#xA;  libavformat    58. 76.100 / 58. 76.100&#xA;  libavdevice    58. 13.100 / 58. 13.100&#xA;  libavfilter     7.110.100 /  7.110.100&#xA;  libswscale      5.  9.100 /  5.  9.100&#xA;  libswresample   3.  9.100 /  3.  9.100&#xA;  libpostproc    55.  9.100 / 55.  9.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;D:/videos/mp4/processing/video\Dropkick Murphys - Rose Tattoo (Video).mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : dash&#xA;    minor_version   : 0&#xA;    compatible_brands: iso6avc1mp41&#xA;    creation_time   : 2020-04-04T10:16:52.000000Z&#xA;  Duration: 00:05:26.08, start: 0.000000, bitrate: 557 kb/s&#xA;  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 854x480 [SAR 1:1 DAR 427:240], 7 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-04-04T10:16:52.000000Z&#xA;      handler_name    : ISO Media file produced by Google Inc.&#xA;      vendor_id       : [0][0][0][0]&#xA;Input #1, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;D:/videos/mp4/processing/audio\Dropkick Murphys - Rose Tattoo (Video).mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : dash&#xA;    minor_version   : 0&#xA;    compatible_brands: iso6mp41&#xA;    creation_time   : 2020-04-04T10:16:00.000000Z&#xA;  Duration: 00:05:26.12, start: 0.000000, bitrate: 129 kb/s&#xA;  Stream #1:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 3 kb/s (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-04-04T10:16:00.000000Z&#xA;      handler_name    : ISO Media file produced by Google Inc.&#xA;      vendor_id       : [0][0][0][0]&#xA;D:/videos/mp4\Dropkick Murphys - "Rose Tattoo" (Video).mp4: Invalid argument&#xA;

    &#xA;

    For some reason, the FFmpeg say that my output name is invalid, but i don't understand why, given that i ran the code multiple times before and it worked perfectly

    &#xA;

    Thanks in advance, sorry for my bad english :3

    &#xA;