hedgewars/avwrapper/avwrapper.c
changeset 11351 82784d932577
parent 11350 846aa36f7cdc
child 11352 ce154ffb9a8b
equal deleted inserted replaced
11350:846aa36f7cdc 11351:82784d932577
    64 #endif
    64 #endif
    65 
    65 
    66 #if LIBAVCODEC_VERSION_MAJOR < 56
    66 #if LIBAVCODEC_VERSION_MAJOR < 56
    67 #define av_frame_alloc                      avcodec_alloc_frame
    67 #define av_frame_alloc                      avcodec_alloc_frame
    68 #define av_frame_free                       av_freep
    68 #define av_frame_free                       av_freep
       
    69 #define av_packet_rescale_ts                rescale_ts
       
    70 
       
    71 static void rescale_ts(AVPacket *pkt, AVRational ctb, AVRational stb)
       
    72 {
       
    73     if (pkt->pts != AV_NOPTS_VALUE)
       
    74         pkt->pts = av_rescale_q(pkt->pts, ctb, stb);
       
    75     if (pkt->dts != AV_NOPTS_VALUE)
       
    76         pkt->dts = av_rescale_q(pkt->dts, ctb, stb);
       
    77     if (pkt->duration > 0)
       
    78         pkt->duration = av_rescale_q(pkt->duration, ctb, stb);
       
    79 }
    69 #endif
    80 #endif
    70 
    81 
    71 #if LIBAVCODEC_VERSION_MAJOR < 57
    82 #if LIBAVCODEC_VERSION_MAJOR < 57
    72 #define AV_CODEC_CAP_DELAY                  CODEC_CAP_DELAY
    83 #define AV_CODEC_CAP_DELAY                  CODEC_CAP_DELAY
    73 #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE    CODEC_CAP_VARIABLE_FRAME_SIZE
    84 #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE    CODEC_CAP_VARIABLE_FRAME_SIZE
   214     int got_packet;
   225     int got_packet;
   215     if (avcodec_encode_audio2(g_pAudio, &Packet, pFrame, &got_packet) != 0)
   226     if (avcodec_encode_audio2(g_pAudio, &Packet, pFrame, &got_packet) != 0)
   216         return FatalError("avcodec_encode_audio2 failed");
   227         return FatalError("avcodec_encode_audio2 failed");
   217     if (!got_packet)
   228     if (!got_packet)
   218         return 0;
   229         return 0;
       
   230 
       
   231     av_packet_rescale_ts(&Packet, g_pAudio->time_base, g_pAStream->time_base);
   219 #else
   232 #else
   220     if (NumSamples == 0)
   233     if (NumSamples == 0)
   221         return 0;
   234         return 0;
   222     int BufferSize = OUTBUFFER_SIZE;
   235     int BufferSize = OUTBUFFER_SIZE;
   223     if (g_pAudio->frame_size == 0)
   236     if (g_pAudio->frame_size == 0)
   372         if (avcodec_encode_video2(g_pVideo, &Packet, pFrame, &got_packet) < 0)
   385         if (avcodec_encode_video2(g_pVideo, &Packet, pFrame, &got_packet) < 0)
   373             return FatalError("avcodec_encode_video2 failed");
   386             return FatalError("avcodec_encode_video2 failed");
   374         if (!got_packet)
   387         if (!got_packet)
   375             return 0;
   388             return 0;
   376 
   389 
   377         if (Packet.pts != AV_NOPTS_VALUE)
   390         av_packet_rescale_ts(&Packet, g_pVideo->time_base, g_pVStream->time_base);
   378             Packet.pts = av_rescale_q(Packet.pts, g_pVideo->time_base, g_pVStream->time_base);
       
   379         if (Packet.dts != AV_NOPTS_VALUE)
       
   380             Packet.dts = av_rescale_q(Packet.dts, g_pVideo->time_base, g_pVStream->time_base);
       
   381 #else
   391 #else
   382         Packet.size = avcodec_encode_video(g_pVideo, g_OutBuffer, OUTBUFFER_SIZE, pFrame);
   392         Packet.size = avcodec_encode_video(g_pVideo, g_OutBuffer, OUTBUFFER_SIZE, pFrame);
   383         if (Packet.size < 0)
   393         if (Packet.size < 0)
   384             return FatalError("avcodec_encode_video failed");
   394             return FatalError("avcodec_encode_video failed");
   385         if (Packet.size == 0)
   395         if (Packet.size == 0)