Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
MP4 cut with ffmpeg doesn't play nicely in VLC but does in Browser
21 février, par AlexI cut a video with ffmpeg:
ffmpeg -ss 2 -to 10 -i src.mp4 -c copy out.mp4
But the playback in VLC is choppy for the first few seconds. Strangely it does play in my browser fine.
I saw this post: https://superuser.com/questions/1167958/video-cut-with-missing-frames-in-ffmpeg?newreg=1502e1698e0344acb214aa8d7e6048bd where the suggestion is to use
-avoid_negative_ts make_zero
. That does fix the playback in VLC. I think that shifts the whole stream, and results in the video being longer than I want it to be.For my use case I need the video to be precisely the correct length and I can't incur the cost of a (full) re-encode. I think the addition of
-avoid_negative_ts
is effectively snapping the cut to the nearest keyframe.So I think the negative timestamps are upsetting VLC? I can see they exist.
$ ffprobe -v error -select_streams v:0 -of default=noprint_wrappers=1 out.mp4 -show_entries packet=pts | head pts=-30720 pts=-30464 pts=-30208 pts=-29952
I also tried with a few other media players (Films & TV in Windows) and had similar issues. Is there a better way to handle this, in a way that will allow the output video to be played normally?
I saw the approach in this question: Cut a video in between key frames without re-encoding the full video using ffpmeg?. But had issues with "Non-monotonous DTS" that also seemed to manifest in choppy playback.
-
ffmpeg - How to combine overlapping clips from single video ?
21 février, par anonI am trying to use ffmpeg to take a few clips from a video and combine them together, similar to this:
Cut multiple parts of a video with ffmpeg
Except that the clips come from timestamps that overlap. My command looks like this:
"C:\Program Files\ffmpeg\bin\ffmpeg.exe" -y -i "C:\temp\5min.mp4" ^ -vf "select='between(t,4,6.5)+between(t,5,6)', setpts=N/FRAME_RATE/TB" ^ -af "aselect='between(t,4,6.5)+between(t,5,6)', asetpts=N/SR/TB" "C:\temp\5min-clip.mp4"
The video that I get only contains the first clip. I am on the latest version of ffmpeg. How do I accomplish this?
-
ffmpeg throws error "Invalid file index 1 in filtergraph description" when used with concat and -/filter_complex [closed]
20 février, par Ernst VI want to create mp4 videos from many small .jpg files (time-lapse). Each image is shown for 2 seconds and then fades to the next. This works fine when I issue the command with a few images (see below). But when the number of images reaches hundreds or thousands, I can no longer put them into a single command, but have to put the filenames and the complex filter into .txt files.
Whatever I try, I always get the error
"Invalid file index 1 in filtergraph description"
.This works fine:
ffmpeg -loop 1 -i "image1.jpg" -loop 1 -i "image2.jpg" -loop 1 -i "image3.jpg" -loop 1 -i "image4.jpg" -loop 1 -i "image5.jpg" -filter_complex "[0:v]trim=0:2,setpts=PTS-STARTPTS[v0]; [1:v]trim=0:2,setpts=PTS-STARTPTS[v1]; [2:v]trim=0:2,setpts=PTS-STARTPTS[v2]; [3:v]trim=0:2,setpts=PTS-STARTPTS[v3]; [4:v]trim=0:2,setpts=PTS-STARTPTS[v4]; [v0][v1] xfade=transition=fade:duration=1:offset=1 [xf1]; [xf1][v2] xfade=transition=fade:duration=1:offset=2 [xf2]; [xf2][v3] xfade=transition=fade:duration=1:offset=3 [xf3]; [xf3][v4] xfade=transition=fade:duration=1:offset=4 [xf4]" -map "[xf4]" -c:v libx264 -crf 18 -pix_fmt yuv420p output.mp4
But when I put the input files and the filter in txt files, it fails with the error above:
ffmpeg -stream_loop 1 -f concat -safe 0 -i concat_list.txt -/filter_complex filter_script.txt -map "[xf4]" -c:v libx264 -crf 18 -pix_fmt yuv420p output.mp4
This is the
concat_list.txt
:file 'image1.jpg' file 'image2.jpg' file 'image3.jpg' file 'image4.jpg' file 'image5.jpg'
This is the
filter_script.txt
:[0:v]trim=0:2,setpts=PTS-STARTPTS[v0];[1:v]trim=0:2,setpts=PTS-STARTPTS[v1];[2:v]trim=0:2,setpts=PTS-STARTPTS[v2];[3:v]trim=0:2,setpts=PTS-STARTPTS[v3];[4:v]trim=0:2,setpts=PTS-STARTPTS[v4];[v0][v1] xfade=transition=fade:duration=1:offset=1 [xf1];[xf1][v2] xfade=transition=fade:duration=1:offset=2 [xf2];[xf2][v3] xfade=transition=fade:duration=1:offset=3 [xf3];[xf3][v4] xfade=transition=fade:duration=1:offset=4 [xf4]
I tried adding/removing line breaks, semicolons, etc. Nothing helped. Any idea what is going wrong here? Thank you very much!
My ffmpeg version is the most recent one:
ffmpeg version 2025-02-17-git-b92577405b-full_build-www.gyan.dev
-
FFmpeg streaming stuck few minutes after start [closed]
19 février, par josue ramirezSorry for my english! :D
I'm trying to make a live video stream from my webcam with ffmpeg using Node.
I get the images or frames from ffmpeg via pipe1 on the stdout event and send them via a socket-io client to my angular app to play the stream.
So far the stream starts fine and my angular app can play it fine, but after a certain time (8 minutes or so) ffmpeg stops sending data and the stream in my angular app stops and if I want to start the webcam again it's not possible anymore because it's apparently occupied by another process. I've been trying to figure out what's going on and what I've noticed is that the ffmpeg process just stops and the process is no longer visible with the
top
command (ubuntu), but the child process in node still shows a ffmpeg process as if it were a zombie process.I've tried running ffmpeg from the terminal to save an mp4 file with the stream and in that case there is no problem, the recording doesn't stop even using pipe1. Only when I run ffmpeg from my Node app, the error occurs.
Does anyone have any idea what could be going on?
This command is the one that is executed to send the data through pipe1 both from node and from the terminal but it only stops in Node
ffmpeg -f v4l2 -input_format mjpeg -video_size 800x600 -i /dev/video0 -q:v 4 -f image2pipe pipe1
The same thing happens when saving an mp4 video only in Node it fails
ffmpeg -f v4l2 -input_format mjpeg -video_size 800x600 -i /dev/video0 -q:v 4 video.mp4
This is my function that starts the streaming
export const startCamera = () => { logger.info('Starting camera ', cameraName); const inputFormat = process.platform === 'win32' ? 'dshow' : 'v4l2'; const ffmpegArgs = [ '-f', inputFormat, // Formato de entrada según la plataforma ]; if (process.platform === 'linux') { ffmpegArgs.push( '-input_format', 'mjpeg', // Especificar el formato antes de video_size '-video_size', '800x600', // Tamaño de la imagen ); } ffmpegArgs.push( '-i', cameraName, // Dispositivo de entrada '-vf', 'fps=15', // Fotogramas por segundo '-q:v', '10', // Calidad de video '-f', 'image2pipe', // Formato de salida 'pipe:1' // Salida por stdout ); try { logger.info('FFmpeg command: ffmpeg', ffmpegArgs.join(' ')); ffmpeg = spawn('ffmpeg', ffmpegArgs); let cameraOpen = false; // Enviar los datos del fotograma a través del WebSocket ffmpeg.stdout.on('data', (chunk) => { logger.debug(`Sending chunk of ${chunk.length} bytes`); if (!cameraOpen) { cameraOpen = true; serialConnection.connect(); logger.info('Camera started!!'); } if (streamWS.isActive()) { streamWS.send(chunk); } }); // Manejo de errores ffmpeg.stderr.on('error', (data) => { logger.error('FFmpeg Error:', data.toString()); }); ffmpeg.on('close', async () => { logger.info('Camera closed....', cameraName); if (!cameraOpen) { await commandWS.send( { command: COMMANDS.START_STREAM, isError: true, response: `Error al intentar iniciar la camara ${cameraName}, verificar que la camara se encuentre bien conectada.`, }, COMMANDS_EVENTS.ROBOT_RESPONSE ); } cameraOpen = false; await serialConnection.close(); stopCamera(); await streamWS.disconnectWS(); }); } catch (e) { logger.error('Error tryng to start the camera...', e); } };
-
How to watermark with overlay fadeout with ffmpeg [closed]
19 février, par Kevin WatersonI wish to put a watermark on my video, and a text overlay. The text overlay should fade out after the first three seconds. The watermark is permanent.
This is what I have come up with, however, the watermark seems to push the overlay down.
ffmpeg -y -i in.mp4 -i images/watermark.png -filter_complex "[0:v][1:v]overlay=10:10[bg];[bg]drawtext=fontfile=fonts/SAMAN___.ttf:text='Testing':box=1:boxborderw=800|800:boxcolor=black:fontsize=40:fontcolor=white:alpha='if(lt(t,2),0,if(lt(t,3),(t-2)/1,if(lt(t,6),1,if(lt(t,7),(1-(t-6))/1,0))))':x=(w-text_w)/2:y=(h-text_h)/2:y=h-th-10[out]" -map "[out]" -map 0:a out.mp4