I am using ffmpeg_extract_subclip(video_name, start-9, start, targetname=target_name)
to trim a 9s video.
The start
(int
) variable comes from a json file:
start = b_info_list[elem+1]["start_time"]
delta_1 = dt.strptime(start, "%H:%M:%S.%f") - dt.strptime("", "")
start = int(delta_1.total_seconds())
The same exact code is working for most of the videos and their json counterparts, but not working for some of them only. So I'm assuming there's nothing wrong with variables start
which is always >= 10
and video_name
, target_name
.
The error log is below:
Traceback (most recent call last):
File "data/video_trim.py", line 324, in <module>
main()
File "data/video_trim.py", line 316, in main
norm_symp_act_videos(f)
File "data/video_trim.py", line 235, in norm_symp_act_videos
ffmpeg_extract_subclip(video_name, start-9, start, targetname=target_name)
File "/home/office/anaconda3/envs/env_2/lib/python3.7/site-packages/moviepy/video/io/ffmpeg_tools.py", line 41, in ffmpeg_extract_subclip
subprocess_call(cmd)
File "/home/office/anaconda3/envs/env_2/lib/python3.7/site-packages/moviepy/tools.py", line 54, in subprocess_call
raise IOError(err.decode('utf8'))
OSError: ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/office/data/video_05.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2021-10-13T04:33:45.000000Z
encoder : Lavf58.45.100
Duration: 00:02:00.07, start: 0.000000, bitrate: 3149 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 3148 kb/s, SAR 1:1 DAR 16:9, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
creation_time : 2021-10-13T04:33:45.000000Z
handler_name : VideoHandler
timecode : 01:00:00:00
Stream #0:1(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 2021-10-13T04:33:45.000000Z
handler_name : TimeCodeHandler
timecode : 01:00:00:00
[mp4 @ 0x62a7600] You requested a copy of the original timecode track so timecode metadata are now ignored
[mp4 @ 0x62a7600] Could not find tag for codec none in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Last message repeated 1 times
The function looks like this:
def ffmpeg_extract_subclip(filename, t1, t2, targetname=None):
""" Makes a new video file playing video file ``filename`` between
the times ``t1`` and ``t2``. """
name, ext = os.path.splitext(filename)
if not targetname:
T1, T2 = [int(1000*t) for t in [t1, t2]]
targetname = "%sSUB%d_%d.%s" % (name, T1, T2, ext)
cmd = [get_setting("FFMPEG_BINARY"),"-y",
"-ss", "%0.2f"%t1,
"-i", filename,
"-t", "%0.2f"%(t2-t1),
"-map", "0", "-vcodec", "copy", "-acodec", "copy", targetname]
subprocess_call(cmd)
I looked for the similar issues, but solutions to them are in command format which I don't understand. Is there anyone who can help solve this issue? Thanks.