[Libav-user] demuxing streams and mux them back to file

Wuerfel, Hannes Hannes.Wuerfel at student.hpi.uni-potsdam.de
Wed Nov 14 21:37:38 CET 2012


Hey Carl,

thank you for your hint! With that I was able to create a video stream, an audio stream and muxed them into a file.
But I guess I was too naive to think that I could decode the frames and encode them back to file as they come in without setting new presentation time stamps and so on.

The difference between the muxing.c example and my program is that I don't do something like this:

if (frame)
        frame->pts = 0;
    for (;;) {
        /* Compute current audio and video time. */
        if (audio_st)
            audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
        else
            audio_pts = 0.0;

        if (video_st)
            video_pts = (double)video_st->pts.val * video_st->time_base.num /
                        video_st->time_base.den;
        else
            video_pts = 0.0;

        if ((!audio_st || audio_pts >= STREAM_DURATION) &&
            (!video_st || video_pts >= STREAM_DURATION))
            break;

        /* write interleaved audio and video frames */
        if (!video_st || (video_st && audio_st && audio_pts < video_pts)) {
            write_audio_frame(oc, audio_st);
        } else {
            write_video_frame(oc, video_st);
            frame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base);
        }
    }

in pseudo code what i am doing (i don't use any buffer queues for frames or packages, I simply want write them back as they come):

while(getFrame)
  video?
    decodeVideo, encode the decoded avframe back to the destination file
  audio?
    decodeAudio, encode the decoded avframe back to the destination file

Should it work out of the box if I insert an .mp4 file with an h264 codec and an acc codec and write it back to an .mp4 file?
It does not for me:

[libx264 @ 0000000000e31e00] MB rate (36000000) > level limit (2073600)
[libx264 @ 0000000000e31e00] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0000000000e31e00] profile High, level 5.2
[libx264 @ 0000000000e31e00] 264 - core 128 r2216 198a7ea - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: caba
c=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11
 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=
0 weightp=2 keyint=12 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=12 rc=abr mbtree=1 bitrate=3091 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=
4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'outMuxed.mp4':
    Stream #0:0: Video: h264, yuv420p, 640x480, q=-1--1, 3091 kb/s, 90k tbn, 30k tbc
    Stream #0:1: Audio: aac, 48000 Hz, 1 channels, s16, 96 kb/s
Video processing started ...
[mp4 @ 0000000000ecd300] Encoder did not produce proper pts, making some up.
[libx264 @ 0000000000e31e00] specified frame type (3) at 12 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 13 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 14 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 15 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 16 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 17 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 18 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 19 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 20 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 21 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 22 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 23 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 24 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 25 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 26 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 27 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 28 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 29 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 42 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 43 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 44 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 45 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 46 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 47 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 48 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 49 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 50 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 51 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 52 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 53 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 54 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 55 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 56 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 57 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 58 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 59 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 72 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 73 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 74 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 75 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 76 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 77 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 78 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 79 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 80 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 81 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 82 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 83 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 84 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 85 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 86 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 87 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 88 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 89 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 102 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 103 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 104 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 105 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 106 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 107 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 108 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 109 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 110 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 111 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 112 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 113 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 114 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 115 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 116 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 117 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 118 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 119 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 132 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 133 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 134 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 135 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 136 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 137 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 138 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 139 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 140 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 141 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 142 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 143 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 144 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 145 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 146 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 147 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 148 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 149 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 162 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 163 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] non-strictly-monotonic PTS
[libx264 @ 0000000000e31e00] specified frame type (3) at 164 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 165 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 166 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 167 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 168 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 169 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 170 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 171 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 172 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 173 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 174 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 175 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 176 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 177 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 178 is not compatible with keyframe interval
[libx264 @ 0000000000e31e00] specified frame type (3) at 179 is not compatible with keyframe interval
[mp4 @ 0000000000ecd300] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 184000 >= 184000
Error while writing video frame


________________________________________
Von: libav-user-bounces at ffmpeg.org [libav-user-bounces at ffmpeg.org] im Auftrag von Carl Eugen Hoyos [cehoyos at ag.or.at]
Gesendet: Mittwoch, 14. November 2012 13:01
An: libav-user at ffmpeg.org
Betreff: Re: [Libav-user] demuxing streams and mux them back to file

Wuerfel, Hannes <Hannes.Wuerfel at ...> writes:

> I'm trying to write a simple program which decodes the
> video and audio frames and encodes and mux it back to a file.
> How can I generally accomplish that?

> Basically I took the demuxing.c example and wanted to mux
> the video and audio frames back together but I'm
> stucked for days on this.

Did you also look at / test the muxing.c example?

Carl Eugen

_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


More information about the Libav-user mailing list