Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if FFmpegFrameGrabberSimple(inputStream) not use grabber.setFrameNumber(num) #1234

Closed
duck123456 opened this issue Jun 23, 2019 · 14 comments
Closed
Labels

Comments

@duck123456
Copy link

ByteArrayInputStream inputStream= new ByteArrayInputStream(inputBytes);

    FFmpegFrameGrabberSimple grabber=new FFmpegFrameGrabberSimple(inputStream);
    grabber.start();
    log.info("===>>"+grabber.getLengthInTime());  this is 0
    Frame frame=null;
    int index=0;
    AVPacket pkt=null;
    while(true){
    grabber.setFrameNumber(index);

        frame=  grabber.grabFrame(false,true,true,false);

      index+=38;

    }

Caused by: org.bytedeco.javacv.FrameGrabber$Exception: avformat_seek_file() error -1: Could not seek file to timestamp 2920000.

https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java#L619

https://github.com/bytedeco/javacv/blob/master/src/main/java/org/bytedeco/javacv/FFmpegFrameGrabber.java#L812-L814

if use avformat_alloc_context AND avio_alloc_context to Allocating memory will not seek frames

thanks

@saudet
Copy link
Member

saudet commented Jun 23, 2019 via email

@duck123456
Copy link
Author

setFrameNumber() won't work well for streams with variable frame rates. Try to use setTimestamp() instead.
The same problem !

@saudet
Copy link
Member

saudet commented Jun 24, 2019

Well, you'll need to give me something to reproduce this issue if you expect some help.

@duck123456
Copy link
Author

public static void main(String[] args) throws FileNotFoundException, FrameGrabber.Exception {
    File file=new File("C:\\Users\\x1c\\Desktop\\temp\\49\\pp\\zao_17.ts");
    InputStream inputStream= new FileInputStream(file);
    FFmpegFrameGrabber grabber=new FFmpegFrameGrabber(inputStream);
    grabber.start();
    grabber.setFrameNumber(5);
    Frame frame= grabber.grabFrame(false,true,true,false);
     
}

this simple demo can reproduce the problem! you can try it ! thanks

@saudet
Copy link
Member

saudet commented Jun 24, 2019

Ah, that's the problem. .ts files don't have an index. You'll need to convert that to something else first.

@saudet saudet closed this as completed Jun 24, 2019
@duck123456
Copy link
Author

Ah, that's the problem. .ts files don't have an index. You'll need to convert that to something else first.

good! thanks

@duck123456
Copy link
Author

public static void main(String[] args) throws FileNotFoundException, FrameGrabber.Exception {
File file=new File("C:\Users\x1c\Desktop\temp\49\pp\zao_17.ts");
FFmpegFrameGrabber grabber=new FFmpegFrameGrabber(file);
grabber.start();
grabber.setFrameNumber(5);
Frame frame= grabber.grabFrame(false,true,true,false);
}

.ts files don't have an index,why InputStream Instead of File is normal ?

@saudet
Copy link
Member

saudet commented Jun 25, 2019

Either work the same for me. I'll need something to reproduce that if it doesn't work for you for some reason.

@duck123456
Copy link
Author

Either work the same for me. I'll need something to reproduce that if it doesn't work for you for some reason.

.ts file doesn't work,but .mp4 file is normal ! I found that avformat_find_stream_info() doesn't work by .ts file! Either work the same for me!but it work no same! It's confusing to me

@saudet
Copy link
Member

saudet commented Jun 25, 2019

You're right, it isn't working the same for MPEG-TS. It feels like there is a bug in FFmpeg somewhere there, and should probably be reported upstream...

@duck123456
Copy link
Author

You're right, it isn't working the same for MPEG-TS. It feels like there is a bug in FFmpeg somewhere there, and should probably be reported upstream...

Well,thanks

saudet added a commit that referenced this issue Jun 25, 2019
@saudet
Copy link
Member

saudet commented Jun 25, 2019

Actually, after implementing AVSEEK_SIZE, it appears to work fine!

@duck123456
Copy link
Author

Actually, after implementing AVSEEK_SIZE, it appears to work fine!

Awesome !it appears to work fine! that is cool !Thank you

@saudet
Copy link
Member

saudet commented Jul 10, 2019

Fix now included in JavaCV 1.5.1. Thanks for reporting!

@saudet saudet closed this as completed Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants