ffmpeg命令行实现h264转yuv、bmp和jpeg

参数介绍

Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…

Getting help:
-h – print basic options
-h long – print more options
-h full – print all options (including all format and codec specific options, very long)
-h type=name – print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol
See man ffmpeg for detailed description of the options.

Print help / information / capabilities:
-L show license
-h topic show help
-? topic show help
-help topic show help
–help topic show help
-version show version
-buildconf show build configuration
-formats show available formats
-muxers show available muxers
-demuxers show available demuxers
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
-hwaccels show available HW acceleration methods

Global options (affect whole program instead of just one file):
-loglevel loglevel set logging level
-v loglevel set logging level
-report generate a report
-max_alloc bytes set maximum size of a single allocated block
-y overwrite output files
-n never overwrite output files
-ignore_unknown Ignore unknown stream types
-filter_threads number of non-complex filter threads
-filter_complex_threads number of threads for -filter_complex
-stats print progress report during encoding
-max_error_rate maximum error rate ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.
-bits_per_raw_sample number set the number of bits per raw sample
-vol volume change audio volume (256=normal)

Per-file main options:
-f fmt force format
-c codec codec name
-codec codec codec name
-pre preset preset name
-map_metadata outfile[,metadata]:infile[,metadata] set metadata information of outfile from infile
-t duration record or transcode “duration” seconds of audio/video
-to time_stop record or transcode stop time
-fs limit_size set the limit file size in bytes
-ss time_off set the start time offset
-sseof time_off set the start time offset relative to EOF
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time set the recording timestamp (‘now’ to set the current time)
-metadata string=string add metadata
-program title=string:st=number… add program with specified streams
-target type specify target file type (“vcd”, “svcd”, “dvd”, “dv” or “dv50” with optional prefixes “pal-”, “ntsc-” or “film-”)
-apad audio pad
-frames number set the number of frames to output
-filter filter_graph set stream filtergraph
-filter_script filename read stream filtergraph description from a file
-reinit_filter reinit filtergraph on input parameter changes
-discard discard
-disposition disposition

Video options:
-vframes number set the number of video frames to output
-r rate set frame rate (Hz value, fraction or abbreviation)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number set the number of bits per raw sample
-vn disable video
-vcodec codec force video codec (‘copy’ to copy stream)
-timecode hh:mm:ss[:;.]ff set initial TimeCode value.
-pass n select the pass number (1 to 3)
-vf filter_graph set video filters
-ab bitrate audio bitrate (please use -b:a)
-b bitrate video bitrate (please use -b:v)
-dn disable data

Audio options:
-aframes number set the number of audio frames to output
-aq quality set audio quality (codec-specific)
-ar rate set audio sampling rate (in Hz)
-ac channels set number of audio channels
-an disable audio
-acodec codec force audio codec (‘copy’ to copy stream)
-vol volume change audio volume (256=normal)
-af filter_graph set audio filters

Subtitle options:
-s size set frame size (WxH or abbreviation)
-sn disable subtitle
-scodec codec force subtitle codec (‘copy’ to copy stream)
-stag fourcc/tag force subtitle tag/fourcc
-fix_sub_duration fix subtitles duration
-canvas_size size set canvas size (WxH or abbreviation)
-spre preset set the subtitle options to the indicated preset

h264转yuv

ffmpeg -i 参数1 -y -an -frams 1 -s 参数2 参数3 
  1. 参数1:-i 后代表输入文件路径,即要转换的h264文件,比如111.h264。
  2. 参数2:-s 后代表要输出的分辨率大小,比如1024x600。
  3. 参数3:代表输出文件名,比如111.yuv。
  4. -y 代表输出文件存在的话,会覆盖原有的。
  5. -an 代表禁用音频。
  6. -frame 1 代表取一帧画面,当然可以用-ss -t 和 -to 来指定时间段

注意,如果C代码中想用system或者popen函数来执行这个命令,会出现打印出ffmpeg信息后就卡住死机的情况,所以C代码要调用ffmpeg命令,要加入“nohup”,需要按如下改写:

system("nohup ffmpeg -i 参数1 -y -an -frams 1 -s 参数2 参数3 >/dev/null 2>&1")

后面重定向到/dev/null是为了不让命令信息输出到控制台,可加也可不加。

h264转bmp和jpeg

ffmpeg -i 参数1 -y -f image2 -t 0.001 -s 参数2 参数3 >/dev/null 2>&1
  1. 参数1:-i 后代表输入文件路径,即要转换的h264文件,比如111.h264。
  2. 参数2:-s 后代表要输出的分辨率大小,比如1024x600。
  3. 参数3:代表输出文件名,比如111.bmp或者111.jpeg。
  4. -y 代表输出文件存在的话,会覆盖原有的。
  5. -f image2 代表输出格式为image2。
  6. -t 0.001 时长0.001秒

No pains, no gains.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值