First off, in the long run I want to implement a speedometer for a MP4 file using Android. I did some research and apparently the best way to do that is through FFmpeg. I decided on using this library: https://github.com/WritingMinds/ffmpeg-android-java . It implements FFmpeg for Android. It was quite simple to include into my project. (Instructions: http://writingminds.github.io/ffmpeg-android-java/)
I use the following method. As cmd I am using a String in Quotations marks
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
...
};
Now I was trying to overlay some dynamic text over an MP4 file. I thought I would start trying it with a timestamp. For a timestamp something like this is needed: ... timecode='02:36:17\;00' ...
My Problem is I am getting this error " Unable to find a suitable output format for '''. It doesn't matter if i try to use "\" (escaping) or if i try to use regular quotes. Whenever I use some kind of quotation mark I am getting an error. That makes it impossible to use an dynamic timestamp. I think.
Does anyone have an idea as to how I can fix this? Keep in mind the timecode is within a String in an Android(Java) class.
Thanks in advance for your help
EDIT:
Can someone provide me with a working command? The cmd 1-3 work, but 4 and 5 don't work (even as String[]).
String cmd1 = "-i /storage/emulated/0/dir1/dir2/TestVideo.MP4 -i /storage/emulated/0/dir1/dir2/logo.png -preset ultrafast -filter_complex overlay=10:main_h-overlay_h-10 -acodec: copy /storage/emulated/0/dir1/dir2/LogoOverlay1.mp4";// working PNG overlay
String cmd2 = "-i /storage/emulated/0/dir1/dir2/TestVideo.MP4 -i /storage/emulated/0/dir1/dir2/logo.png -preset ultrafast -filter_complex overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 -acodec: copy /storage/emulated/0/dir1/dir2/LogoOverlay2.mp4";// working PNG overlay
String cmd3 = "-i /storage/emulated/0/dir1/dir2/TestVideo.MP4 -i /storage/emulated/0/dir1/dir2/logo.png -preset ultrafast -filter_complex [0:v][1:v]overlay=main_w-overlay_w-10:main_h-overlay_h-10[out] -map [out] -map 0:a -acodec: copy /storage/emulated/0/dir1/dir2/LogoOverlay3.mp4";// working PNG overlay
String cmd4 = "-i /storage/emulated/0/dir1/dir2/TestVideo2.MP4 -vf drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text=\'Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2\" -acodec: copy /storage/emulated/0/dir1/dir2/TextOverlay.mp4";
String cmd5 = "-i /storage/emulated/0/dir1/dir2/TestVideo2.MP4 -vf \'transpose=1\' /storage/emulated/0/dir1/dir2/rotated.mp4"; //rotate video
String[] cmd4arr = new String[]{"-i", "/storage/emulated/0/dir1/dir2/TestVideo.MP4", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text='Stack Overflow': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2", "-acodec:", "copy /storage/emulated/0/dir1/dir2/TextOverlay.mp4"};
String[] cmd5arr = new String[]{"-i", "/storage/emulated/0/dir1/dir2/TestVideo2.MP4","-preset","ultrafast", "-vf", "\'transpose=1\'", "/storage/emulated/0/dir1/dir2/rotated.mp4"};
String[] cmd4ArrAlt = new String[]{"-i", "/storage/extSdCard/DCIM/Camera/Test.MP4", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf:", "text=\'Stack Overflow\':", "fontcolor=white:", "fontsize=24:", "box=1:", "boxcolor=black:", "x=(w-text_w)/2:", "y=(h-text_h-line_h)/2", "-acodec:", "copy", "/storage/emulated/0/dir/TextOverlay.mp4"};
cmd4arr produces this Log:
.../MainActivity﹕ onProgress ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
.../MainActivity﹕ onProgress built on Oct 7 2014 15:08:46 with gcc 4.8 (GCC)
.../MainActivity﹕ onProgress configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
.../MainActivity﹕ onProgress libavutil 54. 7.100 / 54. 7.100
.../MainActivity﹕ onProgress libavcodec 56. 1.100 / 56. 1.100
.../MainActivity﹕ onProgress libavformat 56. 4.101 / 56. 4.101
.../MainActivity﹕ onProgress libavdevice 56. 0.100 / 56. 0.100
.../MainActivity﹕ onProgress libavfilter 5. 1.100 / 5. 1.100
.../MainActivity﹕ onProgress libswscale 3. 0.100 / 3. 0.100
.../MainActivity﹕ onProgress libswresample 1. 1.100 / 1. 1.100
.../MainActivity﹕ onProgress libpostproc 53. 0.100 / 53. 0.100
.../MainActivity﹕ onProgress Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/dir1/dir2/TestVideo2.MP4':
.../MainActivity﹕ onProgress Metadata:
.../MainActivity﹕ onProgress major_brand : isom
.../MainActivity﹕ onProgress minor_version : 512
.../MainActivity﹕ onProgress compatible_brands: isomiso2mp41
.../MainActivity﹕ onProgress creation_time : 1970-01-01 00:00:00
.../MainActivity﹕ onProgress encoder : Lavf53.24.2
.../MainActivity﹕ onProgress Duration: 00:00:06.40, start: 0.000000, bitrate: 1321 kb/s
.../MainActivity﹕ onProgress Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x368 [SAR 1:1 DAR 40:23], 932 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
.../MainActivity﹕ onProgress Metadata:
.../MainActivity﹕ onProgress creation_time : 1970-01-01 00:00:00
.../MainActivity﹕ onProgress handler_name : VideoHandler
.../MainActivity﹕ onProgress Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
.../MainActivity﹕ onProgress Metadata:
.../MainActivity﹕ onProgress creation_time : 1970-01-01 00:00:00
.../MainActivity﹕ onProgress handler_name : SoundHandler
cmd4ArrAlt produces this Log:
.
.
.
/MainA: onProgress: handler_name : SoundHandle
/MainA: onProgress: [NULL # 0xb5ec4a00] Unable to find a suitable output format for 'text='Stack Overflow':'
/MainA: onProgress: text='Stack Overflow':: Invalid argument
cmd4arr and cmd5arr create an new MP4 file. But it has a size of 0KB. The commands seem not to process the frames at all. It always stops with this last line of the Log posted above.
Edit:
Answered question: "What how can I use a String [ ] with this Library? Information on that might fix the other issues."
Answer: I imported the project as arr before. When it is imported as a regular library you can't use a normal String anymore but it is implemented as an String[].
I have the same issue, and the problem was that complex ffmpeg command at most android-ffmpeg-java wrapper should be pass as array and not as simple string.
EDIT:
Try this:
String[] cmd4arr = new String[]{
"-i",
"/storage/emulated/0/dir1/dir2/TestVideo.MP4",
"-vf",
"drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text=\'Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2",
"-acodec:",
"copy",
"/storage/emulated/0/dir1/dir2/TextOverlay.mp4"};
Change the transpose in cmd5 single quote should be in before = like this "transpose=\'1\'"
String[] cmd5arr = new String[]{"-i",
"/storage/emulated/0/dir1/dir2/TestVideo2.MP4",
"-preset",
"ultrafast",
"-vf",
"transpose=\'1\'",
"/storage/emulated/0/dir1/dir2/rotated.mp4"};
Related
I am using ffmpeg to convert videos to mp4 format. Everything works fine except with MOV format.
The command I use for everything is:
ffmpeg -i input.mov -strict experimental -sameq -s vga -aspect 1.7777 -vcodec libx264 -preset fast -crf 22 -y output.mp4
but the output I keep getting is:
ffmpeg version 0.9, Copyright (c) 2000-2011 the FFmpeg developers
built on Mar 12 2012 11:01:05 with gcc 4.4.5
configuration: --enable-libx264 --enable-gpl --disable-yasm
libavutil 51. 32. 0 / 51. 32. 0
libavcodec 53. 42. 0 / 53. 42. 0
libavformat 53. 24. 0 / 53. 24. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 53. 0 / 2. 53. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
[mov,mp4,m4a,3gp,3g2,mj2 # 0x21767a0] Referenced QT chapter track not found
Seems stream 0 codec frame rate differs from container frame rate: 30.00 (30/1) -> 30.07 (2225/74)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
Metadata:
creation_time : 2009-04-04 07:12:29
comment : EASTMAN KODAK COMPANY KODAK Z1275 ZOOM DIGITAL CAMERA
comment-eng : EASTMAN KODAK COMPANY KODAK Z1275 ZOOM DIGITAL CAMERA
Duration: 00:00:17.76, start: 0.000000, bitrate: 8100 kb/s
Stream #0:0(eng): Video: mpeg4 (Advanced Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 7968 kb/s, 30.07 fps, 30.07 tbr, 8544k tbn, 30 tbc
Metadata:
creation_time : 2009-04-04 07:12:29
handler_name :
Stream #0:1(eng): Audio: pcm_mulaw (ulaw / 0x77616C75), 16000 Hz, 1 channels, s16, 128 kb/s
Metadata:
creation_time : 2009-04-04 07:12:29
handler_name :
[buffer # 0x2187f00] w:1280 h:720 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[scale # 0x219c120] w:1280 h:720 fmt:yuv420p -> w:640 h:480 fmt:yuv420p flags:0x4
[libx264 # 0x2190d20] using SAR=4/3
[libx264 # 0x2190d20] using cpu capabilities: none!
[libx264 # 0x2190d20] profile High, level 3.0
[libx264 # 0x2190d20] 264 - core 120 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=22.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[aac # 0x21917e0] Too many bits per frame requested
Output #0, mp4, to 'output.mp4':
Metadata:
creation_time : 2009-04-04 07:12:29
comment : EASTMAN KODAK COMPANY KODAK Z1275 ZOOM DIGITAL CAMERA
comment-eng : EASTMAN KODAK COMPANY KODAK Z1275 ZOOM DIGITAL CAMERA
Stream #0:0(eng): Video: h264, yuv420p, 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 90k tbn, 30.07 tbc
Metadata:
creation_time : 2009-04-04 07:12:29
handler_name :
Stream #0:1(eng): Audio: aac, 16000 Hz, 1 channels, s16, 128 kb/s
Metadata:
creation_time : 2009-04-04 07:12:29
handler_name :
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 -> libx264)
Stream #0:1 -> #0:1 (pcm_mulaw -> aac)
Error while opening encoder for output stream #0:1 - maybe incorrect parameters such as bit_rate, rate, width or height
It seems the problem is with audio's bit per frame.
Which might be the right solution?
The "Too many bits per frame requested" error is coming from the native FFmpeg AAC encoder (-c:a aac). You can use one or more of the following solutions:
Update your ffmpeg
Development is very active and the native FFmpeg AAC encoder has seen many improvements; it will now automatically clamp to the max number of bits per frame instead of failing with this error. See the FFmpeg Download page for links to already compiled binaries which are the easiest method to get a recent ffmpeg.
If you're stuck with an old, outdated, ancient ffmpeg:
Increase the audio sampling rate such as by adding -ar 44100.
Decrease your bitrate. Default is probably -b:a 128k. Try lower values until it works.
Use -c:a copy to stream copy (re-mux) the audio, and, because MP4 doesn't support pcm_mulaw, use different output container format such as Matroska (.mkv).
Use a different AAC encoder such as libfdk_aac if your ffmpeg supports it.
You don't need to do any of these options if you upgrade ffmpeg.
I'd hope ffmpeg is more clever than this, but you might try specifying the video stream for your -s and -aspect options: -s:v and -aspect:v.
Alternately, since you're not doing anything special with the audio, you could copy it explicitly with -c:a copy.
I'm using the JavaCV FFmpegFrameRecorder class to encode Android's camera preview frames into a video.
The goal would be to replicate the result of the following command line:
ffmpeg -i input.mp4 -metadata:s:v:0 rotate="90" output.mp4
I modified the startUnsafe() method as follows, but it failed to generate the desired output:
if ((video_st = avformat_new_stream(oc, video_codec)) != null) {
video_c = video_st.codec();
video_c.codec_id(oformat.video_codec());
video_c.codec_type(AVMEDIA_TYPE_VIDEO);
...
AVDictionary avDictionary = new AVDictionary(null);
av_dict_set(avDictionary, "rotate", "90", 0);
video_st.metadata(avDictionaty);
...
}
...
avformat_write_header(oc, (PointerPointer) null);
This still encodes the video correctly, but the added metadata never appears on ffprobe. If it helps, the video encoding is h264.
By the way, here's the ffprobe output:
ffprobe version 2.3.3 Copyright (c) 2007-2014 the FFmpeg developers
built on Jan 22 2015 18:22:57 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libquvi --enable-libx265
libavutil 52. 92.100 / 52. 92.100
libavcodec 55. 69.100 / 55. 69.100
libavformat 55. 48.100 / 55. 48.100
libavdevice 55. 13.102 / 55. 13.102
libavfilter 4. 11.100 / 4. 11.100
libavresample 1. 3. 0 / 1. 3. 0
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 19.100 / 0. 19.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'abcd.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.15.102
Duration: 00:00:19.48, start: 0.023220, bitrate: 572 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, 573 kb/s, 5.71 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 64 kb/s (default)
Metadata:
handler_name : SoundHandler
Any suggestions on why is it failing? Thanks.
It seems this question generated a lot of interest so I'm adding some more info. Following this GitHub issue Samuel from JavaCV committed some changes to allow easier access to metadata settings.
Setting metadata can be achieved through the following code snippet:
AVDictionary metadata = new AVDictionary(null);
for (Entry<String, String> e : videoMetadata.entrySet()) {
av_dict_set(metadata, e.getKey(), e.getValue(), 0);
}
video_st.metadata(metadata);
You can enable it right now by doing mvn install -Pffmpeg or wait until the next JavacV release, which should be 0.12.
PS: As you can see, this is pretty similar to what I presented in my question, so I'm not sure why it didn't work in the first place.
The FFmpegFrameRecorder class you are using uses an AVFormatContext class. Around line 2579 you can see from the method signatures, that the AVFormatContext class uses native code to implement both
public native AVDictionary metadata() method
public native AVFormatContext metadata(AVDictionary metadata) method.
The answer to the link you provided says they used the metadata property of the AVFormatContext directly - something like the first method I think. But Line 649 of FFmpegFrameRecorder uses the second method - I suspect. i.e.:
AVDictionary metadata = new AVDictionary(null);
... code to fill up dictionary ...
...
avformat_write_header(oc.metadata(metadata), options);
Unfortunately I can't try this at the moment, but I wonder if you could do something like this:
AVDictionary metadata = co.metadata();
... code to fill up dictionary ...
//I would assume at this point that oc has the metadata so
avformat_write_header(oc, (PointerPointer) null);
//if not then maybe
// avformat_write_header(oc.metadata(metadata), options);
The signature shows it is public, so I don't see why you can't get the metadata dictionary from the AVFormatContext directly. I'm not sure how the avformat_write_header method works, so I suggested two things above.
Note: I have not used this library before. I tried, unsuccessfully to use Xuggler in the past for some basic encoding.
I have a program called FFprobe which probes media (files/live streams ... ) and outputs result in different formats , for example :
ffprobe.exe -i test.ts -print_format xml -show_programs
gives this output :
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
<programs>
<program program_id="1201" program_num="1201" nb_streams="2" pmt_pid="1000" pcr_pid="2011" start_pts="45394227044" start_time="45394.227044">
<tag key="service_name" value="Arabica TV"/>
<tag key="service_provider" value="Nilesat"/>
<streams>
<stream index="10" codec_name="mpeg2video" codec_long_name="MPEG-2 video" profile="Main" codec_type="video" codec_time_base="1/50" codec_tag_string="[2][0][0][0]" codec_tag="0x0002" width="720" height="576" has_b_frames="1" sample_aspect_ratio="16:15" display_aspect_ratio="4:3" pix_fmt="yuv420p" level="8" timecode="08:28:54:09" id="0x7db" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/90000" start_pts="4085542516" start_time="45394.916844" max_bit_rate="2348000">
<disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
</stream>
<stream index="4" codec_name="mp2" codec_long_name="MP2 (MPEG audio layer 2)" codec_type="audio" codec_time_base="1/48000" codec_tag_string="[0][0][0][0]" codec_tag="0x0000" sample_fmt="s16p" sample_rate="48000" channels="2" channel_layout="stereo" bits_per_sample="0" id="0xbcf" r_frame_rate="0/0" avg_frame_rate="0/0" time_base="1/90000" start_pts="4085480434" start_time="45394.227044" bit_rate="384000">
<disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
</stream>
</streams>
</program>
... more programs
to retrieve this info in java i used ProcessBuilder and a scanner , and then id write to a file once the result is ok ... but it wasnt :
Process proc = new ProcessBuilder("ffprobe.exe","-i", ... same arguments );
Scanner sc = new Scanner (proc.getInputStream()) // im 100% sure its not errorStream
while(sc.hasNext()){
System.out.println(sc.nextLine());
}
the app just hangs with no output , i know its hanging cuz the process is still running and scanner has next , but , i don't know why it would do that ?If i execute the same in cmd i would get good result and ofc i can write to file with ">"
Ive tried it w/o the -print_format option , which gives the info in a plain text on the errorstream(i know its error cuz i was able to write with 2> not >> ) , and i was able to read the error stream in java , but its not meant for parsing cuz very very un-organized .
Input #0, mpegts, from 'PBR_REC_20140426094852_486.ts':
Duration: 00:13:34.30, start: 7791.344722, bitrate: 42154 kb/s
Program 1201
Metadata:
service_name : Arabica TV
service_provider: Nilesat
Stream #0:19[0x7db]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 16:15 DAR 4:3], max. 2348 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:3[0xbcf]: Audio: mp2, 48000 Hz, stereo, s16p, 384 kb/s
Program 1202
Metadata:
service_name : NBN
service_provider: NILESAT
Stream #0:10[0x7d1]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 16:15 DAR 4:3], max. 2600 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:11[0xbba](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 125 kb/s
Program 1203
Metadata:
service_name : Heya TV
service_provider: NILESAT
Stream #0:5[0x7d2]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 720x576 [SAR 16:15 DAR 4:3], max. 2600 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:6[0xbbc](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 125 kb/s
Program 1204 ... more programs
now it might seem organized and "parse-able" and i actually made a parser that worked to some point , but sometimes it doesnt stick to this structure and ruins the whole parsing, its why i need a xml/json ...
The -print_format im sure outputs to outputstream.
Im not asking for help on how to use FFprobe as thats not this place's purpose , Im asking why am i not being able to get the output stream from java while it is definitely outputting if i execute in windows .
I also tried apache commons-exec as i know processbuilder can be a pain ,it did execute perfectly and showed in System.in (black for intput and red for error), but getting the stream with apache is something i couldn't understand , i tried this example
The xml parser i already taken care of , simply put i just need to execute that first command from java and read the output , but for some reason its not working .
I generally use variations of this utility method:
public static void runProcess(ProcessBuilder pb) throws IOException {
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
Even if you don't want to print the error stream you need to consume it otherwise it will block the process. In which case you would need to consume it in a separate thread and only print the input stream from the main thread.
I'm making a player that can play an MPEG-TS stream and display all its videos at once (for monitoring purposes) in one frame using Xuggler for JAVA.
My problem is getting to determine what programs this stream holds (tv programs) and what are its streams...
for example : audio stream 1 and video stream 3 belong to program "BBC".
Now I already got it working for a .ts file by using MediaInfo http://mediaarea.net/en/MediaInfo/ like so :
MediaInfo.exe -LogFile="log.txt" "some .ts file" .... which logs a file like this :
Menu #2
ID : 1001 (0x3E9)
Menu ID : 1202 (0x4B2)
Duration : 13mn 33s
List : 2001 (0x7D1) (MPEG Video) / 3002 (0xBBA) (MPEG Audio, English)
Language : / English
Service name : NBN
Service provider : NILESAT
Service type : digital television
UTC 2006-03-28 00:00:00 : en:NBN / en:Nilesat / / / 99:00:00 / Running
and then I parsed the file in java
but I need to make this work for a live stream and when I give MediaInfo a URL instead of a file it gives this error :
Libcurl library not found
I also tried vlc commands but turns out it doesn't have this option and only available in gui (show codec information)...
the player is already working and I got an extractor too... just need this media info to work... any ideas?
EDIT : I found out FFprobe which is bundled with FFmpeg http://www.ffmpeg.org/ can do the task
but for some reason I can't read anything from the input stream.
Here's what the output looks like:
Input #0, mpegts, from 'D:\record ts\PBR_REC_20140426094852_484.ts':
Duration: N/A, start: 6164.538011, bitrate: N/A
Program 1201
Metadata:
service_name : Arabica TV
service_provider: Nilesat
Stream #0:10[0x7db]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv42
0p(tv), 720x576 [SAR 16:15 DAR 4:3], max. 2348 kb/s, 25 fps, 25 tbr, 90k tbn, 50
tbc
Stream #0:4[0xbcf]: Audio: mp2, 48000 Hz, stereo, s16p, 384 kb/s
Program 1202
I tried this in JAVA:
try {
Process process ;
Scanner sc;
ProcessBuilder processBuilder = new ProcessBuilder("C:\\Users\\vlatkozelka\\Desktop\\ffmpeg-20140623-git-ca35037-win64-static\\bin\\ffprobe.exe","-i",filename);
process=processBuilder.start();
sc=new Scanner(process.getInputStream());
process=processBuilder.start();
while(sc.hasNext()){
System.out.println(sc.nextLine());
}
} catch (IOException ex) {
Logger.getLogger(ChannelDivider.class.getName()).log(Level.SEVERE, null, ex);
}
but the sc.hasNext() just hangs like there is no input
then I tried writing to a file with cmd by using > but it gave me a blank file
however trying both methods with FFprobe -h (help command) does give output which is very much confusing me, I see output in cmd but cant read it...
I just solved this, and hope someone might make use of it:
it turns out that FFprobe was writing to stderr, not stdout,
so instead of:
getInputStream()
I used:
getErrorStream()
Now all I have to do is parse that :)
Videos created with Camtasia can be shared on the web by exporting the project for the TechSmith Smart Player. The video is exported in the "H264 - MPEG-4 AVC (part10) (avc1)" codec and the export also includes other custom XML, JavaScript and SWF files used by the TechSmith Smart Player.
These custom files are also "burnt" into the video itself. For example the contents of the XML file can be viewed when opening the MP4 video in a text editor. This allows other services to only ask for the MP4 file when uploading Camtasia videos.
Therefore my question is how do you extract text and binary files from a MP4 video file? For this project I am limited to Java but I am happy to call an external executable as well.
I tried the "-dump_attachment" option in FFmpeg but that didn't work and I am out of ideas.
C:\Users\Desktop>ffmpeg -dump_attachment:t "" -i getting-started-project.mp4
ffmpeg version N-57448-gc78a416 Copyright (c) 2000-2013 the FFmpeg developers
built on Oct 26 2013 18:08:54 with gcc 4.8.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aa
cenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavp
ack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 47.101 / 52. 47.101
libavcodec 55. 38.101 / 55. 38.101
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 89.100 / 3. 89.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'getting-started-project.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2013-10-24 15:53:19
artist :
description :
title : Untitled
Duration: 00:05:41.12, start: 0.000000, bitrate: 314 kb/s
Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p(tv), 6
40x360 [SAR 1:1 DAR 16:9], 185 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
Metadata:
creation_time : 2013-10-24 15:53:19
handler_name : Mainconcept MP4 Video Media Handler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 12
5 kb/s (default)
Metadata:
creation_time : 2013-10-24 15:53:19
handler_name : Mainconcept MP4 Sound Media Handler
At least one output file must be specified
Update: It appears the XML is contained within a custom UUID atom and I just need a way of extracting that.
Thanks
Managed to find a way to access the UUID Atom/Box by making use of the mp4parser project
IsoFile isoFile = new IsoFile("project.mp4");
UserBox userbox = isoFile.getBoxes(UserBox.class).get(0);
System.out.println(new String(userbox.getData()));