[Ffmpeg-devel] FW: Re-opening media file after crash and continuing writing to it

Stas Oskin stas
Thu Jun 22 20:53:42 CEST 2006


Hi.

 

I tried to implement frame copying old file to a new one via the
following code:

 

------------------------------------------------------------------------
-------------------

    AVFormatContext *sourceFormatContext;

    AVPacket readPacket;

 

    if(av_open_input_file(&sourceFormatContext, sourceFile.c_str(),
NULL, 0, NULL) != 0)

        return false;

 

    while(av_read_frame(sourceFormatContext, &readPacket) >= 0)

    {

                        if(av_write_frame(targetFormatContext,
&readPacket) != 0)

                        {

                                    av_free_packet(&readPacket);

 
av_close_input_file(sourceFormatContext);

                                    return false;

                        }

 

                        av_free_packet(&readPacket);

            }

 

    av_close_input_file(sourceFormatContext);

 

------------------------------------------------------------------------
-------------------

 

The targetFormatContext was opened and initialized earlier.

 

This code works well with the mp4 format. With the asf/wmv format,
libavcodec displays "ff asf bad header" and "ff asf skip" error
messages, and the resulting files are only partially playable in Windows
Media Player. WMP simply skips over the copied frames to the newly
encoded ones.

 

I'm using the latest SVN of ffmpeg.

 

 

Did I forget something in the code above? Or the MS formats
implementation does not support such frames copying?

 

 

Thanks in advance,

Stas.

 

________________________________

From: Stas Oskin [mailto:stas at neo.co.il] 
Sent: Tuesday, June 20, 2006 12:57 PM
To: 'ffmpeg-devel at mplayerhq.hu'
Subject: FW: Re-opening media file after crash and continuing writing to
it

 

Hi.

 

I'm trying to implement a functionality which will re-open an incomplete
video file after the program has crashed, and continue to write to it.
It seems as libavcodec truncates the file on opening thought, which
brings 2 questions:

 

1)       Is there any way to prevent the libavcodec from truncating the
file?

2)       If not, what is the best way to copy video frames from the old
file to a new one, preserving all the info (timestamps, PTS/DTS, etc)?

 

Thanks a lot,

Stas.





More information about the ffmpeg-devel mailing list