Audio and video notes: ffmpeg commonly used command lines

Mainly used to record commonly used command lines.


ffmpeg command line usage

View a list of audio and video equipment:

  • win: ffmpeg -f dshow -list_devices true -i dummpy
[dshow @ 000002266c527fc0] "Microsoft® LifeCam Studio(TM)" (video)
[dshow @ 000002266c527fc0]   Alternative name "@device_pnp_\\?\usb#vid_045e&pid...
[dshow @ 000002266c527fc0] "PRISM Live Studio" (video)
[dshow @ 000002266c527fc0]   Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{A49F51EE-8841-4425-BEC0-85D0C470BBDE}"
[dshow @ 000002266c527fc0] "桌面麦克风 (Microsoft® LifeCam Studio(TM))" (audio)
[dshow @ 000002266c527fc0]   Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{85A88CC0-ADB6-4E97-BB5D-AD3AAB334541}"
[dshow @ 000002266c527fc0] "FrontMic (Realtek(R) Audio)" (audio)
[dshow @ 000002266c527fc0]   Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{7A5C2EBB-2C09-402A-B380-D250BFF4588E}"
  • mac: ffmpeg -f avfoundation -list_devices true -i dummpy
[AVFoundation indev @ 0x7f82ce905040] AVFoundation video devices:
[AVFoundation indev @ 0x7f82ce905040] [0] FaceTime HD Camera
[AVFoundation indev @ 0x7f82ce905040] [1] Capture screen 0
[AVFoundation indev @ 0x7f82ce905040] [2] Capture screen 1
[AVFoundation indev @ 0x7f82ce905040] AVFoundation audio devices:
[AVFoundation indev @ 0x7f82ce905040] [0] Built-in Microphone
[AVFoundation indev @ 0x7f82ce905040] [1] PRISM Live Studio

View the specific support parameters supported by the Dshow/Avfoundation library:

  • MAC: ffmpeg -h demuxer=avfoundation
    Check the specific commands supported by avfoundation. For example, avfoundation does not support the dshow command list_options
Demuxer avfoundation [AVFoundation input device]:
AVFoundation indev AVOptions:
  -list_devices      <boolean>    .D......... list available devices (default false)
  -video_device_index <int>        .D......... select video device by index for devices with same name ...
  -audio_device_index <int>        .D......... select audio device by index for devices with same name ...
  -pixel_format      <pix_fmt>    .D......... set pixel format (default yuv420p)
  -framerate         <video_rate> .D......... set frame rate (default "ntsc")
  -video_size        <image_size> .D......... set video size
  -capture_cursor    <boolean>    .D......... capture the screen cursor (default false)
  ......
  • WIN : ffmpeg -h demuxer=dshow
Demuxer dshow [DirectShow capture]:
dshow indev AVOptions:
  -video_size        <image_size> .D......... set video size given a...
  -pixel_format      <pix_fmt>    .D......... set video pixel format (default none)
  -framerate         <string>     .D......... set video frame rate
  -sample_rate       <int>        .D......... set audio sample rate ...
  -sample_size       <int>        .D......... set audio sample size (from 0 to 16) (default 0)
  -channels          <int>        .D......... set number of audio channels, ...
  -audio_buffer_size <int>        .D......... set audio device buffer latency size in ...
  -list_devices      <boolean>    .D......... list available devices (default false)
  -list_options      <boolean>    .D......... list available options for specified device...
  ......

View a list of supported resolutions or sampling formats for a specific device:

  • WIN Video: ffmpeg -f dshow -list_options true -i video="Microsoft® LifeCam Studio(TM)"
[dshow @ 0000026dba738040] DirectShow video device options (from video devices)
[dshow @ 0000026dba738040]  Pin "捕获" (alternative pin name "捕获")
[dshow @ 0000026dba738040]   pixel_format=yuyv422  min s=640x480 fps=7.5 max s=640x480 fps=30
[dshow @ 0000026dba738040]   pixel_format=yuyv422  min s=960x544 fps=7.5 max s=960x544 fps=20
[dshow @ 0000026dba738040]   pixel_format=yuyv422  min s=800x448 fps=7.5 max s=800x448 fps=30
  ......等
  • WIN Aduio: ffmpeg -f dshow -list_options true -i audio="桌面麦克风 (Microsoft® LifeCam Studio(TM))"
[dshow @ 0000019c5c2b8040] DirectShow audio only device options (from audio devices)
[dshow @ 0000019c5c2b8040]  Pin "Capture" (alternative pin name "Capture")
[dshow @ 0000019c5c2b8040]   ch= 2, bits=16, rate= 44100 
[dshow @ 0000019c5c2b8040]   ch= 1, bits=16, rate= 44100
[dshow @ 0000019c5c2b8040]   ch= 2, bits=16, rate= 32000
[dshow @ 0000019c5c2b8040]   ch= 1, bits=16, rate= 32000
[dshow @ 0000019c5c2b8040]   ch= 2, bits=16, rate= 22050
  ......等

recording:

Preface description: -i v:a The colon is preceded by the video number, followed by the audio number, if only the camera collects it The colon can be omitted

Default parameter version:

-mac: ffmpeg -f avfoundation -i :0 out.wav

-win: ffmpeg -f dshow -i audio="麦克风 (Razer Seiren)" out.wav

Number version:
-win: ffmpeg -f dshow -sample_rate 44100 -sample_size 16 -channels 2 -i audio="麦克风 (Razer Seiren)" out.wav

Play pcm:

ffplay -ar 44100 -ac 2 -f s16le out.pcmpcm must take necessary incoming parameters

video:

Basic configuration options:-video_size -pixel_format framerate

Screen recording:

If -video_size -pixel_format framerate is not written, it will be successful, but the default value will be set. To check the specific parameters supported by the device, please refer to the abovelist_options.

  • WIN: ffmpeg -f dshow -video_size 1920x1080 -pixel_format yuyv422 -i video="Microsoft® LifeCam Studio(TM)" out1.yuv
  • mac: ffmpeg -f avfoundation -framerate 30 -i 0: out.yuv, 0: can be omitted to 0.
    mac cannot view the specific parameters supported by the device. When the previous command reports an error, the specific supported data will be listed. For example, ifframerate is not set, an error will be reported,

play yuv

ffplay -pixel_format yuyv422 -video_size 1920x1080 out1.yuv

Convert format format

  • ffmpeg -i 640x480.jpg -pix_fmt yuv420p out_yuv420p.yuv General yuvj420p 转换成 yuv420p Success.
  • ffmpeg -i 640x480.jpg -pixel_format yuv420p out_yuv420p.yuv Format conversion failed. After using -pixel_format, the converted format is still yuvj420p.

video encoding

  • ffmpeg -pix_fmt yuv420p -video_size 640x480 -i movie_640x480_yuv420p.yuv -c:v libx264 -r 30 ffmpge_640x480_yuv420p.h264 Encode yuv into h264
    -r 30 represents output 30fps

Audio and video decapsulation

  • mp4 -> h264: ffmpeg -i test.mp4 -c:v copy -an output.h264, discard the audio stream and save only the video stream
  • mp4 -> aac: ffmpeg -i test.mp4 -c:a copy -vn output.aac, discard the video stream and save only the audio stream
  • h264 -> yuv: ffmpeg -c:v h264 -i output.h264 out.yuv, h264 solved yuv
  • aac -> pcm: ffmpeg -c:a aac -i output.aac out.pcm, aac solved pcm

basic knowledge

it has size

  • linesize represents in linear PCM, the total size of multiple channels = nChannels * bit depth (AVSampleFormat) >> 3
  • In planner, represents the size of a mono data = bit depth >> 3

sample frame

  • Represents a large sample (samples containing multiple channels)
  • Each channel represents a small sample

Guess you like

Origin blog.csdn.net/goldWave01/article/details/125085434