[Libav-user] Remuxing video file

Stefano Sabatini stefasab at gmail.com
Sun Feb 2 11:18:07 CET 2014


In data Saturday 2014-02-01 23:47:38 +0200, Yuri Oleynikov (יורי אולייניקוב ha scritto:
> hello, i am new to libav. after reading documentation and examples for
> serveral weeks, i tried to write simple remuxing (e.g mp4->avi) w/o
> decoding/encoding, just like *ffmpeg -i inputfile.mp4 -f avi -c:v copy -an
> output.avi.*
> 
> however both VLC and windows media player refuse to play output avi file -
> no video playback.
> moreoever ffprobe on output file shows me incorrect duration and bitrate.
> 
> moreover, though the output file contains only video streams and lacks
> audio streams it's much bigger than the input file:
> 
> -rw-r--r-- 1 me me 28689538 Feb  1 13:00 inputk.mp4
> -rw-r--r-- 1 me me 77916554 Feb  1 13:40 output.avi
> 
> 
> 
> i am definitely missing somesthing.
> again, my appologies, i'm a new to libav*. :(
> thanks for help.
> 
> PS: sorry for long mail.
> 
> my shortened code:
> 
> avformat_open_input(&ic, infname, NULL, NULL);
> avformat_find_stream_info(ic, NULL);
> 
> oc = avformat_alloc_context();
> oc->oformat = av_guess_format("avi", NULL, NULL);
> /**no need to open encoders/decoders since i do no want to recode the
> frames) **/
> memmove(oc->filename, outfname, strlen(outfname));
> avio_open(&oc->pb, outfname, AVIO_FLAG_WRITE);
> 
> // stripped map input video streams to output video streams block
> 
> avformat_write_header(oc, NULL);
> for(i=0; av_read_frame(ic, &inpacket)>=0; i++, av_free_packet(&inpacket)) {
> 
>         idx = inpacket.stream_index;
>         stream = ic->streams[idx];
>         if(stream_map[idx]==-1){
>            continue;
>         }
>         if(ic->streams[stream_map[idx]]->codec->codec_type!=AVMEDIA_TYPE_VIDEO)
>            continue;
>         av_copy_packet(&outpacket, &inpacket);
>         outpacket.stream_index = stream_map[idx];

You're missing timestamp rescaling here.

>         av_interleaved_write_frame(oc, &outpacket);
>         av_free_packet(&outpacket);
> }
> 
> av_write_trailer(oc);
> 
> my full code: https://github.com/yurkao/libavformat-test/blob/master/remux.c

I recently wrote a remuxing example and added it to doc/examples, you
can compare it with your code and report in case you seem some problems
with it.


More information about the Libav-user mailing list