Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Mute specified sections of an audio file using ffmpeg
24 mars 2015, par kimadactylI have a JSON file containing regions that I want to mute in a given audio file. How can I process the audio file to mute the file between the listed sections?
-
FFMPEG is doubling audio length when extracting from video
23 mars 2015, par Samuel StilesI've got a video file,
video.mp4
. It is 18 minutes 23 seconds in duration. I am looking to extract the audio only from this video, and create an MP3 of the highest possible quality from the audio in the video.Some googlefu lead me to this command:
ffmpeg -i video.mp4 audio.mp3
The problem is that, this command doubles the length of the audio that's outputted (duration is 36 minutes 46 seconds). It loops the audio track once, so the output contains the entire 18 minutes 23 seconds of audio, then immediately starts the 18 minutes and 23 seconds of audio over again.
Some more googlefu lead me to this flag:
-write_xing 0
from this SO question, but even with that flag it still loops the audio.EDIT: Additional googlefu and me seeming to think it has something to do with 2 audio channels (and perhaps looping channel 2 immediately after channel 1, rather than merging the two) lead me to this flag:
-ac 1
to force it to merge stereo -> mono. This did not work also, and it still outputs a 38 minute 46 seconds MP3 file.How can I extract (to MP3) the audio from a video file, without doubling the duration?
-
ffmpeg scale, how to crop correctly
23 mars 2015, par sathiaI'm using this command to encode videos
$transcode = FFMPEG_BINARY.' -loglevel panic -y -i "'.$files['original'].'" -vf scale='.VIDEO_SIZE_X.':'.VIDEO_SIZE_Y.' -vcodec libx264 -profile main -preset slow -r 25 -b '.VIDEO_BITRATE.' -maxrate '.VIDEO_BITRATE.' -bufsize 1000k -threads '.VIDEO_THREADS.' -acodec aac -ar 44100 -f mp4 -strict -2 '.$files['mp4']; where: VIDEO_SIZE_X = 640 and VIDEO_SIZE_Y = 480, VIDEO_BITRATE = 900k
it all seems to work fine, but the problem I'm having is that the video is not resized to the desired size which is 640x480
^ This is the output from vlc
It looks like there's some reference to the desired size, but the video is not scaled/cropped, what's the correct way of scaling videos in order to have the desired size? I don't mind having black stripes above and below or bands at the sides.
so, here's a bit of debugging as requested:
/usr/bin/ffmpeg -loglevel panic -y -i "in.wmv" -vf scale=640:480 -vcodec libx264 -profile main -preset slow -r 25 -b 900k -maxrate 900k -bufsize 1000k -threads 8 -acodec aac -ar 44100 -f mp4 -strict -2 out.mp4
original video:
[wmv3 @ 0x13245c0] Extra data: 8 bits left, value: 20 Input #0, asf, from 'in.wmv': Metadata: WMFSDKVersion : 12.0.9600.16384 WMFSDKNeeded : 0.0.0.0000 IsVBR : 1 VBR Peak : 313 Buffer Average : 397 Duration: 00:06:09.13, start: 0.000000, bitrate: 2111 kb/s Stream #0:0: Audio: wmav2 (a[1][0][0] / 0x0161), 48000 Hz, 2 channels, s16, 96 kb/s Stream #0:1: Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 860x484, 2000 kb/s, SAR 1:1 DAR 215:121, 29.97 tbr, 1k tbn, 1k tbc [wmv3 @ 0x13245c0] Extra data: 8 bits left, value: 20
while the result is:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf54.29.104 Duration: 00:06:08.76, start: 0.000000, bitrate: 975 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 645:484 DAR 215:121], 842 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 125 kb/s Metadata: handler_name : SoundHandler
cheers
-
How can i create a portrait video using Android's MediaRecorder
23 mars 2015, par urudroidI have an Android application which is able to record and play a videos in portrait mode, those features are working fine on Android phones.
The issue comes up because this video is needed to be played also on iOS devices (after being shared through a server).
iOS is not correctly showing the video as it looks "cropped", but videos recorded on iOS are played without issues.
So, the main difference between videos created on Android and iOS' is the size and the rotation.
Im using CWAC-Camera library for preview and recording and ffmpeg to scale the video down to 320x568px (as this is the standard size for both Android and iOS apps).
Here is the metadata from an video created from Android:
General Complete name : android_video.mp4 Format : MPEG-4 Format profile : Base Media Codec ID : isom File size : 447 KiB Duration : 5s 596ms Overall bit rate : 654 Kbps Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 1904-01-01 00:00:00 Writing application : Lavf56.4.101 Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L2.1 Format settings, CABAC : Yes Format settings, ReFrames : 4 frames Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 5s 406ms Bit rate : 536 Kbps Width : 568 pixels Height : 320 pixels Display aspect ratio : 16:9 Original display aspect ratio : 16:9 Rotation : 270° Frame rate mode : Constant Frame rate : 14.985 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.197 Stream size : 354 KiB (79%) Writing library : x264 core 142 Encoding settings : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / 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=6 / lookahead_threads=1 / 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=2 / keyint=250 / keyint_min=14 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00 Language : English Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 1904-01-01 00:00:00 Audio ID : 2 Format : AAC Format/Info : Advanced Audio Codec Format profile : LC Codec ID : 40 Duration : 5s 596ms Bit rate mode : Constant Bit rate : 132 Kbps Channel(s) : 2 channels Channel(s)_Original : 1 channel Channel positions : Front: C Sampling rate : 44.1 KHz Compression mode : Lossy Stream size : 89.4 KiB (20%) Language : English Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 1904-01-01 00:00:00
And here is the metadata from the video created on iOS:
General Complete name : ios_video.mp4 Format : MPEG-4 Format profile : Base Media / Version 2 Codec ID : mp42 File size : 673 KiB Duration : 7s 38ms Overall bit rate : 783 Kbps Encoded date : UTC 2015-03-17 19:16:36 Tagged date : UTC 2015-03-17 19:16:37 Video ID : 2 Format : AVC Format/Info : Advanced Video Codec Format profile : Main@L3.0 Format settings, CABAC : Yes Format settings, ReFrames : 2 frames Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 7s 33ms Bit rate : 711 Kbps Width : 320 pixels Height : 568 pixels Display aspect ratio : 0.563 Frame rate mode : Constant Frame rate : 30.000 fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.130 Stream size : 610 KiB (91%) Title : Core Media Video Encoded date : UTC 2015-03-17 19:16:36 Tagged date : UTC 2015-03-17 19:16:37 Color primaries : BT.709 Transfer characteristics : BT.709 Matrix coefficients : BT.709 Color range : Limited Audio ID : 1 Format : AAC Format/Info : Advanced Audio Codec Format profile : LC Codec ID : 40 Duration : 7s 38ms Source duration : 7s 105ms Bit rate mode : Constant Bit rate : 64.0 Kbps Channel(s) : 2 channels Channel(s)_Original : 1 channel Channel positions : Front: C Sampling rate : 44.1 KHz Compression mode : Lossy Stream size : 56.8 KiB (8%) Source stream size : 57.2 KiB (9%) Title : Core Media Audio Encoded date : UTC 2015-03-17 19:16:36 Tagged date : UTC 2015-03-17 19:16:37
The values width and height are inverted on Android, also the Rotation parameter is set to 270º (this is the rotation parameter for portrait videos).
This is a sketch of how iOS' videos look on iOS app:
And this is how Android's videos look on iOS app:
So, in order to get the videos correctly displayed both on iOS and Android i need to be able to set the width to 320 and height to 568 on Android. I tried it from several places (outside and inside CWAC-Camera library) but i always get a Camera.Parameters error.
It is possible to do this on Android?
EDIT:
This is the result i get when i set the rotation to 0 with ffmpeg:
-
Save changed frame in FFMPEG API
23 mars 2015, par VaigardI extracts frames from H.264 video by
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
procedure (like in example from https://github.com/chelyaev/ffmpeg-tutorial/blob/master/tutorial01.c) and changed values of samples. How I can save these changes in original video? After the change of the frame by the pointer he does not change.And I have a problem with
avcodec_encode_video2
function:assertion avctx->codec->encode2 failed at ...
. What does this mean?Thank you.