ffmpeg常用操作

1. yuv图转为png图

ffmpeg -s 1920x1080 -i decode_249.yuv decode_249.png

2. 查看yuv格式图

ffplay -pixel_format yuv420p -video_size 1920x1080 decode_249.yuv

3. 拉取rtsp流并保存为MP4文件

ffmpeg -rtsp_transport tcp -i rtsp://81.68.73.201/test -y test.mp4

-rtsp_transport tcp表示使用tcp协议拉流,不会丢包
-y 表示overwrite输出文件

代码打开rtsp流的操作如下:

  const char *src_filename = "rtsp://81.68.73.201/test"     

  AVDictionary *avdic = NULL;
  char trans_key[] = "rtsp_transport";
  char trans_value[] = "tcp";
  av_dict_set(&avdic, trans_key, trans_value, 0);
  char delay_key[] = "max_delay";
  char delay_value[] = "5000000";
  av_dict_set(&avdic, delay_key, delay_value, 0);

  /* open input file, and allocate format context */
  if (avformat_open_input(&fmt_ctx, src_filename, NULL, &avdic) < 0) {
      fprintf(stderr, "Could not open source file %s\n", src_filename);
      exit(1);
  }

将MP4全部解码为png图片

ffmpeg -i test.mp4 camera_%d.png  # %d为连续增长的1、2、3
posted @ 2020-12-31 11:51  Cristiano-Duan  阅读(155)  评论(0编辑  收藏  举报