WyattBlue / auto-editor

Auto-Editor: Efficient media analysis and rendering
https://auto-editor.com
The Unlicense
2.93k stars 425 forks source link

"Invalid argument" error occurred #297

Closed flt6 closed 2 years ago

flt6 commented 2 years ago

What's your platform?

Python Version: 3.9.1 64-bit
Platform: Windows 10 amd64
FFmpeg Version: N-105325-g7512293cf9
FFmpeg Path: F:\ProgramData\Miniconda3\Lib\site-packages\ae_ffmpeg\Windows\ffmpeg.exe
Auto-Editor Version: 22w32a      (22w35c still exists)

Bug description

When running with arg "-v", error occurred when creating audio. Output file like this: C:\Users\****\AppData\Local\Temp\tmpxyvgfm07\tsm_out.wav: Invalid argument

What command did you use

auto-editor -v 1.5 "in.mp4" -m 10 -o out.mp4

What properties does your input video have?

auto-editor:
2022-09-02 09-05-33.mp4:
 - video:
   - track 0:
     - codec: h264
     - fps: 30
     - resolution: 1280x720
     - aspect ratio: 16:9
     - pixel aspect ratio: 1:1
     - duration: 4721.566667
     - pix fmt: yuv420p
     - color range: tv
     - color space: bt709
     - color primaries: bt709
     - color transfer: bt709
     - timebase: 1/15360
     - bitrate: 486684
     - lang: und
 - audio:
   - track 0:
     - codec: aac
     - samplerate: 48000
     - duration: 4721.472000
     - bitrate: 54143
     - lang: und
 - container:
   - duration: 4721.567000
   - bitrate: 552644

ffmpeg:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2022-09-02 09-05-33.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.20.101
  Duration: 01:18:41.57, start: 0.000000, bitrate: 552 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 486 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 54 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      vendor_id       : [0][0][0][0]

Comments

The key question is -v, it only occur when it is used. I added breakpoint at render/audio.py , and find file is not closed after function read. I checked file wavfile.py, and add fid.close() at line 226, but it doesn't work. The file is still not closed. I broke at line 97, I found file af_out.wav is not closed, which resulted in that error.

I tried to call this function from other file, but it runs well. At the second stop, af_out.wav can be deleted. Test code (*** is hidden due to private):

from subprocess import run
from auto_editor.wavfile import read

opt = 'C:\\Users\\***\\AppData\\Local\\Temp\\tmpngvy7kyt\\af_out.wav'
cmd = [
    'F:\\ProgramData\\Miniconda3\\Lib\\site-packages\\ae_ffmpeg\\Windows\\ffmpeg.exe', 
    '-y', 
    '-hide_banner', 
    '-i', 'C:\\Users\\***\\AppData\\Local\\Temp\\tmpngvy7kyt\\af.wav', 
    '-af', 
    'atempo=1.5', 
    opt, 
    '-nostats', 
    '-loglevel', 
    'error'
]

input("bgn")
print(run(cmd))
print(read(opt))
input("end")
flt6 commented 2 years ago

It haven't occurred recently.

flt6 commented 2 years ago

I found it usually happens when I use it in windows but never occur in Linux.

WyattBlue commented 2 years ago

Does this happen on the latest version?

flt6 commented 2 years ago

I have test this just after I install it from pypi as latest version.