Skip to content

Instantly share code, notes, and snippets.

@prabindh
Created June 3, 2021 11:10
Show Gist options
  • Select an option

  • Save prabindh/c8048ac0f4cd6d48e9b682523e5b3c1f to your computer and use it in GitHub Desktop.

Select an option

Save prabindh/c8048ac0f4cd6d48e9b682523e5b3c1f to your computer and use it in GitHub Desktop.

Revisions

  1. prabindh created this gist Jun 3, 2021.
    73 changes: 73 additions & 0 deletions ffmpeg.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    #Creating SBS (side by side) videos:

    ffmpeg -i input_file -i input_file2 -filter_complex hstack -vcodec libx264 -b:v 30M -vsync 0 output.mp4

    #MP4 from raw YUV

    ffmpeg -f rawvideo -vcodec rawvideo -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v libx264 -preset slow -qp 0 -vsync 0 -pix_fmt nv12 output.mp4

    #Scaling:

    ffmpeg -i input -filter:v scale=1280:-1 -sws_flags lanczos output
    ffmpeg -i input.mp4 -vf "scale=iw/2:ih/2" -preset slow -crf 18 output.mp4
    ffmpeg -i input.mp4 -vf scale=1920:-1 -preset slow -crf 18 -vsync 0 out.mp4

    #VP8 frames in IVF format to image file

    ffmpeg -vcodec libvpx -i frames.ivf vp8decode.jpg

    #Extract frames from video

    (-start_number 0) to start filenames from index 0
    ffmpeg.exe -i input.mp4 "<path>\%10d.png"

    #Extract subrect video:

    ffmpeg.exe -i in.mp4 -filter:v "crop=448:448:0:0" out_left_top.mp4

    #Extract subrect to png:

    ffmpeg.exe -i in.mp4 -filter:v "crop=448:448:0:0" -f image2 image-%03d.png

    #Extract raw h264 (playable via vlc) from mp4:

    ffmpeg -i "input.mp4" -vcodec copy -an -bsf:v h264_mp4toannexb test.h264

    #Stream rtsp from testsrc:

    ffmpeg -f lavfi -i testsrc -c:v libx264 -preset medium -vb 2000k -c:a aac -ab 128k -ar 44100 -bf 0 -f rtsp rtsp://ipaddr:8080/live/ffmpeg

    #Stream from file to tcp at ip:port

    ffmpeg -re -i output.mp4 -an -vcodec copy -f mpegts tcp://<ipaddr>:<port>
    ffmpeg -re -i output.mp4 -vn -acodec copy -f mpegts tcp://<ipaddr>:<port>
    Add "-stream_loop" to repeat

    #Stream desktop to tcp at ip:port :

    ffmpeg -y -rtbufsize 2000M -f gdigrab -framerate 30 -offset_x 0 -offset_y 0 -i desktop -c:v h264_nvenc -preset:v fast -vf scale=1920:1080 -f mpegts tcp://ip:port

    #Capture desktop (windows):

    ffmpeg -y -f gdigrab -i desktop -frames:v 1 screenshot.png

    #Capture RTSP to .ts file:

    ffmpeg -i rtsp://ip:port/some.amp -c copy -f mpegts out.ts

    #Concatenate many files to single mp4:

    Add file list to filelist.txt
    ffmpeg -f concat -i filelist.txt -c copy outputbig.mp4

    #Overlays: 2 streams, overlay
    ffmpeg -y -i c:\outfile.mp4 -i c:\another.mp4 -i overlay.png -filter_complex "[0:v][0:a][1:v][1:a] concat=n=2:v=1:a=1 [outv] [outa]; [outv][2:v] overlay=main_w-overlay_w-10:10 [overlaid]" -map "[overlaid]" -map "[outa]" -g 60 -qp 0 -b:v 24M -vcodec h264_nvenc out.mp4

    #VMAF comparison:

    ffmpeg -i compare_input -i reference_input -lavfi "libvmaf=model_path='C\:/Users/fff/vmaf_float_v0.6.1.json':log_path='./vmaf.log':log_fmt=json:psnr=1:ssim=1:ms_ssim=1" -f null -

    #C++ API for interoperation of CUDA+OpenGL+FFMPEG API

    https://github.com/prabindh/cudammf