0

By following ffmpeg examples i realised they don't provide an example that decodes h.264 and save it to desktop in any way. I can decode h.264 but i cannot save it to desktop. How can i do this?

I can get this point but now how can i save it as a video?

while (1) {
    if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
        break;
    if (packet.stream_index == video_stream_index) {
        got_frame = 0;
        ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, &packet);
        if (ret < 0) {
            av_log(NULL, AV_LOG_ERROR, "Error decoding video\n");
            break;
        }
        if (got_frame) {
            frame->pts = av_frame_get_best_effort_timestamp(frame);
               .
               .
               .
               .
               .
               .        
               .
               }
                av_frame_unref(frame);
            }
        }
        av_packet_unref(&packet);
    }
greentree
  • 45
  • 7
  • Decode it to what? Another video format? –  Aug 21 '16 at 23:45
  • *"how can i save it as a video?"* What type of video? Another H.264 stream? Or VP9? Or FFV1? Or raw video? Or something else? In what container? MKV? MP4? Or something else? Video is complicated, and unless you know your target codec(s) and container(s), I suggest you just use the `ffmpeg` command line program (and perhaps just write a wrapper that builds up and executes the necessary commands). – Cornstalks Aug 22 '16 at 01:53
  • Output type of the video doesn't matter as long as i can play it on vlc. I have other intermediate steps later on i will encode it back to h.264 mp4 again. I have to use API not command line – greentree Aug 22 '16 at 08:30
  • 1
    After decode, you get the output in YUV format. If you are OK to save it in YUV format, just proceed and look at AVFrame structure ("frame" variable in your example) for buffer pointers and dimesions. – ARK Aug 22 '16 at 13:48
  • I am ok to save it in YUV format and it worked out. But now how do i encode YUV to back h.264 with API – greentree Aug 24 '16 at 10:38

0 Answers0