day11_homework_need2submit

发布于:2024-07-06 ⋅ 阅读:(49) ⋅ 点赞:(0)

Homework

编写—个将ts或mp4中视频文件解码到yuv的程序
yuv数据可以使用如下命令播放:
ffplay -i output yuv-pix_fmt yuv420p-s 1024x436
要求:

  1. ffmpeg解析到avpacket并打印出pts和dts字段
  2. 完成解码到avframe并打印任意字段
  3. 完成yuv数据保存
// teminal orders on bash
cd examples     
gcc -o demuxing_decoding demuxing_decoding.c $(pkg-config --cflags --libs libavformat libavcodec libavutil libswscale)

export PKG_CONFIG_PATH=/home/ubuntu2204/workspace/ffmpeg/build/lib/pkgconfig:$PKG_CONFIG_PATH     
//solve not find head file

./demuxing_decoding ubuntu22.04.mp4 a.yuv a.avi 

/* read frames from the file */
    // while (av_read_frame(fmt_ctx, pkt) >= 0) {
    //     // check if the packet belongs to a stream we are interested in, otherwise
    //     // skip it
    //     if (pkt->stream_index == video_stream_idx)
    //         ret = decode_packet(video_dec_ctx, pkt);
    //     else if (pkt->stream_index == audio_stream_idx)
    //         ret = decode_packet(audio_dec_ctx, pkt);
    //     av_packet_unref(pkt);
    //     if (ret < 0)
    //         break;
    // }
    while (av_read_frame(fmt_ctx, pkt) >= 0) {
    // 打印PTS和DTS信息
    if (pkt->stream_index == video_stream_idx || pkt->stream_index == audio_stream_idx) {
        AVRational *time_base = &fmt_ctx->streams[pkt->stream_index]->time_base;
        printf("PTS: %s, DTS: %s, duration: %d, stream index: %d\n",
               av_ts2timestr(pkt->pts, time_base),
               av_ts2timestr(pkt->dts, time_base),
               pkt->duration,
               pkt->stream_index);
    }

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到