I have a H.264 video and I want to extract the bitstream from it. In other words, I need to know the stream after encoding a video via H.264 standard. I am going to use the extracted stream in Matlab. How can I do this (extract the bitstream)? Is it possible to use ffmpeg?if so what is the command.
You can do this using
ffmpeg -i in.mp4 -c copy -f h264 stream.264
Depending on what MATLAB expects, you may need to add a bitstream filter
ffmpeg -i in.mp4 -c copy -f h264 -vbsf h264_mp4toannexb stream.264
Related
I have a python script that write images (numpy arrays) on the standard output.
I want to keep this frames and encode them h264 with FFMPEG, using GPU, then give it to vlc to expose a stream over http.
Here there's a working example of my apporach, without the part of h264 encoding:
python3 script.py | ffmpeg -r 24 -s 1920x1080 -f rawvideo -i - -vcodec copy -f avi - | cvlc --demux=rawvideo --rawvid-fps=25
--rawvid-width=1920 --rawvid-height=1080 --rawvid-chroma=RV24 - --no-audio --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{user=pippo,pwd=pluto,mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:10001/}'
Now, I'm having troubles in writing working pipes to do what I need.
Here the pipe I'm actually working on, FFMPEG process is managed by GPU, but VLC cannot correctly manage the flow, I suppose, in fact I can connect to VLC from another VLC instance used as client, but then I got an error in which VLC client cannot open MRL.
Here the pipe:
python3 script.py | ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -f rawvideo -s 1920x1080 -i - -c:a copy -c:v h264_nvenc -f h264 - | cvlc --demux=rawvideo --rawvid-fps=25 --rawvid-width=1920 --rawvid-height=1080 --rawvid-chroma=RV24 - --no-audio --sout '#transcode{vcodec=MJPG,venc=ffmpeg{strict=1}}:standard{access=http{user=pippo,pwd=pluto,mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:10001/}'
I don't understand how to set vlc parameters in order to manage the incoming stream. I also could have made errors in ffmpeg pipe, any suggestion is welcome.
I am currently using ffmpeg to read the recorded video by native frame rate and publish the stream to nginx rtmp server.
The command looks something like this
ffmpeg -re -i [video file] \
-vcodec libx264 -r 60 -g 120 -keyint_min 120 -vb [bitrate]\
-f flv -y rtmp://[server url];
I want to change the encoding bitrate of the software encoder manually,
according to the bandwidth fluctuation. For example,
If 2kbps< estimated_bandwidth <4kbps,
change ffmpeg bitrate to 3kbps, 1280x720 size
However, I couldn't find any framework or codec that supports dynamic bitrate change during encoding.
Is there a way that I could achieve this?
Last thing that I want to do is to implement the codec myself because I have no background.
ffmpeg does not have this feature. x264, a common h264 encoder, and the default encoder in ffmpeg does have support for for changing the bitrate on the fly. You do not need to implement the coded yourself, but you do need to modify ffmpeg to add the feature.
Previously, I used HandBrake to encode a video and was able to read it into MATLAB without any issues. Now I'm trying to use ffmpeg to encode the video; however, MATLAB is only reading in black frames. Both HandBrake and ffmpeg are using h.264 (mp4) and both videos play fine in VLC.
Here is the command I'm using for the ffmpeg encoding.
ffmpeg -i Barrier.avi -c:v libx264 -b:v 500k outputt5.mp4
I have a .mp4 video file, I need to trim it, however no matter how I do it, trimmed video is being encoded again which results in noisy video.
What I've tried:
Open video with Matlab, read frames and write only the frames that I want to have in trimmed video, I use 'MPEG-4' option.
Trim video using Windows Movie Maker.
Trim video using VirtualDub.
In first 2 scenarios original mp4 movie is encoded again after trimming it. I couldn't get mp4 files open in VirtualDub.
So what would be the easiest way to trim a video without re-encdong it?
You can do the split and re-encode in one command.
Create a text file, list.txt,
like this
file 'in.mp4'
inpoint 48.101
outpoint 67.459
file 'in.mp4'
inpoint 76.178
outpoint 86.399
file 'in.mp4'
inpoint 112.140
outpoint 125.031
then run,
ffmpeg -f concat -i list.txt -an -crf 18 out_merged.mp4
I've solved it with the following commands:
ffmpeg.exe -ss 48.101 -t 19.358 -i in.mp4 -an out_part1.mp4
ffmpeg.exe -ss 76.178 -t 10.221 -i in.mp4 -an out_part2.mp4
ffmpeg.exe -ss 112.140 -t 12.891 -i in.mp4 -an out_part3.mp4
ffmpeg -i out_part1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt1.ts
ffmpeg -i out_part2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt2.ts
ffmpeg -i out_part3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intrmdt3.ts
ffmpeg -i "concat:intrmdt1.ts|intrmdt2.ts|intrmdt3.ts" -c copy out_merged.mp4
And some explanation:
Giving -ss (start time) and -t (duration) options before -i (input) option avoids unnecessary decoding.
Not using -c copy provides transcoding hence result more precise cut (got this from here).
I used -an because I didn't need the audio, if you need audio just omit this option.
Before concatenating the resulting trimmed videos I needed to transcode them to mpeg transport streams, to achieve lossless concatenation (for more details you can see this link).
i use this command line on Windows to encode all my videos :
ffmpeg -i MyInputFile.wmv -c:v mpeg4 -q:v 1 -c:a libvo_aacenc -q:a 100 MyOutPutFile.mp4
All these originals videos are in .wmv and they have a bitrate of 1200kb/s.
I have to use MPEG4 to read the encoded videos on Android / iOS. With x264 it doesn't work, i have a black screen and audio only.
The command line works fine, but my output files are too big ( bigger than .wmv files, but MPEG4 is better normally ). How can i change my settings ? Select the bitrate ? i'm trying this but it doesn't work, the bitrate is still too high :
ffmpeg -i TestBitRate.wmv -c:v mpeg4 -q:v 1 -b 500k -c:a libvo_aacenc -q:a 100 TestBitRate.mp4
Thank you in advance for your help. :)