I am trying to open a file descriptor from a CATEGORY_OPENABLE
URI from the Storage Access Framework. I am first trying with a file on the sdcard, which I can already resolve to a file path using the _data
column and open (I am trying to get away from doing this, and use the file descriptor instead).
I get the the native int fd like this:
int fd = getContentResolver().openFileDescriptor(data.getData(), "r").detachFd();
Then in C++, I am trying to open it like this, the idea taken from How to properly pass an asset FileDescriptor to FFmpeg using JNI in Android:
pFormatCtx = avformat_alloc_context();
pFormatCtx->iformat = av_find_input_format("mp3");
char path[50];
sprintf(path, "pipe:%d", fd);
int e;
if(e=(avformat_open_input(&pFormatCtx,path,NULL,NULL)!=0)){
av_strerror(e, path, 50);
return error;
}
This yields an "Unknown error" from avformat_open_input
. The same thing happens if I use the jni method jniGetFDFromFileDescriptor
from the above linked on a FileDescriptor
object to get the int fd instead. How can I open an openable URI with FFMPEG correctly without using the file path?
You can select the output format of each frame with ffmpeg by specifying the audio and video codec and format. For example to compute the CRC of the input audio converted to PCM unsigned 8-bit and the input video converted to MPEG-2 video, use the command:
Use ffmpeg to encode the input, and send the output to three different destinations. The dump_extra bitstream filter is used to add extradata information to all the output video keyframes packets, as requested by the MPEG-TS format. The select option is applied to out.aac in order to make it contain only audio packets.
You can print the CRC to stdout with the command: You can select the output format of each frame with ffmpeg by specifying the audio and video codec and format. For example to compute the CRC of the input audio converted to PCM unsigned 8-bit and the input video converted to MPEG-2 video, use the command:
Available identifiers are "$RepresentationID$", "$Number$", "$Bandwidth$" and "$Time$". In addition to the standard identifiers, an ffmpeg-specific "$ext$" identifier is also supported.
My project (FFmpegMediaMetadataRetriever) accomplishes this. See this gist or the full file here.
Note: make sure you have built FFmpeg with the pipe protocol enabled!
I used avformat_open_input
, dup()
the file descriptor and made sure to set the offset via:
if (state->offset > 0) {
state->pFormatCtx = avformat_alloc_context();
state->pFormatCtx->skip_initial_bytes = state->offset;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With