1

I'm attempting to trim and concatenate several video files using ffmpeg. These videos have already been transcoded with H.264 at a resolution of 720p. However, when executing the command, I encounter the following error.

[aost#0:1/copy @ 0x55728055fe00] Error submitting a packet to the muxer: Cannot allocate memory+03x
Last message repeated 1 times [out#0/mp4 @ 0x55727ff66f80] Error muxing a packet [out#0/mp4 @ 0x55727ff66f80] Task finished with error code: -12 (Cannot allocate memory) [out#0/mp4 @ 0x55727ff66f80] Terminating thread with return code -12 (Cannot allocate memory) [out#0/mp4 @ 0x55727ff66f80] Error writing trailer: Cannot allocate memory

My command is:

ffmpeg -hwaccel cuda -v error -stats -y -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -stream_loop -1 -i audio.mp3 -filter_complex '[1:v]trim=start=1371:end=1384,setpts=PTS-STARTPTS[v1];[2:v]trim=start=3471:end=3484,setpts=PTS-STARTPTS[v2];[0:v][v1][v2][3:v]concat=n=4:v=1:a=0[v]' -map '[v]' -vsync 2 -map 4:a:0 -c:a copy -c:v h264_nvenc -preset fast -f mp4 output.mp4

Any help please ? Also, I'm wondering if using cuda can help speed the operation.

4
  • The issue in not reproducible. Try updating FFmpeg to the latest stable release. What is your version of FFmpeg? What is the OS? What is the size of the system RAM? What is the GPU type?
    – Rotem
    Commented Mar 22 at 11:00
  • I think the issue is related to the trim filters. Try using -ss and -to instead of trim filter, and add -shortest: ffmpeg -hwaccel cuda -stats -y -an -i input1.mp4 -ss 1371 -to 1384 -an -i input2.mp4 -ss 3471 -to 3484 -an -i input3.mp4 -an -i input4.mp4 -stream_loop -1 -i audio.mp3 -filter_complex "[0:v][1:v][2:v][3:v]concat=n=4:v=1:a=0[v]" -map "[v]" -fps_mode:v vfr -map 4:a:0 -c:a copy -c:v h264_nvenc -preset fast -shortest -f mp4 output2.mp4
    – Rotem
    Commented Mar 22 at 11:27
  • @Rotem I'm working with ffmpeg version N-114300-g535b1a93f5, compiled with gcc 11 on Ubuntu 22.04, coupled with 64GB RAM and an Nvidia GPU. Despite attempting options like -ss and -to, along with incorporating the -shortest filter, it always throws errors. However, I managed to resolve the issue by dividing the task into two separate commands: initially trimming the videos and saving them individually, followed by concatenating the trimmed videos.
    – Zahra
    Commented Mar 23 at 14:01
  • I can't recommend your solution, because it probably re-encodes the video twice, and loses quality (I recommend you to post the commands, in your answer). The issue is probably related to your version of FFmpeg (I assume N-114300-g535b1a93f5 is a custom build of a version that may not be a "stable release").
    – Rotem
    Commented Mar 23 at 21:18

1 Answer 1

0

I managed to resolve the issue by dividing the task into two separate commands: initially trimming the videos with the trim filter and saving them individually, followed by concatenating the trimmed videos.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .