This is my code:
videoAdd =(VideoFileClip("video5.avi", audio=False))
audioAdd =(AudioFileClip("1.mp3"))
final = CompositeVideoClip([videoAdd, audioAdd])
final.subclip(0,3).write_videofile("video5audio.avi",fps=24,codec='libx264')
But when I run it I am getting the following error:
AttributeError: 'NoneType' object has no attribute 'start'
Am I doing something wrong when adding the audio or is it something else?
The right way would be something like this:
audioclip = AudioFileClip("1.mp3")
videoclip = VideoFileClip("video5.avi")
finalclip = videoclip.set_audio(audioclip)
finalclip.subclip(0,3).write_videofile("video5audio.avi",fps=24,codec='libx264')
Thanks for the prompt response!
However when I run that code I get the following:
Traceback (most recent call last):
File "D:\Python34\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 300, in ffmpeg_parse_infos
tbr = float(line[match.start():match.end()].split(' ')[1])
ValueError: could not convert string to float: '90k'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Users\main\Desktop\video_code\test.py", line 88, in <module>
audioclip = AudioFileClip("1.mp3")
File "D:\Python34\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 63, in **init**
buffersize=buffersize)
File "D:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 56, in **init**
infos = ffmpeg_parse_infos(filename)
File "D:\Python34\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 305, in ffmpeg_parse_infos
result['video_fps'] = float(line[match.start():match.end()].split(' ')[1])
AttributeError: 'NoneType' object has no attribute 'start'
Does the audio need to be cut to match the exact length of the video?
Strange, at first sight it looks like the fps of your mp3 is given as 90k while moviepy would expect 90000. I thought this was taken care of. Could you try converting your mp3 to something else ? Like open a terminal and type ffmpeg -i 1.mp3 -r 48000 1bis.mp3 to convert the mp3 to a 48000fps file ?
I did that and I got the same result
Traceback (most recent call last):
File "D:\Python34\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 300, in ffmpeg_parse_infos
tbr = float(line[match.start():match.end()].split(' ')[1])
ValueError: could not convert string to float: '90k'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Users\main\Desktop\video_code\test.py", line 88, in <module>
audioclip = AudioFileClip("1bis.mp3")
File "D:\Python34\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 63, in **init**
buffersize=buffersize)
File "D:\Python34\lib\site-packages\moviepy\audio\io\readers.py", line 56, in **init**
infos = ffmpeg_parse_infos(filename)
File "D:\Python34\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 305, in ffmpeg_parse_infos
result['video_fps'] = float(line[match.start():match.end()].split(' ')[1])
AttributeError: 'NoneType' object has no attribute 'start'
Sorry, forgot my ffmpeg output.
D:\Users\mainDesktop\video_code>ffmpeg -i 1.mp3 -r 48000 1bis.mp3
ffmpeg version N-75573-g1d0487f Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --ena
ble-decklink --enable-zlib
libavutil 55. 2.100 / 55. 2.100
libavcodec 57. 3.100 / 57. 3.100
libavformat 57. 2.100 / 57. 2.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 9.100 / 6. 9.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.100 / 2. 0.100
libpostproc 54. 0.100 / 54. 0.100
[mp3 @ 00000000003f01c0] Skipping 0 bytes of junk at 97054.
Input #0, mp3, from '1.mp3':
Metadata:
date : 2008
track : 1/10
title : Bottom Rung
album : Good Evening
genre : Indie
artist : Nite Jewel
replaygain_album_gain: -8.40 dB
replaygain_album_peak: 1.049781
replaygain_track_gain: -6.26 dB
replaygain_track_peak: 1.004341
Duration: 00:02:34.96, start: 0.025056, bitrate: 205 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 200 kb/s
Metadata:
encoder : LAME3.98r
Side data:
replaygain: track gain - -6.260000, track peak - 0.000023, album gain - -8
.400000, album peak - 0.000024,
Stream #0:1: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 285x285 [S
AR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
Metadata:
comment : Other
File '1bis.mp3' already exists. Overwrite ? [y/N] y
[swscaler @ 0000000002a340a0] deprecated pixel format used, make sure you did se
t range correctly
[mp3 @ 0000000002a6d5a0] Frame rate very high for a muxer not efficiently suppor
ting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
Output #0, mp3, to '1bis.mp3':
Metadata:
TDRC : 2008
TRCK : 1/10
TIT2 : Bottom Rung
TALB : Good Evening
TCON : Indie
TPE1 : Nite Jewel
replaygain_album_gain: -8.40 dB
replaygain_album_peak: 1.049781
replaygain_track_gain: -6.26 dB
replaygain_track_peak: 1.004341
TSSE : Lavf57.2.100
Stream #0:0: Video: png, rgb24, 285x285 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s,
48k fps, 48k tbn, 48k tbc
Metadata:
comment : Other
encoder : Lavc57.3.100 png
Stream #0:1: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc57.3.100 libmp3lame
Stream mapping:
Stream #0:1 -> #0:0 (mjpeg (native) -> png (native))
Stream #0:0 -> #0:1 (mp3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:17.47 bitrate= 0.1kbits/s
frame= 1 fps=1.0 q=0.0 size= 0kB time=00:00:34.82 bitrate= 0.1kbits/s
frame= 1 fps=0.7 q=0.0 size= 0kB time=00:00:52.08 bitrate= 0.0kbits/s
frame= 1 fps=0.5 q=0.0 size= 0kB time=00:01:09.56 bitrate= 0.0kbits/s
frame= 1 fps=0.4 q=0.0 size= 0kB time=00:01:26.98 bitrate= 0.0kbits/s
frame= 1 fps=0.3 q=0.0 size= 0kB time=00:01:44.59 bitrate= 0.0kbits/s
frame= 1 fps=0.3 q=0.0 size= 0kB time=00:02:01.91 bitrate= 0.0kbits/s
frame= 1 fps=0.2 q=0.0 size= 0kB time=00:02:19.49 bitrate= 0.0kbits/s
frame= 1 fps=0.2 q=-0.0 Lsize= 2624kB time=00:02:34.90 bitrate= 138.8kbits
/s
video:203kB audio:2421kB subtitle:0kB other streams:0kB global headers:0kB muxin
g overhead: 0.020884%
Same problem here, it happens with mp3 files having an image cover. ffmpeg detects it has a video stream with tbr/tbn/tbc values like 48k, 90k, etc.
# get the frame rate. Sometimes it's 'tbr', sometimes 'fps', sometimes
# tbc, and sometimes tbc/2...
# Current policy: Trust tbr first, then fps. If result is near from x*1000/1001
# where x is 23,24,25,50, replace by x*1000/1001 (very common case for the fps).
try:
match = re.search("( [0-9]*.| )[0-9]* tbr", line)
tbr = float(line[match.start():match.end()].split(' ')[1])
result['video_fps'] = tbr
except:
match = re.search("( [0-9]*.| )[0-9]* fps", line)
result['video_fps'] = float(line[match.start():match.end()].split(' ')[1])
It crashes at this line https://github.com/Zulko/moviepy/blob/master/moviepy/video/io/ffmpeg_reader.py#L305, but the real problem seems to be in the try block.
issue #448 has the same problem.
This is still an issue. VideoClip.set_audio(audioclip) does not seem to work after testing it on an ImageClip obj and CompositeVideoClip obj and with multiple different audio files with param audioclip=AudioFileClip('/home/j/my_song.mp3')
Most helpful comment
Same problem here, it happens with mp3 files having an image cover. ffmpeg detects it has a video stream with tbr/tbn/tbc values like 48k, 90k, etc.
It crashes at this line https://github.com/Zulko/moviepy/blob/master/moviepy/video/io/ffmpeg_reader.py#L305, but the real problem seems to be in the try block.