question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ffmpeg stuck when using Channels to extract image close to the end of a video

See original GitHub issue

This problem is when using Channels.

I used this video file as input: https://file-examples-com.github.io/uploads/2020/03/file_example_WEBM_480_900KB.webm

The video has a length of 30540 milliseconds.

If I extract an image at 30.000 milliseconds on the console it works: /mnt/Data/software/ffmpeg-4.4-amd64-static/ffmpeg -loglevel level+info -ss 30.000 -i /mnt/Data/downloads/webm/file_example_WEBM_480_900KB.webm -y -frames:v 1 -q:v 1 -f image2 /mnt/Data/downloads/data.jpeg

When I try to repeat this in Jaffree, ffmpeg gets stuck and is never interrupted (see log below). I guess Channels are not the harddisk so there are small differences. No problem. Writing out at position 29500 works. However it is somewhat of a problem, that ffmpeg gets stuck and doesn’t throw an Exception. On the console ffmpeg never “freezes” even if you get close or over the video length. It just returns with an error: [warning] Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

try (SeekableByteChannel inputChannel = Files.newByteChannel(pathToSrc, StandardOpenOption.READ); SeekableByteChannel outputChannel = Files.newByteChannel(pathToDst, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.TRUNCATE_EXISTING) ) { FFmpeg.atPath() .addInput(ChannelInput.fromChannel(inputChannel).setPosition(30000)) .setOverwriteOutput(true) .addArguments("-frames:v", "1") .addArguments("-q:v", "1") .addOutput(ChannelOutput.toChannel(filename, outputChannel).setFormat("image2")) .execute(); }

[main] WARN com.github.kokorin.jaffree.ffmpeg.PipeOutput - It’s recommended to use ChannelOutput since ffmpeg requires seekable output for many formats [main] WARN com.github.kokorin.jaffree.ffmpeg.FFmpeg - ProgressListener isn’t set, progress won’t be reported [main] INFO com.github.kokorin.jaffree.process.ProcessHandler - Command constructed: ffmpeg -loglevel level+info -ss 30.000 -i ftp://127.0.0.1:38773/ -n -frames:v 1 -q:v 1 -f image2 tcp://127.0.0.1:44917 [main] INFO com.github.kokorin.jaffree.process.ProcessHandler - Starting process: ffmpeg [main] INFO com.github.kokorin.jaffree.process.ProcessHandler - Waiting for process to finish [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] ffmpeg version N-59310-gd115eec979-static https://johnvansickle.com/ffmpeg/ Copyright © 2000-2021 the FFmpeg developers [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] built with gcc 8 (Debian 8.3.0-6) [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libavutil 57. 7.100 / 57. 7.100 [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libavcodec 59. 11.100 / 59. 11.100 [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libavformat 59. 6.100 / 59. 6.100 [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libavdevice 59. 0.101 / 59. 0.101 [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libavfilter 8. 12.100 / 8. 12.100 [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libswscale 6. 1.100 / 6. 1.100 [StdErr] INFO com.github.kokorin.jaffree.ffmpeg.FFmpegResultReader - [info] libswresample 4. 0.100 / 4. 0.100

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
kokorincommented, Nov 6, 2021

@shoeoffhead It looks like problem is related to ChannelInput and TS file. FFmpeg can’t seek TS (no syncpoints?), and has to read input file from the beginning looking for required start position. Check #244 for details. Expect to merge it soon.

0reactions
kokorincommented, Nov 12, 2021

@shoeoffhead it’s very interesting to me how do you use Jaffree? Especially how do you use ChannelInput/Output? Could you share such information?

Read more comments on GitHub >

github_iconTop Results From Across the Web

FFMPEG frame extraction - stuck - Stack Overflow
The image sequence muxer, by default, is set to assume a constant frame rate output, so it will fill in missing timestamp gaps...
Read more >
ffmpeg Documentation
Before encoding, ffmpeg can process raw audio and video frames using filters from the ... You can also extract each channel of an...
Read more >
Extract Y-channel of every I-frame from MPEG4 movie as ...
I wrote my tracker myself and it cannot parse video, so it needs a folder with stills. Now my question is: how can...
Read more >
Repair Corrupt Video Files using FFmpeg
This blog aims to answer all the queries related to repairing corrupt video files like MOV, MP4, F4V, M4V, 3GP, AVI etc using...
Read more >
How to download portion of video with youtube-dl command?
I don't believe youtube-dl alone will do what you want. However you can combine it with a command line utility like ffmpeg. First...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found