Short version:
- files are corrupted because you are interrupting to finish the
mp4 encode, switch to something like mkv instead.
- 'uncorrupt' by format shifting to another container
ffmpeg -i corrupt.mp4 -c copy not_corrupt.mkv
- don't use
vfwcap as it is out of date
Why am I having problems capturing from my USB webcam with ffmpeg?
From the ffmpeg docs on vfwcap:
Note Well this is out of date, these days you can use the -f dshow device to capture from a directshow device.
Since it is out of date, use -f dshow instead. From the DirectShow documentation:
FFmpeg can take input from "directshow" devices on your Windows computer. See the FFmpeg dshow input device documentation for official documentation. It can accept input from audio, video devices, video capture devices, analog tv tuner devices.
From the linked dshow documentation, you should first find out what the device is under dshow:
ffmpeg.exe -list_devices true -f dshow -i dummy
Example output:
[dshow @ 0000000002e9bb20] DirectShow video devices (some may be both video and audio devices)
[dshow @ 0000000002e9bb20] "PC Camera"
[dshow @ 0000000002e9bb20] Alternative name "@device_pnp_\\?\usb#vid_058f&pid_3880&mi_00#6&218cd81a&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
using the "PC Camera" found by the previous command:
ffmpeg -f dshow -i video="PC Camera" -y output.mkv
(I would back off on using -rtbufsize initially, as there are some caveats noted for using it with dshow devices`)
I would suggest using mkv over mp4 as my guess is you are not doing a fixed-time encode but instead terminating ffmpeg with Ctrl-C; this prevents ffmpeg from writing certain atoms to the video container and likely why the file is corrupted1. mkv can be interrupted at will2.
1: You could test this by format-shifting the corrupted mp4s:
ffmpeg -i corrupt.mp4 -c copy not_corrupt.mkv. If that doesn't work, another answer on SU by sparrowt recommends untrunc
2: Tested using ffmpeg version N-72939-g5b0f55a on Windows, and a random cheap webcam I happened to have lying around