Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
FFMPEG MemoryAccessException on cleanup
16 décembre 2015, par Casey PriceI've written an application that records from various USB webcams using ffmpeg, however if I unplug a camera while ffmpeg is in the middle of recording I get memory access exceptions when running the following cleanup code.
if (packet.data != 0) av_packet_unref(&packet); if (frame != 0) av_frame_free(&frame); if (ifmt_ctx != NULL) { for (i = 0; i < ifmt_ctx->nb_streams; i++) { avcodec_close(ifmt_ctx->streams[i]->codec); if (ofmt_ctx && ofmt_ctx->nb_streams > i && ofmt_ctx->streams[i] && ofmt_ctx->streams[i]->codec) avcodec_close(ofmt_ctx->streams[i]->codec); if (filter_ctx && filter_ctx[i].filter_graph) avfilter_graph_free(&filter_ctx[i].filter_graph); } } if (filter_ctx != NULL && filter_ctx->buffersink_ctx != NULL && filter_ctx->buffersrc_ctx != NULL && filter_ctx->filter_graph != NULL) av_freep(&filter_ctx); if (ifmt_ctx != 0) avformat_close_input(&ifmt_ctx); if (ofmt_ctx && ofmt_ctx->oformat != NULL && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) avio_closep(&ofmt_ctx->pb); if (ofmt_ctx != 0 && ofmt_ctx->oformat != 0) avformat_free_context(ofmt_ctx);
Specifically it crashes on
if (filter_ctx != NULL && filter_ctx->buffersink_ctx != NULL && filter_ctx->buffersrc_ctx != NULL && filter_ctx->filter_graph != NULL) av_freep(&filter_ctx);
With a Null Reference exception on the if check sometimes. Other times the code runs fine and doesn't crash. I've also tried
if (filter_ctx) av_free(filter_ctx);
But this gives me a MemoryAccessException instead of a null reference, I'm guessing something on another thread is changing my data while cleaning up, however all of my variables are are not shared with any other thread.
Does anyone know whats going on?
-
Unable to combine mp4 videos using MP4Box
16 décembre 2015, par rajeshkumarI am using MP4box to combine mp4(H264) videos, If two video will combine means, the videos are combine but the first video are repeating twice and its play. Before that i used FFmpeg to convert the mp4 videos as constant bitrate,dimensions etc. I thing that may problem occurs. I used the command as given below:
ffmpeg -i inputfile.mp4 -r 25 -s 640x360 -ar 48000 -acodec copy -f mp4 -vcodec libx264 -vpre normal outputfile.mp4 MP4Box -force-cat -cat outputfile1.mp4 -cat outputfile2.mp4 -new largeOutput.mp4
Kindly suggest me any solution....
-
MP4 file data structure
16 décembre 2015, par man-ri have an mp4 video byte array and i need to generate a thumbnail for it using its middle frame (e.g. if the video length is 10 seconds then i need to get the picture from 5th second).
i managed to parse through the file and extract its boxes (atom). i have also managed to get the video length from the mvhd box. also i managed to extract 1. the time-To-Sample table from stts box, 2. the sample-To-Chunk table from stcs box, 3. the chunk-Offset table from stco box, 4. the sample Size table from stsz box, 5. the Sync Sample table from stss box
i know that all the actual media are available in the mdat box and that i need to correlate the above table to find the exact frame offset in the file but my question is how? the tables data seems to be compressed (specially the time-To-Sample table) but i don't know how decompress them.
any help is appreciated.
below are code samples
code to convert byte to hex
public static char[] bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for ( int j = 0; j < bytes.length; j++ ) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return hexChars; }
code for getting the box offset
final static String MOOV = "6D6F6F76"; final static String MOOV_MVHD = "6D766864"; final static String MOOV_TRAK = "7472616B"; final static String MOOV_TRAK_MDIA = "6D646961"; final static String MOOV_TRAK_MDIA_MINF = "6D696E66"; final static String MOOV_TRAK_MDIA_MINF_STBL = "7374626C"; final static String MOOV_TRAK_MDIA_MINF_STBL_STSD = "73747364"; final static String MOOV_TRAK_MDIA_MINF_STBL_STTS = "73747473"; final static String MOOV_TRAK_MDIA_MINF_STBL_STSS = "73747373"; final static String MOOV_TRAK_MDIA_MINF_STBL_STSC = "73747363"; final static String MOOV_TRAK_MDIA_MINF_STBL_STCO = "7374636F"; final static String MOOV_TRAK_MDIA_MINF_STBL_STSZ = "7374737A"; static int getBox(char[] s, int offset, String type) { int typeOffset = -1; for (int i = offset*2; i-1) { break; } } i+=(size*2); } return typeOffset; }
code for getting the duration and timescale
static int[] getDuration(char[] s) { int mvhdOffset = getBox(s, 0, MOOV_MVHD); int timeScaleStart = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4)*2; int timeScaleEnd = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4 + 4)*2; int durationStart = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4 + 4)*2; int durationEnd = (mvhdOffset*2) + (4 + 4 + 1 + 3 + 4 + 4 + 4 + 4)*2; String timeScaleHex = new String(Arrays.copyOfRange(s, timeScaleStart, timeScaleEnd)); String durationHex = new String(Arrays.copyOfRange(s, durationStart, durationEnd)); int timeScale = Integer.parseInt(timeScaleHex, 16); int duration = Integer.parseInt(durationHex, 16); int[] result = {duration, timeScale}; return result; }
code to get the time-To-Sample table
static int[][] getTimeToSampleTable(char[] s, int trakOffset) { int offset = getBox(s, trakOffset, MOOV_TRAK_MDIA_MINF_STBL_STTS); int sizeStart = offset*2; int sizeEnd = offset*2 + (4)*2; int typeStart = offset*2 + (4)*2; int typeEnd = offset*2 + (4 + 4)*2; int noOfEntriesStart = offset*2 + (4 + 4 + 1 + 3)*2; int noOfEntriesEnd = offset*2 + (4 + 4 + 1 + 3 + 4)*2; String sizeHex = new String(Arrays.copyOfRange(s, sizeStart, sizeEnd)); String typeHex = new String(Arrays.copyOfRange(s, typeStart, typeEnd)); String noOfEntriesHex = new String(Arrays.copyOfRange(s, noOfEntriesStart, noOfEntriesEnd)); int size = Integer.parseInt(sizeHex, 16); int noOfEntries = Integer.parseInt(noOfEntriesHex, 16); int[][] timeToSampleTable = new int[noOfEntries][2]; for (int i = 0; icode>
-
Read output from ffmpeg command
16 décembre 2015, par Gonzalo SoleraI'm trying to read the output from a ffmpeg command in android. I've been attempting this:
try { Process process = Runtime.getRuntime().exec("data/data/com.extremeye/cache/ffmpeg" + " -i " + videoPath + " -y " + framesPath + "%d.jpg"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); StringBuilder log = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { log.append(line + "\n"); } Log.d(TAG, log.toString()); } catch (IOException e) { }
It works when the command is "ls /data/data/package/cache" for example, but It doesn't retrieve the data I want from my ffmpeg command. The data I want should be these:
But when I use my code with this command it doesn't retrieve any data.
Now, I'm using the new code from answers and it seems to work but not really. I'm getting this:
[format @ 0xee7450] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'format' [scale @ 0xee85f0] w:1280 h:720 fmt:yuv420p sar:1/1 -> w:1280 h:720 fmt:yuvj420p sar:1/1 flags:0x4 Output #0, image2, to '/data/data/com.extremeye/cache/frames/%d.jpg': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp41isom creation_time : 2013-11-20 14:45:01 encoder : Lavf54.6.100 Stream #0:0(und): Video: mjpeg, yuvj420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30 tbc Metadata: creation_time : 2013-11-20 14:45:01 handler_name : VideoHandler Stream mapping: Stream #0:0 -> #0:0 (h264 -> mjpeg) Press [q] to stop, [?] for help frame= 3 fps=1.1 q=2.0 size= 0kB time=00:00:00.10 bitrate= 0.0kbits/s frame= 5 fps=1.5 q=5.0 size= 0kB time=00:00:00.16 bitrate= 0.0kbits/s frame= 7 fps=1.8 q=10.2 size= 0kB time=00:00:00.23 bitrate= 0.0kbits/s frame= 9 fps=1.9 q=16.0 size= 0kB time=00:00:00.30 bitrate= 0.0kbits/s frame= 11 fps=1.9 q=21.9 size= 0kB time=00:00:00.36 bitrate= 0.0kbits/s frame= 12 fps=1.3 q=24.8 size= 0kB time=00:00:00.40 bitrate= 0.0kbits/s frame= 13 fps=1.0 q=24.8 size= 0kB time=00:00:00.43 bitrate= 0.0kbits/s frame= 14 fps=1.0 q=24.8 size= 0kB time=00:00:00.46 bitrate= 0.0kbits/s frame= 15 fps=1.1 q=24.8 size= 0kB time=00:00:00.50 bitrate= 0.0kbits/s frame= 17 fps=1.1 q=24.8 size= 0kB time=00:00:00.56 bitrate= 0.0kbits/s frame= 19 fps=1.2 q=24.8 size= 0kB time=00:00:00.63 bitrate= 0.0kbits/s frame= 21 fps=1.3 q=24.8 size= 0kB time=00:00:00.70 bitrate= 0.0kbits/s frame= 23 fps=1.4 q=24.8 size= 0kB time=00:00:00.76 bitrate= 0.0kbits/s frame= 25 fps=1.4 q=24.8 size=
The data retrieving is interrupted suddenly and I don't know why... Any idea?
-
How can I read the video MediaInfo in Android?
16 décembre 2015, par 肖剑锋I want to read a video file's media info in android. How can I write code? please,help.
And the media info like this: