Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Kinda related, here's a few ffmpeg commands i've probably spent many hours getting to work just right recently (and they might not even the right way to do these things), perhaps someone will find it helpful. All of these are on a macbook.

- play facetime camera (or any avfoundation camera, like a capture card) to mpv

  ffmpeg -f avfoundation -video_size 1920x1080  -framerate 30 -drop_late_frames true -i "FaceTime HD Camera" -c:v rawvideo -f matroska -r 30 - | mpv -profile=low-latency -untimed -
- play raw video stream from the usb camlink capture card

  ffmpeg -f avfoundation -video_size 3840x2160 -framerate 23.98 -pixel_format uyvy422 -drop_late_frames true  -i "Cam Link 4K" -c:v rawvideo -f matroska - | mpv -profile=low-latency -untimed -
- Capture video, and do live HVEC hardware encoding on apple hardware and save result. Control quality with q variable. q=85 is around 250Mb/s:

  ffmpeg -f avfoundation -video_size 3840x2160 -framerate 23.98 -i "Cam Link 4K" -c:v hevc_videotoolbox -q:v 85 -r 23.98 -tag:v hvc1 <filename>_x265.mp4
- Use named pipe with mkfifo to play a stream. Sometimes this produces less input lag than other methods.

  mkfifo /tmp/fifo1
  cat /tmp/fifo1 | mpv -profile=low-latency -untimed -
  ffmpeg -f avfoundation -video_size 1920x1080  -framerate 30 -drop_late_frames true -i "FaceTime HD Camera" -c:v rawvideo -f matroska -r 30 - > /tmp/fifo1


Riffing off those, here's a ffmpeg/mpv command to run an audio frequency spectrum visualizer on a live microphone (or a virtual loopback one):

   ffmpeg -f avfoundation -i ":0" -flush_packets 1 -flags low_delay -muxdelay 0.01 -fflags nobuffer -f wav -c copy - | mpv - --profile=low-latency -untimed --lavfi-complex="[aid1]showcqt=fps=30:s=1280x720:count=5:axis=1:axis_h=6:bar_h=100:timeclamp=0.13[vo]" 
Specifically it's using ffmpeg's showcqt[0] filter, which I find to be by far ffmpeg's most beautiful/comprehensible frequency visualizer. In my example `-i ":0"` refers to my microphone at index "0". To find your system's microphone index you can run `ffmpeg -f avfoundation -list_devices true -i ""`.

here's a screenshot: https://dl.dropboxusercontent.com/s/yx5rlgpsmai3kej/showcqt_...

[0] https://ffmpeg.org/ffmpeg-filters.html#showcqt


Nice, thanks, just tried it, that's quite cool, saving it for later! Any reason you are running the filters within the `mpv` command vs within the `ffmpeg` command? I honestly have no idea which way is "better" if any, I think underneath both actually use `libavfilter` library?


They’re both the same really! Though I prefer doing the visualizing in mpv because than it’s easier to switch to different visualizations at runtime. With my mpv config I have obscure keyboard shortcuts that'll switch between different ones. But also possible to do it without mpv entirely.


And in windows batch. record your face with hardcoded timestamp for working on customer systems.

@echo on

setlocal

set ID=IDIDID

set VIDFILENAME=%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%

echo "-segment_atclocktime 1 "

ffmpeg -loglevel error -rtbufsize 150M -y -f dshow -i video="YOUR HD Camera" -r 10 -f segment -segment_time 1800 -segment_format mp4 -vcodec libx264 -preset fast -threads 1 -crf 28 -tune zerolatency -thread_type slice -slices 1 -intra-refresh 1 -r 10 -g 60 -s 640x480 -aspect 4:3 -b:v 512k -minrate:v 256k -maxrate:v 2.5M -bufsize:v 5M -pix_fmt yuv420p -vf "drawtext=fontfile=/Windows/Fonts/arial.ttf:text='%%{localtime\:%%x %%X}': fontcolor=white@0.8: x=7: y=10" %ID%_%VIDFILENAME%-%%03d.mp4


Please stop using batch files grandpa. PowerShell has been around for 15 years now.


Even ignoring the fact that batch files still have their place in a world where PowerShell exists, that is a needlessly inflammatory reply to someone who shared their knowledge with everyone.


Tell that to the domain admin that keeps overwriting my work laptops registry to not allow powershell scripts to execute..


The first two might be possible with just MPV. Relevant thread on /r/GenkiLab: https://www.reddit.com/r/GenkiLab/comments/mzw9a2/lower_late...


I think I vaguely remembering trying it and eventually gave up as it wasn't working. I believe I arrived at this bug report which still seems open - https://github.com/mpv-player/mpv/issues/8818

Overall I just found it better to leave pretty much everything to the more battle-tested `ffmpeg` and then use mpv to play the content (or can also use ffplay, but I do have have some customizations in mpv which I like).


I wish their was a website were people uploaded their ffmpeg commands and people rated them.

So many bad ffmpeg commands, it's hard to filter them by quality



> - Capture video, and do live HVEC hardware encoding on apple hardware and save result.

Here's what I use to GPU encode/decode multiple IP camera feeds using motion on a 15W haswell system with enough CPU left free for other tasks.

  #motion.conf
  movie_extpipe_use on
  movie_extpipe ffmpeg -y -f rawvideo -pix_fmt yuv420p -video_size %wx%h -framerate %fps -vaapi_device /dev/dri/renderD128 -i pipe:0 -vf 'format=nv12,hwupload' -c:v h264_vaapi %f.mp4
  netcam_params decoder=vaapi,rtsp_transport=tcp,keepalive=off,tolerant_check=on


> q=85 is around 250Mb/s

Is that really true!? 1.8 GB per minute?


Yeah. h265 encoding is quite expensive so to be doing it live there is a tradeoff with speed/size. If you take a look at most cameras (I have Fujifilm XT4), if you're recording at 4k resolution with h265 at 60fps, you're looking at 400Mb/s. Which is still not much compared to something like say ProRes422 (~100MB/s) And nothing compared to raw uncompressed video (recorduing the literal raw video bytes coming uncompressed via HDMI cable) where you can get to something like 1GB/s even (https://www.gammaraydigital.com/blog/just-how-big-are-those-...). In fact in my above commands if you just keep the `rawvideo` format without passing any encoder and try to save to a file, you'll see how large these files can get!

Ever since I started playing with video recording I ended up getting a NAS with 10Gb/s ethernet card, definitely helps!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: