Discussion:
[FFmpeg-user] Rendering video in reverse.
Jeff Sorrentino
2011-12-07 16:47:57 UTC
Permalink
I have a short project where I would like to reverse video play.

while (av_read_frame(pFormatCtx, &packet) >= 0) {
if (packet.stream_index == videoStream) {
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, packet.data,
packet.size);
if (frameFinished) {
if (img_convert_ctx == NULL) {
img_convert_ctx =
sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
textureWidth,textureHeight, textureFormat, SWS_FAST_BILINEAR, NULL, NULL,
NULL );
if(img_convert_ctx == NULL) {
// FREE PACKET? av_free_packet(&packet);
av_free_packet(&packet);
return;
}
}
sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0,
pCodecCtx->height, pFrameConverted->data, pFrameConverted->linesize );
av_free_packet(&packet);
return;
}
}
av_free_packet(&packet);
}
av_seek_frame(pFormatCtx, videoStream, 0, AVSEEK_FLAG_ANY);


In the above example, the methodology to do this is pretty simple, *but* I
did not find functions that would allow me to properly gather the data and
manipulate the current frame as need be.

Meaning, av_seek_frame(...) takes a timestamp as an argument for where to
seek in TIME, but I would (or so i think) need to seek to the last frame
(last line above).

If av_seek_frame can do a SEEK TO LAST FRAME, then in the initial loop i
can call av_read_frame followed by an av_seek_frame ( CurrentFrame - 1 )
(or CurrentFrame - 2 taking into account the read frame).

1. How do I get the total number of frames from the video?
2. How do I incorporate the av_seek_frame to seek based on frame and not
time?
3. OR, is there an av_read_frame_NUMBER() function available?

Thank You!
Mark Himsley
2011-12-08 08:23:24 UTC
Permalink
Post by Jeff Sorrentino
I have a short project where I would like to reverse video play.
Reverse decoding is really hard in long GOP encoded video.

As a quick solution for video only with FFmpeg and a short script, you
could export all frames to images, renumber the images to the reverse
order (being careful to avoid file name collisions) and then re-encode
from the renumbered files.

Sorry, didn't really answer your question.
--
Mark
肖波
2011-12-08 09:37:39 UTC
Permalink
Recently I'm do some test on ffmpeg decoding,and I think I may found a bug in the latest windows version(it didn't exist in quite old versions).

My test file is in MXF(op-1a) format,with video in mpeg-2 and audio in mpeg-1.

After avcodec_find_decoder(), I found my first audio stream's codec-id is CODEC_ID_MPEG2VIDEO,and when call avcodec_open(), it failed!

When decode with ffplay,it resulted errors:"[mpeg2video @ 03259E20] codec type or id mismatches"

I tested the file with an old version ffmpeg (published at year 2007),it doesn't have this problem.

I have uploaded the sample file to the following position,anybody interested please download it

http://www.datafilehost.com/download-c570856f.html
Carl Eugen Hoyos
2011-12-09 16:16:02 UTC
Permalink
Post by 肖波
or id mismatches"
I tested the file with an old version ffmpeg (published at year 2007),it
doesn't have this problem.
I have uploaded the sample file to the following position,anybody interested
please download it
http://www.datafilehost.com/download-c570856f.html
This is a regression since 2008 (!), I opened ticket #721 and sent a patch
(actually two) yesterday to ffmpeg-devel to fix the bug, unfortunately, the
patches do not apply anymore today;-(

Feel free to add yourself to CC in the ticket.

Please do not highjack threads, this is considered highly rude, Carl Eugen
Carl Eugen Hoyos
2011-12-10 14:15:19 UTC
Permalink
Post by 肖波
or id mismatches"
Fixed, thank you for the sample!

Carl Eugen

肖波
2011-12-08 10:18:47 UTC
Permalink
At 2011-12-08 17:37:39,"肖波" <***@163.com> wrote: >Recently I'm do some test on ffmpeg decoding,and I think I may found a bug in the latest windows version(it didn't exist in quite old versions). > >My test file is in MXF(op-1a) format,with video in mpeg-2 and audio in mpeg-1. > >After avcodec_find_decoder(), I found my first audio stream's codec-id is CODEC_ID_MPEG2VIDEO,and when call avcodec_open(), it failed! > >When decode with ffplay,it resulted errors:"[mpeg2video @ 03259E20] codec type or id mismatches" > >I tested the file with an old version ffmpeg (published at year 2007),it doesn't have this problem. > >I have uploaded the sample file to the following position,anybody interested please download it > >http://www.datafilehost.com/download-c570856f.html > > > > > > > > > > > > >_______________________________________________ >ffmpeg-user mailing list >ffmpeg-***@ffmpeg.org >http://ffmpeg.org/mailman/listinfo/ffmpeg-user


Sorry, the sample file link is:
http://www.datafilehost.com/do
Continue reading on narkive:
Loading...