by ly3xqhl8g9 · 3y ago · 0 comments
ChatGPT: >>>
ffmpeg -f v4l2 -framerate 30 -video_size 640x480 -i /dev/video0 -c:v libx264 -preset veryfast -crf 28 -pix_fmt yuv420p output.mp4
Here's a brief explanation of what each part of the command does:
- `f v4l2`: specifies that the input device is a V4L2 (Video for Linux 2) device, which is typically what webcams use.
- `framerate 30`: sets the framerate to 30 frames per second.
- `video_size 640x480`: sets the video resolution to 640x480 pixels. You can adjust this to your desired resolution.
- `i /dev/video0``: specifies the input device to use, which is typically /dev/video0 for the first connected webcam. If you have multiple webcams, you may need to adjust this to the appropriate device.
- `c:v libx264``: sets the video codec to use, which is H.264 in this case.
- `preset veryfast``: sets the encoding speed preset to "veryfast", which is a good balance between speed and quality.
- `crf 28`: sets the video quality using the Constant Rate Factor (CRF) method, with a value of 28. Lower values mean higher quality and larger file sizes, while higher values mean lower quality and smaller file sizes. You can adjust this to your desired quality/file size.
- `pix_fmt yuv420p``: sets the pixel format to YUV 4:2:0, which is a commonly used format for H.264 video.
- `output.mp4`: specifies the output file name and format.
<<<Never used the `crf` or `pix_fmt` flags personally, but seems correct (the issue with ChatGPT).
pix_fmt: pixel format. 99% videos use this format, and it has best compatibility. FFMPEG will try to keep the original format when do transcoding, so in most of time you don't need to specify. However, in this very case, since the input is from a webcam, the chance it uses some weird format is high. And you don't want to keep that in your final result. So it's good to specify it out here.
My 2c: ChatGPT is great, but I recommend to read the comments it gives about each parameter, try to understand their purposes, and adjust accordingly if needed.
Also having a rough idea about how FFMPEG pipeline works (mainly the order of input, output and their associated switches in arguments) helps a lot.
Video process is a very complex thing and lots of time it relies on experience. Just be prepared sometimes your "typically works" command would break.
Let me translate: the AI might or might not be bullshitting, I have no way to know but I decide to believe in it. Why ?
Also, you disingenuously left out the parentheses from the quote: using a tool requires undertaking its downsides, if the downsides can be mitigated accordingly then the tool is useful. Millions of users put to good use imperfect tools daily.
You linked Wikipedia: I don't trust that either. If I want to actually know something I will follow the sources and then evaluate the trustworthiness of the sources. Indeed, most of the Scottish Wikipedia being written by an American teenager who didn't speak Scottish at all very strongly parallels ChatGPT.
In practice that means that most hardware decoders (not just iPhones, also other phones, TVs, older PC GPUs) won't be able to decode YUV 4:2:2 or YUV 4:4:4 videos.
It's kinda annoying, since YUV420 really messes up red text in screen captures for example.
You need this parameter to force ffmpeg to convert the color space if your input isn't YUV420P (it defaults to keeping the input pixel format to avoid quality loss).
Is there an detailed explanation why red is especially bad after chroma subsampling? Have been wondering about this for awhile.
I assume it's because red has low brightness/luminance (no idea if correct or not)?
-tag:v hvc1
for iphone/quicktime to recognize it.