Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
video overwriting using ffmpeg - I want to Add video rotation code and rewrite the existing file..How can i do that ?
27 octobre 2013, par Lakshmi Priya.KI want to rotate the .mov file which is in portrait mode by 90 degrees, for that i used the following code.. It works but, it results in loss of video frames...
My code is,
public void encode(File source, File target, EncodingAttributes attributes, EncoderProgressListener listener, Integer i) throws IllegalArgumentException, InputFormatException, EncoderException { String formatAttribute = attributes.getFormat(); Float offsetAttribute = attributes.getOffset(); Float durationAttribute = attributes.getDuration(); QualityScale qualityScale = attributes.getQualityScale(); AudioAttributes audioAttributes = attributes.getAudioAttributes(); VideoAttributes videoAttributes = attributes.getVideoAttributes(); if (audioAttributes == null && videoAttributes == null) { throw new IllegalArgumentException( "Both audio and video attributes are null"); } target = target.getAbsoluteFile(); target.getParentFile().mkdirs(); FFMPEGExecutor ffmpeg = locator.createExecutor(); if (offsetAttribute != null) { ffmpeg.addArgument("-ss"); ffmpeg.addArgument(String.valueOf(offsetAttribute.floatValue())); } ffmpeg.addArgument("-i"); ffmpeg.addArgument(source.getAbsolutePath()); if (durationAttribute != null) { ffmpeg.addArgument("-t"); ffmpeg.addArgument(String.valueOf(durationAttribute.floatValue())); } if (qualityScale != null) { ffmpeg.addArgument("-qscale:"+qualityScale.getQualityStreamSpecifier()); ffmpeg.addArgument(String.valueOf(qualityScale.getQualityValue())); } if (videoAttributes == null) { ffmpeg.addArgument("-vn"); } else { String codec = videoAttributes.getCodec(); if (codec != null) { ffmpeg.addArgument("-vcodec"); ffmpeg.addArgument(codec); } String tag = videoAttributes.getTag(); if (tag != null) { ffmpeg.addArgument("-vtag"); ffmpeg.addArgument(tag); } Integer bitRate = videoAttributes.getBitRate(); if (bitRate != null) { ffmpeg.addArgument("-b"); ffmpeg.addArgument(String.valueOf(bitRate.intValue())); } Integer frameRate = videoAttributes.getFrameRate(); if (frameRate != null) { ffmpeg.addArgument("-r"); ffmpeg.addArgument(String.valueOf(frameRate.intValue())); } VideoSize size = videoAttributes.getSize(); if (size != null) { ffmpeg.addArgument("-s"); ffmpeg.addArgument(String.valueOf(size.getWidth()) + "x" + String.valueOf(size.getHeight())); } FilterGraph filterGraph = videoAttributes.getFilterGraph(); if (filterGraph != null) { ffmpeg.addArgument("-vf"); if(videoAttributes.getRotate() != null && videoAttributes.getRotate() == 90){ ffmpeg.addArgument("transpose=1"); }else if(videoAttributes.getRotate() != null && videoAttributes.getRotate() == 180){ ffmpeg.addArgument("vflip,hflip"); } else { if (filterGraph.isUseExpression()) { ffmpeg.addArgument(filterGraph.getFilterGraphExpression()); } } } } if (audioAttributes == null) { ffmpeg.addArgument("-an"); } else { String codec = audioAttributes.getCodec(); if (codec != null) { ffmpeg.addArgument("-acodec"); ffmpeg.addArgument(codec); } Integer bitRate = audioAttributes.getBitRate(); if (bitRate != null) { ffmpeg.addArgument("-ab"); ffmpeg.addArgument(String.valueOf(bitRate.intValue())); } Integer channels = audioAttributes.getChannels(); if (channels != null) { ffmpeg.addArgument("-ac"); ffmpeg.addArgument(String.valueOf(channels.intValue())); } Integer samplingRate = audioAttributes.getSamplingRate(); if (samplingRate != null) { ffmpeg.addArgument("-ar"); ffmpeg.addArgument(String.valueOf(samplingRate.intValue())); } Integer volume = audioAttributes.getVolume(); if (volume != null) { ffmpeg.addArgument("-vol"); ffmpeg.addArgument(String.valueOf(volume.intValue())); } } ffmpeg.addArgument("-f"); ffmpeg.addArgument(formatAttribute); ffmpeg.addArgument("-y"); ffmpeg.addArgument(target.getAbsolutePath()); try { ffmpeg.execute(); } catch (IOException e) { throw new EncoderException(e); } try { String lastWarning = null; long duration; long progress = 0; RBufferedReader reader = null; reader = new RBufferedReader(new InputStreamReader(ffmpeg .getErrorStream())); MultimediaInfo info = parseMultimediaInfo(source, reader); if (durationAttribute != null) { duration = (long) Math .round((durationAttribute.floatValue() * 1000L)); } else { duration = info.getDuration(); if (offsetAttribute != null) { duration -= (long) Math .round((offsetAttribute.floatValue() * 1000L)); } } if (listener != null) { listener.sourceInfo(info); } int step = 0; String line; while ((line = reader.readLine()) != null) { System.out.println("line::::"+line); if (step == 0) { if (line.startsWith("WARNING: ")) { if (listener != null) { listener.message(line); } } else if (!line.startsWith("Output #0")) { //throw new EncoderException(line); } else { step++; } } else if (step == 1) { if (!line.startsWith(" ")) { step++; } else { System.out.println("line>>>>>>"+line); Hashtable table1 = new Hashtable(); Matcher m = ROTATE_INFO_PATTERN.matcher(line); while (m.find()) { if (table1 == null) { table1 = new Hashtable(); } String key = m.group(1); String value = m.group(2); table1.put(key, value); } System.out.println("Table values"+table1.get("rotate")); if(table1.get("rotate") != null){ Object videoRotateValue = table1.get("rotate"); int rotate = Integer.valueOf(videoRotateValue.toString()); switch(rotate){ case 90: videoAttributes.setRotate(rotate); if(i == 0){ i++; encode(source, target, attributes, null, i); } break; case 180: videoAttributes.setRotate(rotate); if(i == 0){ i++; encode(source, target, attributes, null, i); } break; case 270: System.out.println("case 3 :: "+videoRotateValue); break; } } } } if (step == 2) { if (!line.startsWith("Stream mapping:")) { throw new EncoderException(line); } else { step++; } } else if (step == 3) { if (!line.startsWith(" ")) { step++; } } if (step == 4) { line = line.trim(); if (line.length() > 0) { Hashtable table = parseProgressInfoLine(line); if (table == null) { if (listener != null) { listener.message(line); } lastWarning = line; } else { if (listener != null) { String time = (String) table.get("time"); if (time != null) { int dot = time.indexOf('.'); if (dot > 0 && dot == time.length() - 2 && duration > 0) { String p1 = time.substring(0, dot); String p2 = time.substring(dot + 1); try { long i1 = Long.parseLong(p1); long i2 = Long.parseLong(p2); progress = (i1 * 1000L) + (i2 * 100L); int perm = (int) Math .round((double) (progress * 1000L) / (double) duration); if (perm > 1000) { perm = 1000; } listener.progress(perm); } catch (NumberFormatException e) { ; } } } } lastWarning = null; } } } } if (lastWarning != null) { if (!SUCCESS_PATTERN.matcher(lastWarning).matches()) { throw new EncoderException(lastWarning); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { ffmpeg.destroy(); } }
Please advise, how to achieve video rotation without any video Frame loss
Thanks In Advance
Lakshmi Priya . K
-
Converting avi to mp4 php fail
27 octobre 2013, par Dirk SwarzI'm able to convert video via server command using:
ffmpeg -i movie.avi -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 goodmovie.mp4
For this test I used a 1.8mb video and after conversion it is 5 MB. I'm able to upload the video to my server after I download it from FTP and it will work with flash player, but when I try to automate this it fails.
CODE:
$ffmpeg_command = 'ffmpeg -i '.$new_name.' -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 '.$anew_name; $convert_avi = true;
It converts to MP4, but
- it is not 5 MB but rather 2.2 MB when the original file is 1.8 MB
- it doesn't play in flash player.
The main upload script is in upload.php which anyone can download from here:
http://www.mediafire.com/?lp3f5pjal2oc19c
That code which i provided i just put into config.php
-
Jwplayer function snapshot using ffmpeg and php
27 octobre 2013, par Offboardbefore anything I'm using version 6, then the Snapshot plugin does not work.
I'm finally with 2 questions, take a sequence of photos of a percentage of the video, so googled it and got this code from ffmpeg:
ffmpeg -i video.mp4 -r 0.5 -f image2 output-%05d.jpeg
so far so good, but I do not know how to take a screen shot of the video by setting the time, if I'm right this code is per frame.
I searched again to get the function that calls the images, to generate good is quite simple, but the problem is that I found the pictures looks is all in one look.
if anyone has any function or know how to do please tell me: D My English sucks, so do not call if I messed up.
-
Converting avi to mp4 with ffmpeg
27 octobre 2013, par Juddy SwaftI use php code:
$ffmpeg_command ="ffmpeg -i ".$new_name." -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 ".$anew_name; $convert_avi = true;
i know that the problem is in here:
-s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5
EDIT2: My ffmpeg info with installed libx264:
http://www.part.lt/img/6459c908d41d2c4ce7a9294db1f134df613.PNG
EDIT 3: OK this is confusing becose i have just tried convert via putty i used:
ffmpeg -i movie.avi -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 goodmovie.mp4
and it converted well just weights 6mb original one was 1.8mb, so i uploaded to my ftp via upload script and it worked now im sure that problem is not in the server anymore is in my php code but i dont know how to fix it:/
-
Converting avi to mp4 ffmpeg
26 octobre 2013, par Dirk SwarzI use php code:
$ffmpeg_command ="ffmpeg -i ".$new_name." -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 ".$anew_name;
$convert_avi = true;
i know that the problem is in here:
-s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5
Idea is when video is converted i can watch it via flash player and now flash player is saying that video is not found or bad syntax so obviuos its bad syntax but i dont know how to fix it